simplify parseLedgerAndDo
This commit is contained in:
parent
b8b3de0719
commit
59f0a2fabe
13
hledger.hs
13
hledger.hs
@ -84,16 +84,15 @@ balance opts args = parseLedgerAndDo opts args printbalance
|
|||||||
-- | parse the user's specified ledger file and do some action with it
|
-- | parse the user's specified ledger file and do some action with it
|
||||||
-- (or report a parse error). This function makes the whole thing go.
|
-- (or report a parse error). This function makes the whole thing go.
|
||||||
parseLedgerAndDo :: [Opt] -> [String] -> (Ledger -> IO ()) -> IO ()
|
parseLedgerAndDo :: [Opt] -> [String] -> (Ledger -> IO ()) -> IO ()
|
||||||
parseLedgerAndDo opts args cmd = do
|
parseLedgerAndDo opts args cmd =
|
||||||
parsed <- ledgerFilePathFromOpts opts >>= parseLedgerFile
|
ledgerFilePathFromOpts opts >>= parseLedgerFile >>= either parseError runthecommand
|
||||||
case parsed of Left err -> parseError err
|
|
||||||
Right l -> cmd $ cacheLedger $ filterLedger begin end aregex dregex l
|
|
||||||
where
|
where
|
||||||
(apats,dpats) = parsePatternArgs args
|
runthecommand = cmd . cacheLedger . filterLedger begin end aregex dregex
|
||||||
aregex = regexFor apats
|
|
||||||
dregex = regexFor dpats
|
|
||||||
begin = beginDateFromOpts opts
|
begin = beginDateFromOpts opts
|
||||||
end = endDateFromOpts opts
|
end = endDateFromOpts opts
|
||||||
|
aregex = regexFor apats
|
||||||
|
dregex = regexFor dpats
|
||||||
|
(acctpats,descpats) = parsePatternArgs args
|
||||||
|
|
||||||
-- ghci helpers
|
-- ghci helpers
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user