fix filter pattern handling, filtered non -s balance report showing full account names

This commit is contained in:
Simon Michael 2008-10-03 11:52:07 +00:00
parent 2ce3124738
commit 26b6130a9b
2 changed files with 12 additions and 13 deletions

View File

@ -1,4 +1,4 @@
module Options (parseOptions, parsePatternArgs, nullpats, wildcard, Flag(..), usage, ledgerFilePath)
module Options (parseOptions, parsePatternArgs, regexFor, nullpats, wildcard, Flag(..), usage, ledgerFilePath)
where
import System.Console.GetOpt
import System.Directory
@ -76,10 +76,10 @@ tildeExpand xs = return xs
-- | ledger pattern arguments are: 0 or more account patterns
-- optionally followed by -- and 0 or more description patterns.
-- No arguments implies match all. We convert the arguments to
-- a pair of regexps.
parsePatternArgs :: [String] -> (Regex,Regex)
parsePatternArgs args = (regexFor as, regexFor ds')
-- No arguments implies match all. Here we gather these into two lists.
-- parsePatternArgs :: [String] -> (Regex,Regex)
parsePatternArgs :: [String] -> ([String],[String])
parsePatternArgs args = (as, ds')
where (as, ds) = break (=="--") args
ds' = dropWhile (=="--") ds
@ -87,7 +87,7 @@ parsePatternArgs args = (regexFor as, regexFor ds')
-- or a wildcard if there are none.
regexFor :: [String] -> Regex
regexFor [] = wildcard
regexFor ss = mkRegex $ "(" ++ (unwords $ intersperse "|" ss) ++ ")"
regexFor ss = mkRegex $ concat $ ["("] ++ (intersperse "|" ss) ++ [")"]
wildcard :: Regex
wildcard = mkRegex ".*"

View File

@ -55,7 +55,7 @@ main = do
| cmd `isPrefixOf` "balance" = balance opts pats
| otherwise = putStr usage
type Command = [Flag] -> (Regex,Regex) -> IO ()
type Command = [Flag] -> ([String],[String]) -> IO ()
selftest :: Command
selftest opts pats = do
@ -77,19 +77,18 @@ balance opts pats = parseLedgerAndDo opts pats printbalance
where
showsubs = (ShowSubs `elem` opts)
depth = case (pats, showsubs) of
-- when there are no filter patterns and no -s, show
-- only to depth 1. (This was clearer when we used maybe.)
(nullpats, False) -> 1
-- when there is no -s or pattern args, show with depth 1
(([],[]), False) -> 1
otherwise -> 9999
-- | 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.
parseLedgerAndDo :: [Flag] -> (Regex,Regex) -> (Ledger -> IO ()) -> IO ()
parseLedgerAndDo opts pats cmd = do
parseLedgerAndDo :: [Flag] -> ([String],[String]) -> (Ledger -> IO ()) -> IO ()
parseLedgerAndDo opts (apats,dpats) cmd = do
path <- ledgerFilePath opts
parsed <- parseLedgerFile path
case parsed of Left err -> parseError err
Right l -> cmd $ cacheLedger l pats
Right l -> cmd $ cacheLedger l (regexFor apats, regexFor dpats)
-- ghci helpers