drop the FilterPatterns type
This commit is contained in:
parent
a4039de739
commit
bf136fae5c
@ -38,7 +38,7 @@ instance Show Ledger where
|
|||||||
-- 1. filter based on account/description patterns, if any
|
-- 1. filter based on account/description patterns, if any
|
||||||
-- 2. cache per-account info
|
-- 2. cache per-account info
|
||||||
-- also, figure out the precision(s) to use
|
-- also, figure out the precision(s) to use
|
||||||
cacheLedger :: FilterPatterns -> LedgerFile -> Ledger
|
cacheLedger :: (Regex,Regex) -> LedgerFile -> Ledger
|
||||||
cacheLedger pats l =
|
cacheLedger pats l =
|
||||||
let
|
let
|
||||||
lprecision = maximum $ map (precision . amount) $ rawLedgerTransactions l
|
lprecision = maximum $ map (precision . amount) $ rawLedgerTransactions l
|
||||||
@ -66,7 +66,7 @@ cacheLedger pats l =
|
|||||||
-- | description patterns, if any, and which have at least one
|
-- | description patterns, if any, and which have at least one
|
||||||
-- | transaction matching one of the account patterns, if any.
|
-- | transaction matching one of the account patterns, if any.
|
||||||
-- | No description or account patterns implies match all.
|
-- | No description or account patterns implies match all.
|
||||||
filterLedgerEntries :: FilterPatterns -> LedgerFile -> LedgerFile
|
filterLedgerEntries :: (Regex,Regex) -> LedgerFile -> LedgerFile
|
||||||
filterLedgerEntries (acctpat,descpat) (LedgerFile ms ps es f) =
|
filterLedgerEntries (acctpat,descpat) (LedgerFile ms ps es f) =
|
||||||
LedgerFile ms ps filteredentries f
|
LedgerFile ms ps filteredentries f
|
||||||
where
|
where
|
||||||
@ -84,7 +84,7 @@ filterLedgerEntries (acctpat,descpat) (LedgerFile ms ps es f) =
|
|||||||
-- | in each ledger entry, filter out transactions which do not match
|
-- | in each ledger entry, filter out transactions which do not match
|
||||||
-- | the account patterns, if any. (Entries are no longer balanced
|
-- | the account patterns, if any. (Entries are no longer balanced
|
||||||
-- | after this.)
|
-- | after this.)
|
||||||
filterLedgerTransactions :: FilterPatterns -> LedgerFile -> LedgerFile
|
filterLedgerTransactions :: (Regex,Regex) -> LedgerFile -> LedgerFile
|
||||||
filterLedgerTransactions (acctpat,descpat) (LedgerFile ms ps es f) =
|
filterLedgerTransactions (acctpat,descpat) (LedgerFile ms ps es f) =
|
||||||
LedgerFile ms ps (map filterentrytxns es) f
|
LedgerFile ms ps (map filterentrytxns es) f
|
||||||
where
|
where
|
||||||
|
|||||||
@ -74,9 +74,9 @@ tildeExpand xs = return xs
|
|||||||
|
|
||||||
-- | ledger pattern arguments are: 0 or more account patterns
|
-- | ledger pattern arguments are: 0 or more account patterns
|
||||||
-- | optionally followed by -- and 0 or more description patterns.
|
-- | optionally followed by -- and 0 or more description patterns.
|
||||||
-- | Here we convert the arguments, if any, to FilterPatterns,
|
-- | No arguments implies match all. We convert the arguments to
|
||||||
-- | which is a pair of maybe regexps.
|
-- | a pair of regexps.
|
||||||
parsePatternArgs :: [String] -> FilterPatterns
|
parsePatternArgs :: [String] -> (Regex,Regex)
|
||||||
parsePatternArgs args = (regexFor as, regexFor ds')
|
parsePatternArgs args = (regexFor as, regexFor ds')
|
||||||
where (as, ds) = break (=="--") args
|
where (as, ds) = break (=="--") args
|
||||||
ds' = dropWhile (=="--") ds
|
ds' = dropWhile (=="--") ds
|
||||||
|
|||||||
3
Types.hs
3
Types.hs
@ -6,9 +6,6 @@ where
|
|||||||
import Utils
|
import Utils
|
||||||
import qualified Data.Map as Map
|
import qualified Data.Map as Map
|
||||||
|
|
||||||
-- | account and description-matching patterns, see 'Options.parsePatternArgs'.
|
|
||||||
type FilterPatterns = (Regex, Regex)
|
|
||||||
|
|
||||||
type Date = String
|
type Date = String
|
||||||
|
|
||||||
type DateTime = String
|
type DateTime = String
|
||||||
|
|||||||
@ -65,16 +65,16 @@ main = do
|
|||||||
| cmd `isPrefixOf` "balance" = balance opts pats
|
| cmd `isPrefixOf` "balance" = balance opts pats
|
||||||
| otherwise = putStr usage
|
| otherwise = putStr usage
|
||||||
|
|
||||||
doWithFilteredLedger :: [Flag] -> FilterPatterns -> (Ledger -> IO ()) -> IO ()
|
doWithFilteredLedger :: [Flag] -> (Regex,Regex) -> (Ledger -> IO ()) -> IO ()
|
||||||
doWithFilteredLedger opts pats cmd = do
|
doWithFilteredLedger opts pats cmd = do
|
||||||
ledgerFilePath opts >>= parseLedgerFile >>= doWithParsed pats cmd
|
ledgerFilePath opts >>= parseLedgerFile >>= doWithParsed pats cmd
|
||||||
|
|
||||||
doWithParsed :: FilterPatterns -> (Ledger -> IO ()) -> (Either ParseError LedgerFile) -> IO ()
|
doWithParsed :: (Regex,Regex) -> (Ledger -> IO ()) -> (Either ParseError LedgerFile) -> IO ()
|
||||||
doWithParsed pats cmd parsed = do
|
doWithParsed pats cmd parsed = do
|
||||||
case parsed of Left e -> parseError e
|
case parsed of Left e -> parseError e
|
||||||
Right l -> cmd $ cacheLedger pats l
|
Right l -> cmd $ cacheLedger pats l
|
||||||
|
|
||||||
type Command = [Flag] -> FilterPatterns -> IO ()
|
type Command = [Flag] -> (Regex,Regex) -> IO ()
|
||||||
|
|
||||||
test :: Command
|
test :: Command
|
||||||
test opts pats = do
|
test opts pats = do
|
||||||
@ -100,7 +100,7 @@ balance opts pats = do
|
|||||||
depth = case (pats, showsubs) of
|
depth = case (pats, showsubs) of
|
||||||
-- when there are no account patterns and no -s,
|
-- when there are no account patterns and no -s,
|
||||||
-- show only to depth 1. (This was clearer and more
|
-- show only to depth 1. (This was clearer and more
|
||||||
-- correct when FilterPatterns used maybe.)
|
-- correct when we used maybe.)
|
||||||
((wildcard,_), False) -> 1
|
((wildcard,_), False) -> 1
|
||||||
otherwise -> 9999
|
otherwise -> 9999
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user