update example scripts for api, clarify -f support
This commit is contained in:
parent
a95bc44345
commit
415cd19a7e
@ -2,8 +2,15 @@
|
||||
-- Show all account names used in the default journal.
|
||||
|
||||
import Hledger
|
||||
import Hledger.Cli (getCliOpts, mainmode, withJournalDo)
|
||||
|
||||
main = do
|
||||
j <- defaultJournal
|
||||
let l = ledgerFromJournal Any j
|
||||
mapM_ putStrLn $ ledgerAccountNames l
|
||||
-- simple way to read ~/.hledger.journal or $LEDGER_FILE
|
||||
-- j <- defaultJournal
|
||||
|
||||
-- but we'd better handle -f as well:
|
||||
opts <- getCliOpts $ mainmode []
|
||||
withJournalDo opts $ \_opts j -> do
|
||||
|
||||
-- query the journal for all account names and print each one
|
||||
mapM_ putStrLn $ journalAccountNames j
|
||||
|
||||
@ -26,7 +26,7 @@ main = getCliOpts argsmode >>= printBalanceCsv
|
||||
printBalanceCsv opts = withJournalDo opts $
|
||||
\CliOpts{reportopts_=ropts} j -> do
|
||||
d <- getCurrentDay
|
||||
let (items,_) = accountsReport ropts (queryFromOpts d ropts) j
|
||||
let (items,_) = balanceReport ropts (queryFromOpts d ropts) j
|
||||
putStrLn $ printCSV $
|
||||
["account","balance"] :
|
||||
[[a, showMixedAmountWithoutPrice b] | (a, _, _, b) <- items]
|
||||
|
||||
@ -17,12 +17,13 @@ import Hledger.Cli
|
||||
import System.Environment
|
||||
|
||||
main = do
|
||||
putStrLn "(-f option not supported, see hledger-accountnames.hs for how to add it)"
|
||||
j <- defaultJournal
|
||||
d <- getCurrentDay
|
||||
args <- getArgs
|
||||
let query = Or $ map Acct args
|
||||
ropts = defreportopts{flat_=True}
|
||||
(acctbals,_) = accountsReport ropts query j
|
||||
(acctbals,_) = balanceReport ropts query j
|
||||
balancingamt = negate $ sum $ map (\(_,_,_,b) -> b) acctbals
|
||||
ps = [posting{paccount=a, pamount=b} | (a,_,_,b) <- acctbals]
|
||||
++ [posting{paccount="equity:opening balances", pamount=balancingamt}]
|
||||
|
||||
@ -13,6 +13,7 @@ import Hledger
|
||||
import Hledger.Cli
|
||||
|
||||
main = do
|
||||
putStrLn "(-f option not supported)"
|
||||
opts <- getCliOpts (defCommandMode ["hledger-print-unique"])
|
||||
withJournalDo opts $
|
||||
\opts j@Journal{jtxns=ts} -> print' opts j{jtxns=uniquify ts}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user