From 255e79c550a85c759eef1eca52ca0ad246ddba81 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 22 Apr 2025 18:50:42 -1000 Subject: [PATCH] lib: Hledger.Read: more ways to read the default journal defaultJournalWith, defaultJournalSafely, defaultJournalSafelyWith --- hledger-lib/Hledger/Read.hs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/hledger-lib/Hledger/Read.hs b/hledger-lib/Hledger/Read.hs index a0dd19d5c..9bbc0e9f6 100644 --- a/hledger-lib/Hledger/Read.hs +++ b/hledger-lib/Hledger/Read.hs @@ -89,6 +89,9 @@ module Hledger.Read ( -- * Journal files PrefixedFilePath, defaultJournal, + defaultJournalWith, + defaultJournalSafely, + defaultJournalSafelyWith, defaultJournalPath, requireJournalFileExists, ensureJournalFileExists, @@ -175,9 +178,25 @@ journalEnvVar = "LEDGER_FILE" journalEnvVar2 = "LEDGER" journalDefaultFilename = ".hledger.journal" --- | Read the default journal file specified by the environment, or raise an error. +-- | Read the default journal file specified by the environment, +-- with default input options, or raise an error. defaultJournal :: IO Journal -defaultJournal = defaultJournalPath >>= runExceptT . readJournalFile definputopts >>= either error' return -- PARTIAL: +defaultJournal = defaultJournalSafely >>= either error' return -- PARTIAL: + +-- | Read the default journal file specified by the environment, +-- with the given input options, or raise an error. +defaultJournalWith :: InputOpts -> IO Journal +defaultJournalWith iopts = defaultJournalSafelyWith iopts >>= either error' return -- PARTIAL: + +-- | Read the default journal file specified by the environment, +-- with default input options, or return an error message. +defaultJournalSafely :: IO (Either String Journal) +defaultJournalSafely = defaultJournalSafelyWith definputopts + +-- | Read the default journal file specified by the environment, +-- with the given input options, or return an error message. +defaultJournalSafelyWith :: InputOpts -> IO (Either String Journal) +defaultJournalSafelyWith iopts = defaultJournalPath >>= runExceptT . readJournalFile iopts -- | Get the default journal file path specified by the environment. -- Like ledger, we look first for the LEDGER_FILE environment