HORIZON HASKELLDocslts/ghc-10.0.x8c2f8e82026-10-19Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8c2f8e8 · 2026-10-19

Modulehledger-1.52.4GHC2021

Hledger.Cli.Utils

Utilities for top-level modules and ghci. See also Hledger.Read and Hledger.Utils.

  • 16 values
  • Packagehledger-1.52.4
  • Exports16
  • LanguageGHC2021
  • LicenceGPL-3.0-or-later
  • SourceUtils.hs
valuewithJournal :: CliOpts -> (Journal -> IO a) -> IO a
#

Parse the user's specified journal file(s) as a Journal, maybe apply some transformations according to options, and run a hledger command with it. Or, throw an error.

valuewithPossibleJournal :: CliOpts -> (Journal -> IO a) -> IO a
#

Like withJournal, but if the first journal file does not exist, provides an empty journal with that file path set. This is useful for commands like add and import that need to work with a potentially non-existent first journal file, while still reading all specified files (for completions, etc).

valuewriteOutput :: CliOpts -> String -> IO ()
#

Write some output to stdout or to a file selected by --output-file. If the file exists it will be overwritten.

valuewriteOutputLazyText :: CliOpts -> Text -> IO ()
#

Write some output, to a file specified by --output-file if any, otherwise to stdout. If writing to a file and the file exists, it will be overwritten. If writing to stdout, a pager is used when appropriate and possible.

Apply some journal transformations, if enabled by options, that should happen late. These happen after parsing, finalising the journal, strict checks, and .latest filtering/updating, but before report calculation. They are, in processing order: --pivot, --anonymise error message, --obfuscate.

Why not do these in journalFinalise ? That step is supposed to check the data's intrinsic correctness, regardless of view options; whereas here we assume correctness and are just transforming the view (based only on InputOpts). XXX But it's easy to forget to call this. Current callers include withJournal, journalReload, uiReload, withJournalCached.

Re-read the journal file(s) specified by options, applying any transformations specified by options. Or return an error string. Reads the full journal, without filtering.

Re-read the option-specified journal file(s), but only if any of them has changed since last read. (If the file is standard input, this will either do nothing or give an error, not tested yet). Returns a journal or error message, and a flag indicating whether it was re-read or not. Like withJournal and journalReload, reads the full journal, without filtering.

Has the specified file changed since the journal was last read ? Typically this is one of the journal's journalFilePaths. These are not always real files, so the file's existence is tested first; for non-files the answer is always no.

Back up this file with a (incrementing) numbered suffix then overwrite it with this new text, or give an error, but only if the text is different from the current file contents, and return a flag indicating whether we did anything.

The given text should have unix line endings (n); the existing file content will be normalised to unix line endings before comparing the two. If the file is overwritten, the new file will have the current system's native line endings (n on unix, rn on windows). This could be different from the file's previous line endings, if working with a DOS file on unix or vice-versa.