diff --git a/Ledger/Ledger.hs b/Ledger/Ledger.hs index e9dea4efc..cb8aecb63 100644 --- a/Ledger/Ledger.hs +++ b/Ledger/Ledger.hs @@ -136,8 +136,8 @@ printregister l = putStr $ showTransactionsWithBalances nullamt{precision=lprecision l} {-| -This and the functions below help generate ledger-compatible balance -reports. Here's how it should work: +This and the functions below generate ledger-compatible balance report +output. Here's how it should work: a sample account tree: diff --git a/Options.hs b/Options.hs index e1ccd6826..cce88ee44 100644 --- a/Options.hs +++ b/Options.hs @@ -1,4 +1,4 @@ -module Options (parseOptions, parsePatternArgs, wildcard, Flag(..), usage, ledgerFilePath, parseLedgerAndDo) +module Options (parseOptions, parsePatternArgs, wildcard, Flag(..), usage, ledgerFilePath) where import System.Console.GetOpt import System.Directory @@ -92,12 +92,3 @@ regexFor ss = mkRegex $ "(" ++ (unwords $ intersperse "|" ss) ++ ")" wildcard :: Regex wildcard = mkRegex ".*" --- | parse the user's specified ledger file and do some action with it --- (or report a parse error). This function makes the whole thing go. -parseLedgerAndDo :: [Flag] -> (Regex,Regex) -> (Ledger -> IO ()) -> IO () -parseLedgerAndDo opts pats cmd = do - path <- ledgerFilePath opts - parsed <- parseLedgerFile path - case parsed of Left err -> parseError err - Right l -> cmd $ cacheLedger l pats - diff --git a/hledger.hs b/hledger.hs index 34db0d6f2..f51799f01 100644 --- a/hledger.hs +++ b/hledger.hs @@ -7,11 +7,11 @@ Released under GPL version 3 or later. This is a minimal haskell clone of John Wiegley's ledger . hledger generates -simple ledger-compatible register & balance reports from a standard +simple ledger-compatible register & balance reports from a plain text ledger file, and demonstrates a (naive) purely functional implementation of ledger. -This module includes some helpers for querying your ledger in ghci. Examples: +This module includes some helpers for working with your ledger in ghci. Examples: > $ rm -f hledger.o > $ ghci hledger.hs @@ -38,7 +38,7 @@ import qualified Data.Map as Map (lookup) import Options import Tests (hunit, quickcheck) import Ledger -import Ledger.Parse (parseLedgerFile) +import Ledger.Parse (parseLedgerFile, parseError) import Ledger.Utils hiding (test) @@ -70,18 +70,26 @@ register :: Command register opts pats = parseLedgerAndDo opts pats printregister balance :: Command -balance opts pats = do - parseLedgerAndDo opts pats printbalance +balance opts pats = parseLedgerAndDo opts pats printbalance where - printbalance l = - putStr $ showLedgerAccounts l depth - where - showsubs = (ShowSubs `elem` opts) - depth = case (pats, showsubs) of - -- when there are no account patterns and no -s, show - -- only to depth 1. (This was clearer when we used maybe.) - ((wildcard,_), False) -> 1 - otherwise -> 9999 + printbalance :: Ledger -> IO () + printbalance l = putStr $ showLedgerAccounts l depth + where + showsubs = (ShowSubs `elem` opts) + depth = case (pats, showsubs) of + -- when there are no account patterns and no -s, show + -- only to depth 1. (This was clearer when we used maybe.) + ((wildcard,_), False) -> 1 + otherwise -> 9999 + +-- | parse the user's specified ledger file and do some action with it +-- (or report a parse error). This function makes the whole thing go. +parseLedgerAndDo :: [Flag] -> (Regex,Regex) -> (Ledger -> IO ()) -> IO () +parseLedgerAndDo opts pats cmd = do + path <- ledgerFilePath opts + parsed <- parseLedgerFile path + case parsed of Left err -> parseError err + Right l -> cmd $ cacheLedger l pats -- ghci helpers