From 6fc8cdfe3e00fcf8f53ea8877e17aed4208dffd6 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sat, 22 Nov 2008 09:46:57 +0000 Subject: [PATCH] -n flag for balance command --- BalanceCommand.hs | 3 ++- NOTES | 1 - Options.hs | 2 ++ Tests.hs | 5 +++++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/BalanceCommand.hs b/BalanceCommand.hs index dc07b9af1..6e8ce56b4 100644 --- a/BalanceCommand.hs +++ b/BalanceCommand.hs @@ -119,7 +119,7 @@ balance opts args l = putStr $ showBalanceReport opts args l -- | Generate balance report output for a ledger, based on options. showBalanceReport :: [Opt] -> [String] -> Ledger -> String -showBalanceReport opts args l = acctsstr ++ totalstr +showBalanceReport opts args l = acctsstr ++ (if collapse then "" else totalstr) where acctsstr = concatMap showatree $ subs t showatree t = showAccountTreeWithBalances matchedacctnames t @@ -128,6 +128,7 @@ showBalanceReport opts args l = acctsstr ++ totalstr apats = fst $ parseAccountDescriptionArgs args sub = SubTotal `elem` opts empty = Empty `elem` opts + collapse = Collapse `elem` opts maxdepth = 9999 totalstr = if isZeroMixedAmount total then "" diff --git a/NOTES b/NOTES index 2e20181f7..baa5ac06a 100644 --- a/NOTES +++ b/NOTES @@ -12,7 +12,6 @@ implementations were its consequences." --Niklaus Wirth *** parse commented lines at end of file *** display mixed amounts vertically, not horizontally ** features -*** -n to skip total, for compound reports *** flexible date expressions, for easier time reports *** commodity @ rate, for tracking client hours in main ledger *** actual/effective entry & txn dates, for ... diff --git a/Options.hs b/Options.hs index 4435ac33f..f22907932 100644 --- a/Options.hs +++ b/Options.hs @@ -29,6 +29,7 @@ options = [ Option ['C'] ["cleared"] (NoArg Cleared) "report only on cleared entries", Option ['E'] ["empty"] (NoArg Empty) "balance report: show accounts with zero balance", Option ['R'] ["real"] (NoArg Real) "report only on real (non-virtual) transactions", + Option ['n'] ["collapse"] (NoArg Collapse) "balance report: no grand total", Option ['s'] ["subtotal"] (NoArg SubTotal) "balance report: show subaccounts", Option ['h'] ["help","usage"] (NoArg Help) "show this help", Option ['V'] ["version"] (NoArg Version) "show version" @@ -42,6 +43,7 @@ data Opt = Cleared | Empty | Real | + Collapse | SubTotal | Help | Version diff --git a/Tests.hs b/Tests.hs index 3bb1676e4..04e949863 100644 --- a/Tests.hs +++ b/Tests.hs @@ -222,6 +222,11 @@ balancecommand_tests = TestList [ "--------------------\n" ++ " $-1\n" ++ "") + , + "balance report with -n omits the total" ~: + ([Collapse], ["cash"]) `gives` + (" $-2 assets:cash\n" ++ + "") ] where gives (opts,pats) e = do l <- ledgerfromfile pats "sample.ledger"