balance: support -s with account patterns
This commit is contained in:
parent
dd202d3113
commit
a881f713c1
@ -19,6 +19,9 @@ data Account = Account {
|
|||||||
abalance :: Amount
|
abalance :: Amount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
instance Show Account where
|
||||||
|
show (Account a ts b) = printf "Account %s with %d transactions" a $ length ts
|
||||||
|
|
||||||
nullacct = Account "" [] nullamt
|
nullacct = Account "" [] nullamt
|
||||||
|
|
||||||
mkAccount :: Ledger -> AccountName -> Account
|
mkAccount :: Ledger -> AccountName -> Account
|
||||||
@ -108,7 +111,7 @@ ledgerAccountTreeMatching l showsubs [] =
|
|||||||
ledgerAccountTreeMatching l showsubs [".*"]
|
ledgerAccountTreeMatching l showsubs [".*"]
|
||||||
ledgerAccountTreeMatching l showsubs acctpats =
|
ledgerAccountTreeMatching l showsubs acctpats =
|
||||||
addDataToAccountNameTree l $
|
addDataToAccountNameTree l $
|
||||||
filterAccountNameTree acctpats $
|
filterAccountNameTree acctpats showsubs $
|
||||||
ledgerAccountNameTree l
|
ledgerAccountNameTree l
|
||||||
|
|
||||||
showLedgerAccounts :: Ledger -> Bool -> [String] -> String
|
showLedgerAccounts :: Ledger -> Bool -> [String] -> String
|
||||||
|
|||||||
@ -82,10 +82,11 @@ showAccountNameTree t =
|
|||||||
where
|
where
|
||||||
topacct = indentAccountName 0 $ root t
|
topacct = indentAccountName 0 $ root t
|
||||||
|
|
||||||
filterAccountNameTree :: [String] -> Tree AccountName -> Tree AccountName
|
filterAccountNameTree :: [String] -> Bool -> Tree AccountName -> Tree AccountName
|
||||||
filterAccountNameTree pats =
|
filterAccountNameTree pats keepsubs =
|
||||||
treefilter matchany
|
treefilter $ \a -> matchpats a || (keepsubs && issubofmatch a)
|
||||||
where
|
where
|
||||||
matchany a = any (match a) pats
|
matchpats a = any (match a) pats
|
||||||
match a pat = matchAccountName pat $ accountLeafName a
|
match a pat = matchAccountName pat $ accountLeafName a
|
||||||
|
issubofmatch a = any matchpats $ parentAccountNames a
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user