mirror of
https://github.com/simonmichael/hledger.git
synced 2024-09-20 02:37:12 +03:00
33 lines
812 B
Haskell
Executable File
33 lines
812 B
Haskell
Executable File
#!/usr/bin/env runhaskell
|
|
{-|
|
|
hledger-balance-csv [OPTIONS] [ARGS]
|
|
|
|
Show a balance report as CSV.
|
|
-}
|
|
|
|
import Hledger
|
|
import Hledger.Cli
|
|
import System.Console.CmdArgs.Explicit
|
|
import Text.CSV
|
|
|
|
|
|
argsmode =
|
|
(defCommandMode ["balance-csv"]) {
|
|
modeHelp = "show matched postings accounts and their balances as CSV"
|
|
,modeGroupFlags = Group {
|
|
groupNamed = []
|
|
,groupUnnamed = inputflags ++ reportflags ++ helpflags
|
|
,groupHidden = []
|
|
}
|
|
}
|
|
|
|
main = getCliOpts argsmode >>= printBalanceCsv
|
|
|
|
printBalanceCsv opts = withJournalDo opts $
|
|
\CliOpts{reportopts_=ropts} j -> do
|
|
d <- getCurrentDay
|
|
let (items,_) = balanceReport ropts (queryFromOpts d ropts) j
|
|
putStrLn $ printCSV $
|
|
["account","balance"] :
|
|
[[a, showMixedAmountWithoutPrice b] | (a, _, _, b) <- items]
|