balance: support -s with account patterns

This commit is contained in:
Simon Michael 2007-03-10 22:29:09 +00:00
parent dd202d3113
commit a881f713c1
3 changed files with 9 additions and 6 deletions

View File

@ -19,6 +19,9 @@ data Account = Account {
abalance :: Amount
}
instance Show Account where
show (Account a ts b) = printf "Account %s with %d transactions" a $ length ts
nullacct = Account "" [] nullamt
mkAccount :: Ledger -> AccountName -> Account
@ -108,7 +111,7 @@ ledgerAccountTreeMatching l showsubs [] =
ledgerAccountTreeMatching l showsubs [".*"]
ledgerAccountTreeMatching l showsubs acctpats =
addDataToAccountNameTree l $
filterAccountNameTree acctpats $
filterAccountNameTree acctpats showsubs $
ledgerAccountNameTree l
showLedgerAccounts :: Ledger -> Bool -> [String] -> String

View File

@ -82,10 +82,11 @@ showAccountNameTree t =
where
topacct = indentAccountName 0 $ root t
filterAccountNameTree :: [String] -> Tree AccountName -> Tree AccountName
filterAccountNameTree pats =
treefilter matchany
filterAccountNameTree :: [String] -> Bool -> Tree AccountName -> Tree AccountName
filterAccountNameTree pats keepsubs =
treefilter $ \a -> matchpats a || (keepsubs && issubofmatch a)
where
matchany a = any (match a) pats
matchpats a = any (match a) pats
match a pat = matchAccountName pat $ accountLeafName a
issubofmatch a = any matchpats $ parentAccountNames a

1
TODO
View File

@ -75,7 +75,6 @@ algorithm:
2 add subaccounts if -s
3 display account tree, eliding boring accounts
include subaccounts
elide boring accounts