extra: make hledger-equity support -f etc. (Julien Moutinho)

This commit is contained in:
Simon Michael 2014-04-14 12:03:52 -07:00
parent 5885914547
commit 06a8ec07c5

View File

@ -16,16 +16,31 @@ Usage: hledger-equity [ACCTPAT]
import Hledger.Cli import Hledger.Cli
import System.Environment import System.Environment
argsmode :: Mode RawOpts
argsmode = (defCommandMode ["equity"])
{ modeHelp = "print a journal entry posting the total balance of all accounts"
++ " (or the specified account and its subaccounts)"
, modeGroupFlags = Group
{ groupNamed =
[ ("Input",inputflags)
, ("Reporting",reportflags)
, ("Misc",helpflags)
]
, groupUnnamed = []
, groupHidden = []
}
}
main :: IO ()
main = do main = do
putStrLn "(-f option not supported, see hledger-accountnames.hs for how to add it)" opts <- getCliOpts argsmode
j <- defaultJournal withJournalDo opts $
d <- getCurrentDay \CliOpts{reportopts_=ropts} j -> do
args <- getArgs d <- getCurrentDay
let query = Or $ map Acct args let ropts_ = ropts{flat_=True}
ropts = defreportopts{flat_=True} let (acctbals,_) = balanceReport ropts_ (queryFromOpts d ropts_) j
(acctbals,_) = balanceReport ropts query j let balancingamt = negate $ sum $ map (\((_,_,_),b) -> b) acctbals
balancingamt = negate $ sum $ map (\((_,_,_),b) -> b) acctbals let ps = [posting{paccount=a, pamount=b} | ((a,_,_),b) <- acctbals]
ps = [posting{paccount=a, pamount=b} | ((a,_,_),b) <- acctbals] ++ [posting{paccount="equity:opening balances", pamount=balancingamt}]
++ [posting{paccount="equity:opening balances", pamount=balancingamt}] let txn = nulltransaction{tdate=d, tpostings=ps}
txn = nulltransaction{tdate=d, tpostings=ps} putStr $ showTransactionUnelided txn
putStr $ showTransactionUnelided txn