Skip to content

Commit

Permalink
;bin: register-max: don't add -H by default
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichael committed Jan 29, 2023
1 parent 82abb00 commit dc8e0f6
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions bin/hledger-register-max.hs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env stack
-- stack script --compile --resolver lts-20.8 --verbosity error --package hledger-lib --package hledger --package text

-- hledger-register-max - runs "register -H" and prints the posting with largest historical balance
-- hledger-register-max - runs "hledger register" and prints the posting with largest running total/balance.
-- Usage:
-- hledger-register-max [REGISTERARGS]
-- hledger register-max -- [REGISTERARGS]
-- For negative balances, use --invert.
-- For historical balances, add -H. For negative balances, add --invert.

-- Examples:
-- $ hledger-register-max -f examples/bcexample.hledger checking
-- $ hledger-register-max -f examples/bcexample.hledger -H checking
-- 2013-01-03 Hoogle | Payroll Assets:US:BofA:Checking 1350.60 USD 8799.22 USD
-- $ hledger register-max -- -f examples/bcexample.hledger checking
-- $ hledger register-max -- -f examples/bcexample.hledger -H checking
-- 2013-01-03 Hoogle | Payroll Assets:US:BofA:Checking 1350.60 USD 8799.22 USD


Expand All @@ -28,18 +28,19 @@ import Hledger
import Hledger.Cli
import Hledger.Cli.Main (argsToCliOpts)

-- needs --help, see hledger-addon-example.hs
-- XXX needs --help, see hledger-addon-example.hs
-- XXX shows only one posting when multiple have same balance

main = do
args <- getArgs
opts <- argsToCliOpts ("register" : "-H" : args) []
opts <- argsToCliOpts ("register" : args) []
withJournalDo opts $ \j -> do
let r = postingsReport (reportspec_ opts) j
unless (null r) $ do
let
i = maximumBy (comparing fifth5) r
(_, _, mdesc, p, _) = i
d = maybe (error "shouldn't happen") tdate $ ptransaction p
d = postingDate p
desc = fromMaybe "" mdesc
ptxt = T.strip $ T.unlines $ first3 $ postingAsLines False True 20 15 p
T.putStrLn $ T.unwords [showDate d, desc, "", ptxt, "", T.pack $ showMixedAmountOneLine $ fifth5 i]

0 comments on commit dc8e0f6

Please sign in to comment.