quick --depth option, a hledger feature
This commit is contained in:
		
							parent
							
								
									6fc8cdfe3e
								
							
						
					
					
						commit
						86b510917d
					
				| @ -129,7 +129,7 @@ showBalanceReport opts args l = acctsstr ++ (if collapse then "" else totalstr) | |||||||
|       sub = SubTotal `elem` opts |       sub = SubTotal `elem` opts | ||||||
|       empty = Empty `elem` opts |       empty = Empty `elem` opts | ||||||
|       collapse = Collapse `elem` opts |       collapse = Collapse `elem` opts | ||||||
|       maxdepth = 9999 |       maxdepth = fromMaybe 9999 $ depthFromOpts opts | ||||||
|       totalstr = if isZeroMixedAmount total  |       totalstr = if isZeroMixedAmount total  | ||||||
|                  then ""  |                  then ""  | ||||||
|                  else printf "--------------------\n%20s\n" $ showMixedAmount total |                  else printf "--------------------\n%20s\n" $ showMixedAmount total | ||||||
|  | |||||||
							
								
								
									
										1
									
								
								NOTES
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								NOTES
									
									
									
									
									
								
							| @ -16,7 +16,6 @@ implementations were its consequences." --Niklaus Wirth | |||||||
| *** commodity @ rate, for tracking client hours in main ledger | *** commodity @ rate, for tracking client hours in main ledger | ||||||
| *** actual/effective entry & txn dates, for ... | *** actual/effective entry & txn dates, for ... | ||||||
| *** --display, for reconciling recent transactions with real balance | *** --display, for reconciling recent transactions with real balance | ||||||
| *** depth control |  | ||||||
| *** more ledger features from README | *** more ledger features from README | ||||||
| *** new features | *** new features | ||||||
| **** option for strict ledger-compatible output (or, compare xml ?) | **** option for strict ledger-compatible output (or, compare xml ?) | ||||||
|  | |||||||
							
								
								
									
										13
									
								
								Options.hs
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								Options.hs
									
									
									
									
									
								
							| @ -27,6 +27,7 @@ options = [ | |||||||
|  Option ['b'] ["begin"]        (ReqArg Begin "YYYY/MM/DD") "report on entries on or after this date", |  Option ['b'] ["begin"]        (ReqArg Begin "YYYY/MM/DD") "report on entries on or after this date", | ||||||
|  Option ['e'] ["end"]          (ReqArg End "YYYY/MM/DD")   "report on entries prior to this date", |  Option ['e'] ["end"]          (ReqArg End "YYYY/MM/DD")   "report on entries prior to this date", | ||||||
|  Option ['C'] ["cleared"]      (NoArg  Cleared)            "report only on cleared entries", |  Option ['C'] ["cleared"]      (NoArg  Cleared)            "report only on cleared entries", | ||||||
|  |  Option []    ["depth"]        (ReqArg Depth "N")          "balance report: maximum account depth to show", | ||||||
|  Option ['E'] ["empty"]        (NoArg  Empty)              "balance report: show accounts with zero balance", |  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 ['R'] ["real"]         (NoArg  Real)               "report only on real (non-virtual) transactions", | ||||||
|  Option ['n'] ["collapse"]     (NoArg  Collapse)           "balance report: no grand total", |  Option ['n'] ["collapse"]     (NoArg  Collapse)           "balance report: no grand total", | ||||||
| @ -41,6 +42,7 @@ data Opt = | |||||||
|     Begin String |  |     Begin String |  | ||||||
|     End String |  |     End String |  | ||||||
|     Cleared |  |     Cleared |  | ||||||
|  |     Depth String |  | ||||||
|     Empty |  |     Empty |  | ||||||
|     Real |  |     Real |  | ||||||
|     Collapse | |     Collapse | | ||||||
| @ -109,6 +111,17 @@ endDateFromOpts opts = | |||||||
|       getenddate _ = [] |       getenddate _ = [] | ||||||
|       defaultdate = "" |       defaultdate = "" | ||||||
| 
 | 
 | ||||||
|  | -- | Get the value of the depth option, if any. | ||||||
|  | depthFromOpts :: [Opt] -> Maybe Int | ||||||
|  | depthFromOpts opts =  | ||||||
|  |     case depthopts of | ||||||
|  |       (x:_) -> Just $ read x | ||||||
|  |       _     -> Nothing | ||||||
|  |     where | ||||||
|  |       depthopts = concatMap getdepth opts | ||||||
|  |       getdepth (Depth s) = [s] | ||||||
|  |       getdepth _ = [] | ||||||
|  | 
 | ||||||
| -- | Gather any ledger-style account/description pattern arguments into | -- | Gather any ledger-style account/description pattern arguments into | ||||||
| -- two lists.  These are 0 or more account patterns optionally followed by | -- two lists.  These are 0 or more account patterns optionally followed by | ||||||
| -- -- and 0 or more description patterns. | -- -- and 0 or more description patterns. | ||||||
|  | |||||||
							
								
								
									
										12
									
								
								Tests.hs
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								Tests.hs
									
									
									
									
									
								
							| @ -227,6 +227,18 @@ balancecommand_tests = TestList [ | |||||||
|   ([Collapse], ["cash"]) `gives` |   ([Collapse], ["cash"]) `gives` | ||||||
|   ("                 $-2  assets:cash\n" ++ |   ("                 $-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" ++ | ||||||
|  |    "") | ||||||
|  ] where |  ] where | ||||||
|     gives (opts,pats) e = do  |     gives (opts,pats) e = do  | ||||||
|       l <- ledgerfromfile pats "sample.ledger" |       l <- ledgerfromfile pats "sample.ledger" | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user