mirror of
https://github.com/simonmichael/hledger.git
synced 2024-09-19 18:29:36 +03:00
marginal cleanup: parse acctpats, descpats for all commands
This commit is contained in:
parent
12a9a03f1a
commit
abc3ed32cf
23
hledger.hs
23
hledger.hs
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user