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

Safe Haskell | None
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
- 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 #

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

withJournalDo :: 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.

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

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 () #

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.

journalTransform :: CliOpts -> Journal -> Journal #

Apply some extra post-parse transformations to the journal, if enabled by options. These happen after parsing and finalising the journal, but before report calculation. They are, in processing order:

- pivoting account names (--pivot)
- anonymising (--anonymise).

journalReload :: CliOpts -> ExceptT String IO Journal #

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) #

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 #

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 #

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

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

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 #

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.

pivotByOpts :: CliOpts -> Journal -> Journal #

Apply the pivot transformation on a journal (replacing account names by a different field's value), if option is present.

anonymiseByOpts :: CliOpts -> Journal -> Journal #

Raise an error, announcing the rename to --obfuscate and its limitations.

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

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

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

tests_Cli_Utils :: TestTree #