make --depth activate -s like ledger's -d'<=N'

This commit is contained in:
Simon Michael 2008-11-23 21:21:18 +00:00
parent 037e762b1b
commit 27c1f06055
3 changed files with 27 additions and 17 deletions

View File

@ -126,10 +126,10 @@ showBalanceReport opts args l = acctsstr ++ (if collapse then "" else totalstr)
matchedacctnames = balancereportacctnames l sub apats t
t = (if empty then id else pruneZeroBalanceLeaves) $ ledgerAccountTree maxdepth l
apats = fst $ parseAccountDescriptionArgs args
sub = SubTotal `elem` opts
maxdepth = fromMaybe 9999 $ depthFromOpts opts
sub = SubTotal `elem` opts || (isJust $ depthFromOpts opts)
empty = Empty `elem` opts
collapse = Collapse `elem` opts
maxdepth = fromMaybe 9999 $ depthFromOpts opts
totalstr = if isZeroMixedAmount total
then ""
else printf "--------------------\n%20s\n" $ showMixedAmount total

View File

@ -117,7 +117,7 @@ endDateFromOpts opts =
-- | Get the value of the depth option, if any.
depthFromOpts :: [Opt] -> Maybe Int
depthFromOpts opts =
depthFromOpts opts =
case depthopts of
(x:_) -> Just $ read x
_ -> Nothing

View File

@ -127,7 +127,7 @@ balancecommand_tests = TestList [
" $1 liabilities\n" ++
"")
,
"balance report with --subtotal" ~:
"balance report with -s" ~:
([SubTotal], []) `gives`
(" $-1 assets\n" ++
" $-2 cash\n" ++
@ -140,6 +140,28 @@ balancecommand_tests = TestList [
" $-1 salary\n" ++
" $1 liabilities:debts\n" ++
"")
,
"balance report --depth limits -s" ~:
([SubTotal,Depth "1"], []) `gives`
(" $-1 assets\n" ++
" $2 expenses\n" ++
" $-2 income\n" ++
" $1 liabilities\n" ++
"")
,
"balance report --depth activates -s" ~:
([Depth "2"], []) `gives`
(" $-1 assets\n" ++
" $-2 cash\n" ++
" $1 saving\n" ++
" $2 expenses\n" ++
" $1 food\n" ++
" $1 supplies\n" ++
" $-2 income\n" ++
" $-1 gifts\n" ++
" $-1 salary\n" ++
" $1 liabilities:debts\n" ++
"")
,
"balance report with account pattern o" ~:
([], ["o"]) `gives`
@ -149,7 +171,7 @@ balancecommand_tests = TestList [
" $-1\n" ++
"")
,
"balance report with account pattern o and --subtotal" ~:
"balance report with account pattern o and -s" ~:
([SubTotal], ["o"]) `gives`
(" $1 expenses:food\n" ++
" $-2 income\n" ++
@ -227,18 +249,6 @@ balancecommand_tests = TestList [
([Collapse], ["cash"]) `gives`
(" $-2 assets:cash\n" ++
"")
,
"balance report with --depth 1" ~:
([SubTotal,Collapse,Depth "1"], ["assets"]) `gives`
(" $-1 assets\n" ++
"")
,
"balance report with --depth 2" ~:
([SubTotal,Collapse,Depth "2"], ["assets"]) `gives`
(" $-1 assets\n" ++
" $-2 cash\n" ++
" $1 saving\n" ++
"")
,
"balance report with cost basis" ~: do
let l = cacheLedger [] $