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