hledger-1.30.1: Command-line interface for the hledger accounting system

Safe Haskell | Safe-Inferred
Language | Haskell2010

Hledger.Cli.Utils

Description

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

Synopsis

- unsupportedOutputFormatError :: String -> String
- withJournalDo :: CliOpts -> (Journal -> IO a) -> IO a
- writeOutput :: CliOpts -> String -> IO ()
- writeOutputLazyText :: CliOpts -> Text -> IO ()
- journalTransform :: CliOpts -> Journal -> Journal
- journalReload :: CliOpts -> ExceptT String IO Journal
- journalReloadIfChanged :: CliOpts -> Day -> Journal -> ExceptT String IO (Journal, Bool)
- journalFileIsNewer :: Journal -> FilePath -> IO Bool
- openBrowserOn :: String -> IO ExitCode
- writeFileWithBackup :: FilePath -> String -> IO ()
- writeFileWithBackupIfChanged :: FilePath -> Text -> IO Bool
- readFileStrictly :: FilePath -> IO Text
- pivotByOpts :: CliOpts -> Journal -> Journal
- anonymiseByOpts :: CliOpts -> Journal -> Journal
- journalSimilarTransaction :: CliOpts -> Journal -> Text -> Maybe Transaction
- postingsOrTransactionsReportAsText :: Bool -> CliOpts -> (Int -> Int -> (a, [WideBuilder], [WideBuilder]) -> Builder) -> (a -> MixedAmount) -> (a -> MixedAmount) -> [a] -> Builder
- tests_Cli_Utils :: TestTree

# Documentation

unsupportedOutputFormatError :: String -> String Source #

Standard error message for a bad output format specified with -O/-o.

withJournalDo :: CliOpts -> (Journal -> IO a) -> IO a Source #

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.

writeOutput :: CliOpts -> String -> IO () Source #

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

writeOutputLazyText :: CliOpts -> Text -> IO () Source #

Write some output to stdout or to a file selected by --output-file. If the file exists it will be overwritten. This function operates on Lazy Text values.

journalTransform :: CliOpts -> Journal -> Journal Source #

Apply some extra post-parse transformations to the journal, if specified by options. These happen after journal validation, but before report calculation. They include:

- adding forecast transactions (--forecast)
- pivoting account names (--pivot)
- anonymising (--anonymise).

This will return an error message if the query in any auto posting rule fails to parse, or the generated transactions are not balanced.

journalReload :: CliOpts -> ExceptT String IO Journal Source #

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.

journalReloadIfChanged :: CliOpts -> Day -> Journal -> ExceptT String IO (Journal, Bool) Source #

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 withJournalDo and journalReload, reads the full journal, without filtering.

journalFileIsNewer :: Journal -> FilePath -> IO Bool Source #

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.

openBrowserOn :: String -> IO ExitCode Source #

Attempt to open a web browser on the given url, all platforms.

writeFileWithBackup :: FilePath -> String -> IO () Source #

Back up this file with a (incrementing) numbered suffix, then overwrite it with this new text, or give an error.

writeFileWithBackupIfChanged :: FilePath -> Text -> IO Bool Source #

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.

readFileStrictly :: FilePath -> IO Text Source #

pivotByOpts :: CliOpts -> Journal -> Journal Source #

Apply the pivot transformation on a journal, if option is present.

anonymiseByOpts :: CliOpts -> Journal -> Journal Source #

Apply the anonymisation transformation on a journal, if option is present

journalSimilarTransaction :: CliOpts -> Journal -> Text -> Maybe Transaction Source #

postingsOrTransactionsReportAsText :: Bool -> CliOpts -> (Int -> Int -> (a, [WideBuilder], [WideBuilder]) -> Builder) -> (a -> MixedAmount) -> (a -> MixedAmount) -> [a] -> Builder Source #

Render a `PostingsReport` or `AccountTransactionsReport` as Text, determining the appropriate starting widths and increasing as necessary.

tests_Cli_Utils :: TestTree Source #