marginal cleanup: parse acctpats, descpats for all commands

This commit is contained in:
Simon Michael 2007-03-12 08:17:51 +00:00
parent 12a9a03f1a
commit abc3ed32cf

View File

@ -44,33 +44,32 @@ import Utils
main :: IO ()
main = do
(opts, (cmd:args)) <- getArgs >>= parseOptions
run cmd opts args
where run cmd opts args
| cmd `isPrefixOf` "register" = register opts args
| cmd `isPrefixOf` "balance" = balance opts args
let (acctpats, descpats) = parseLedgerPatternArgs args
run cmd opts acctpats descpats
where run cmd opts acctpats descpats
| cmd `isPrefixOf` "register" = register opts acctpats descpats
| cmd `isPrefixOf` "balance" = balance opts acctpats descpats
| cmd `isPrefixOf` "test" = test
| otherwise = putStr usage
-- commands
register :: [Flag] -> [String] -> IO ()
register opts args = do
doWithLedger opts $ printRegister
register :: [Flag] -> [String] -> [String] -> IO ()
register opts acctpats descpats = do
doWithLedger opts printRegister
where
printRegister ledger =
putStr $ showTransactionsWithBalances
(ledgerTransactionsMatching (acctpats,descpats) ledger)
0
where (acctpats,descpats) = parseLedgerPatternArgs args
balance :: [Flag] -> [String] -> IO ()
balance opts args = do
doWithLedger opts $ printBalance
balance :: [Flag] -> [String] -> [String] -> IO ()
balance opts acctpats _ = do
doWithLedger opts printBalance
where
printBalance ledger =
putStr $ showLedgerAccounts ledger acctpats showsubs maxdepth
where
(acctpats,_) = parseLedgerPatternArgs args
showsubs = (ShowSubs `elem` opts)
maxdepth = case (acctpats, showsubs) of
([],False) -> 1