-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | The main command-line interface for the hledger accounting tool. -- -- hledger is a library and set of user tools for working with financial -- data (or anything that can be tracked in a double-entry accounting -- ledger.) It is a haskell port and friendly fork of John Wiegley's -- Ledger. hledger provides command-line, curses and web interfaces, and -- aims to be a reliable, practical tool for daily use. @package hledger @version 0.21 module Hledger.Cli.Version progname :: String version :: String prognameandversion :: String -- | Given a program name, return a precise platform-specific executable -- name suitable for naming downloadable binaries. Can raise an error if -- the version and patch level was not defined correctly at build time. binaryfilename :: String -> String -- | Command-line options for the hledger program, and option-parsing -- utilities. module Hledger.Cli.Options type RawOpts = [(String, String)] defmode :: Mode RawOpts mainmode :: [Name] -> Mode RawOpts convertmode :: Mode RawOpts addonmode :: Name -> Mode RawOpts help_postscript :: [a] generalflagstitle :: [Char] generalflags1 :: [Flag [([Char], [Char])]] generalflags2 :: [Flag [([Char], [Char])]] generalflags3 :: [Flag [([Char], [Char])]] fileflags :: [Flag [([Char], [Char])]] reportflags :: [Flag [([Char], [Char])]] helpflags :: [Flag [([Char], [Char])]] mainargsflag :: Arg [([Char], [Char])] commandargsflag :: Arg [([Char], [Char])] addonargsflag :: Arg [([Char], [Char])] commandmode :: [Name] -> Mode RawOpts addmode :: Mode RawOpts testmode :: Mode RawOpts accountsmode :: Mode RawOpts entriesmode :: Mode RawOpts postingsmode :: Mode RawOpts transactionsmode :: Mode RawOpts activitymode :: Mode RawOpts incomestatementmode :: Mode RawOpts balancesheetmode :: Mode RawOpts cashflowmode :: Mode RawOpts statsmode :: Mode RawOpts data CliOpts CliOpts :: RawOpts -> String -> Maybe FilePath -> Maybe FilePath -> [String] -> Bool -> Bool -> Maybe String -> ReportOpts -> CliOpts rawopts_ :: CliOpts -> RawOpts command_ :: CliOpts -> String file_ :: CliOpts -> Maybe FilePath rules_file_ :: CliOpts -> Maybe FilePath alias_ :: CliOpts -> [String] debug_ :: CliOpts -> Bool no_new_accounts_ :: CliOpts -> Bool width_ :: CliOpts -> Maybe String reportopts_ :: CliOpts -> ReportOpts defcliopts :: CliOpts -- | Parse raw option string values to the desired final data types. Any -- relative smart dates will be converted to fixed dates based on today's -- date. Parsing failures will raise an error. toCliOpts :: RawOpts -> IO CliOpts -- | Get all command-line options, specifying any extra commands that are -- allowed, or fail on parse errors. getHledgerCliOpts :: [String] -> IO CliOpts -- | Get the unique suffixes (without hledger-) of hledger-* executables -- found in the current user's PATH, or the empty list if there is any -- problem. getHledgerAddonCommands :: IO [String] -- | Get the unique names of hledger-* executables found in the current -- user's PATH, or the empty list if there is any problem. getHledgerProgramsInPath :: IO [String] getEnvSafe :: String -> IO String getDirectoryContentsSafe :: FilePath -> IO [FilePath] -- | Convert possibly encoded option values to regular unicode strings. decodeRawOpts :: [(t, SystemString)] -> [(t, String)] rearrangeForCmdArgs :: [[Char]] -> [[Char]] optserror :: [Char] -> c setopt :: t -> [Char] -> [(t, [Char])] -> [(t, [Char])] setboolopt :: t -> [(t, [Char])] -> [(t, [Char])] in_ :: String -> RawOpts -> Bool boolopt :: String -> RawOpts -> Bool maybestringopt :: Eq a => a -> [(a, String)] -> Maybe String stringopt :: Eq a => a -> [(a, String)] -> [Char] listofstringopt :: Eq a => a -> [(a, t)] -> [t] maybeintopt :: String -> RawOpts -> Maybe Int intopt :: String -> RawOpts -> Int maybesmartdateopt :: Day -> String -> RawOpts -> Maybe Day maybedisplayopt :: Day -> RawOpts -> Maybe DisplayExp maybeperiodopt :: Day -> RawOpts -> Maybe (Interval, DateSpan) -- | Do final validation of processed opts, raising an error if there is -- trouble. checkCliOpts :: CliOpts -> IO CliOpts -- | Parse the format option if provided, possibly returning an error, -- otherwise get the default value. formatFromOpts :: ReportOpts -> Either String [FormatString] -- | Default line format for balance report: %20(total) -- %2(depth_spacer)%-(account) defaultBalanceFormatString :: [FormatString] data OutputWidth TotalWidth :: Width -> OutputWidth FieldWidths :: [Width] -> OutputWidth data Width Width :: Int -> Width Auto :: Width defaultWidth :: Int defaultWidthWithFlag :: Int -- | Parse the width option if provided, possibly returning an error, -- otherwise get the default value. widthFromOpts :: CliOpts -> Either String OutputWidth parseWidth :: String -> Either String OutputWidth outputwidth :: GenParser Char st OutputWidth width :: GenParser Char st Width -- | Get the (tilde-expanded, absolute) journal file path from options, an -- environment variable, or a default. journalFilePathFromOpts :: CliOpts -> IO String -- | Get the (tilde-expanded) rules file path from options, if any. rulesFilePathFromOpts :: CliOpts -> IO (Maybe FilePath) aliasesFromOpts :: CliOpts -> [(AccountName, AccountName)] showModeHelp :: Mode a -> String tests_Hledger_Cli_Options :: Test instance Show CliOpts instance Show Width instance Show OutputWidth instance Default CliOpts -- | Utilities for top-level modules and ghci. See also Hledger.Read and -- Hledger.Utils. module Hledger.Cli.Utils -- | Parse the user's specified journal file and run a hledger command on -- it, or throw an error. withJournalDo :: CliOpts -> (CliOpts -> Journal -> IO ()) -> IO () -- | Re-read a journal from its data file, or return an error string. journalReload :: Journal -> IO (Either String Journal) -- | Re-read a journal from its data file mostly, only if the file has -- changed since last read (or if there is no file, ie data read from -- stdin). The provided options are mostly ignored. Return a journal or -- the error message while reading it, and a flag indicating whether it -- was re-read or not. journalReloadIfChanged :: CliOpts -> Journal -> IO (Either String Journal, Bool) -- | Has the journal's main data file changed since the journal was last -- read ? journalFileIsNewer :: Journal -> IO Bool -- | Has the specified file (presumably one of journal's data files) -- changed since journal was last read ? journalSpecifiedFileIsNewer :: Journal -> FilePath -> IO Bool -- | Get the last modified time of the specified file, or if it does not -- exist or there is some other error, the current time. fileModificationTime :: FilePath -> IO ClockTime -- | Attempt to open a web browser on the given url, all platforms. openBrowserOn :: String -> IO ExitCode -- | Back up this file with a (incrementing) numbered suffix, then -- overwrite it with this new text, or give an error. writeFileWithBackup :: FilePath -> String -> IO () -- | 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. writeFileWithBackupIfChanged :: FilePath -> String -> IO Bool readFileStrictly :: FilePath -> IO String -- | The basic structure used to create an annotated tree of test cases. data Test :: * -- | A set of Tests sharing the same level in the hierarchy. TestList :: [Test] -> Test -- | Print some statistics for the journal. module Hledger.Cli.Stats -- | Print various statistics for the journal. stats :: CliOpts -> Journal -> IO () showLedgerStats :: Ledger -> Day -> DateSpan -> String -- | A ledger-compatible register command. module Hledger.Cli.Register -- | Print a (posting) register report. register :: CliOpts -> Journal -> IO () -- | Render a register report as plain text suitable for console output. postingsReportAsText :: CliOpts -> PostingsReport -> String tests_Hledger_Cli_Register :: Test -- | A ledger-compatible print command. module Hledger.Cli.Print -- | Print journal transactions in standard format. print' :: CliOpts -> Journal -> IO () showTransactions :: ReportOpts -> Query -> Journal -> String tests_Hledger_Cli_Print :: Test -- | Print a histogram report. module Hledger.Cli.Histogram barchar :: Char -- | Print a histogram of some statistic per reporting interval, such as -- number of postings per day. histogram :: CliOpts -> Journal -> IO () showHistogram :: ReportOpts -> Query -> Journal -> String printDayWith :: PrintfType (t2 -> t) => (t1 -> t2) -> (DateSpan, t1) -> t countBar :: [a] -> [Char] -- | A ledger-compatible balance command. -- -- ledger's balance command is easy to use but not easy to describe -- precisely. In the examples below we'll use sample.journal, which has -- the following account tree: -- --
--   assets
--     bank
--       checking
--       saving
--     cash
--   expenses
--     food
--     supplies
--   income
--     gifts
--     salary
--   liabilities
--     debts
--   
-- -- The balance command shows accounts with their aggregate balances. -- Subaccounts are displayed indented below their parent. Each balance is -- the sum of any transactions in that account plus any balances from -- subaccounts: -- --
--   $ hledger -f sample.journal balance
--                   $-1  assets
--                    $1    bank:saving
--                   $-2    cash
--                    $2  expenses
--                    $1    food
--                    $1    supplies
--                   $-2  income
--                   $-1    gifts
--                   $-1    salary
--                    $1  liabilities:debts
--   
-- -- Usually, the non-interesting accounts are elided or omitted. Above, -- checking is omitted because it has no subaccounts and a zero -- balance. bank is elided because it has only a single -- displayed subaccount (saving) and it would be showing the -- same balance as that ($1). Ditto for liabilities. We will -- return to this in a moment. -- -- The --depth argument can be used to limit the depth of the balance -- report. So, to see just the top level accounts: -- --
--   $ hledger -f sample.journal balance --depth 1
--                    $-1  assets
--                     $2  expenses
--                    $-2  income
--                     $1  liabilities
--   
-- -- This time liabilities has no displayed subaccounts (due to --depth) -- and is not elided. -- -- With one or more account pattern arguments, the balance command shows -- accounts whose name matches one of the patterns, plus their parents -- (elided) and subaccounts. So with the pattern o we get: -- --
--    $ hledger -f sample.journal balance o
--                     $1  expenses:food
--                    $-2  income
--                    $-1    gifts
--                    $-1    salary
--   --------------------
--                    $-1
--   
-- -- The o pattern matched food and income, so they are -- shown. Unmatched parents of matched accounts are also shown (elided) -- for context (expenses). -- -- Also, the balance report shows the total of all displayed accounts, -- when that is non-zero. Here, it is displayed because the accounts -- shown add up to $-1. -- -- Also, non-interesting accounts may be elided. Here's an imperfect -- description of the ledger balance command's eliding behaviour: -- "Interesting" accounts are displayed on their own line. An account -- less deep than the report's max depth, with just one interesting -- subaccount, and the same balance as the subaccount, is -- non-interesting, and prefixed to the subaccount's line, unless -- (hledger's) --no-elide is in effect. An account with a zero inclusive -- balance and less than two interesting subaccounts is not displayed at -- all, unless --empty is in effect. module Hledger.Cli.Balance -- | Print a balance report. balance :: CliOpts -> Journal -> IO () -- | Render a balance report as plain text suitable for console output. accountsReportAsText :: ReportOpts -> AccountsReport -> [String] tests_Hledger_Cli_Balance :: Test -- | The balancesheet command prints a simple balance sheet. module Hledger.Cli.Balancesheet -- | Print a simple balance sheet. balancesheet :: CliOpts -> Journal -> IO () tests_Hledger_Cli_Balancesheet :: Test -- | The cashflow command prints a simplified cashflow statement. -- It just shows the change in all cash accounts for the period -- (without the traditional segmentation into operating, investing, and -- financing cash flows.) module Hledger.Cli.Cashflow -- | Print a simple cashflow statement. cashflow :: CliOpts -> Journal -> IO () tests_Hledger_Cli_Cashflow :: Test -- | The incomestatement command prints a simple income statement -- (profit & loss) report. module Hledger.Cli.Incomestatement -- | Print a simple income statement. incomestatement :: CliOpts -> Journal -> IO () tests_Hledger_Cli_Incomestatement :: Test -- | A history-aware add command to help with data entry. -- -- Note: this might not be sensible, but add has some aspirations of -- being both user-friendly and pipeable/scriptable and for this reason -- informational messages are mostly written to stderr rather than -- stdout. module Hledger.Cli.Add -- | Read multiple transactions from the console, prompting for each field, -- and append them to the journal file. If the journal came from stdin, -- this command has no effect. add :: CliOpts -> Journal -> IO () -- | Loop reading transactions from the console, prompting for, validating, -- displaying and appending each one to the journal file, until end of -- input or ctrl-c (then raise an EOF exception). If provided, -- command-line arguments are used as defaults for the first transaction; -- otherwise defaults come from the most similar recent transaction in -- the journal. getAndAddTransactionsLoop :: Journal -> CliOpts -> String -> [String] -> IO () -- | Read a single transaction from the console, with history-aware -- prompting, allowing the user to restart and confirm at the end. A -- default date, and zero or more defaults for subsequent fields, are -- provided. getTransaction :: Journal -> CliOpts -> String -> [String] -> IO Transaction -- | Read a single transaction from the console, with history-aware -- prompting, or return nothing indicating that the user wants to restart -- entering this transaction. A default date, and zero or more defaults -- for subsequent fields, are provided. getTransactionOrRestart :: Journal -> CliOpts -> String -> [String] -> IO (Maybe Transaction) data RestartEntryException RestartEntryException :: RestartEntryException -- | Information used as the basis for suggested account names, amounts -- etc. in add prompt. data PostingsState PostingsState :: Journal -> (AccountName -> Bool) -> Bool -> Maybe [Posting] -> PostingsState psJournal :: PostingsState -> Journal psAccept :: PostingsState -> AccountName -> Bool psSuggestHistoricalAmount :: PostingsState -> Bool psHistory :: PostingsState -> Maybe [Posting] -- | Loop reading postings from the console, until a valid balanced set of -- postings has been entered, then return the final transaction, or -- nothing indicating that the user wants to restart entering this -- transaction. getPostingsForTransactionWithHistory :: Journal -> CliOpts -> String -> String -> String -> String -> [String] -> IO (Maybe Transaction) -- | Read postings from the command line until . is entered, generating -- useful defaults based on historical context and postings entered so -- far. getPostingsLoop :: PostingsState -> [Posting] -> [String] -> IO [Posting] -- | Prompt for and read a string value, optionally with a default value -- and a validator. A validator causes the prompt to repeat until the -- input is valid. May also raise an EOF exception if control-d or -- control-c is pressed. askFor :: String -> Maybe String -> Maybe (String -> Bool) -> InputT IO String -- | Append this transaction to the journal's file, and to the journal's -- transaction list. journalAddTransaction :: Journal -> CliOpts -> Transaction -> IO Journal -- | Append a string, typically one or more transactions, to a journal -- file, or if the file is -, dump it to stdout. Tries to avoid -- excess whitespace. appendToJournalFileOrStdout :: FilePath -> String -> IO () -- | Replace a string's 0 or more terminating newlines with exactly one. ensureOneNewlineTerminated :: String -> String -- | Convert a string of journal data into a register report. registerFromString :: String -> IO String -- | Return a similarity measure, from 0 to 1, for two strings. This is -- Simon White's letter pairs algorithm from -- http:www.catalysoft.comarticlesStrikeAMatch.html with a -- modification for short strings. compareStrings :: String -> String -> Double wordLetterPairs :: String -> [[Char]] letterPairs :: [t] -> [[t]] compareDescriptions :: [Char] -> [Char] -> Double transactionsSimilarTo :: Journal -> Query -> String -> [(Double, Transaction)] runInteraction :: Journal -> InputT IO a -> IO a runInteractionDefault :: InputT IO a -> IO a type CompletionCache = [AccountName] completionCache :: Journal -> CompletionCache accountCompletion :: CompletionCache -> CompletionFunc IO capitalize :: String -> String headTailDef :: a -> [a] -> (a, [a]) instance Typeable RestartEntryException instance Show RestartEntryException instance Exception RestartEntryException -- | Hledger.Cli re-exports the options, utilities and commands provided by -- the hledger command-line program. This module also aggregates the -- built-in unit tests defined throughout hledger and hledger-lib, and -- adds some more which are easier to define here. module Hledger.Cli tests_Hledger_Cli :: Test -- | A simple test runner for hledger's built-in unit tests. module Hledger.Cli.Tests -- | Run HUnit unit tests and exit with success or failure. test' :: CliOpts -> IO () -- | Run all or just the matched unit tests and return their HUnit result -- counts. runTests :: CliOpts -> IO Counts -- | Run all or just the matched unit tests until the first failure or -- error, returning the name of the problem test if any. runTestsTillFailure :: CliOpts -> IO (Maybe String) -- | All or pattern-matched tests, as a flat list to show simple names. flatTests :: CliOpts -> Test -- | All or pattern-matched tests, in the original suites to show -- hierarchical names. hierarchicalTests :: CliOpts -> Test -- | hledger - a ledger-compatible accounting tool. Copyright (c) 2007-2011 -- Simon Michael simon@joyful.com Released under GPL version 3 or -- later. -- -- hledger is a partial haskell clone of John Wiegley's ledger. It -- generates ledger-compatible register & balance reports from a -- plain text journal, and demonstrates a functional implementation of -- ledger. For more information, see http://hledger.org . -- -- This module provides the main function for the hledger command-line -- executable. It is exposed here so that it can be imported by eg -- benchmark scripts. -- -- You can use the command line: -- --
--   $ hledger --help
--   
-- -- or ghci: -- --
--   $ ghci hledger
--   > j <- readJournalFile Nothing Nothing "data/sample.journal"
--   > register [] ["income","expenses"] j
--   2008/01/01 income               income:salary                   $-1          $-1
--   2008/06/01 gift                 income:gifts                    $-1          $-2
--   2008/06/03 eat & shop           expenses:food                    $1          $-1
--                                   expenses:supplies                $1            0
--   > balance [Depth "1"] [] l
--                    $-1  assets
--                     $2  expenses
--                    $-2  income
--                     $1  liabilities
--   > l <- myLedger
--   
-- -- See Hledger.Data.Ledger for more examples. module Hledger.Cli.Main main :: IO ()