fix filter pattern handling, filtered non -s balance report showing full account names
This commit is contained in:
parent
2ce3124738
commit
26b6130a9b
12
Options.hs
12
Options.hs
@ -1,4 +1,4 @@
|
|||||||
module Options (parseOptions, parsePatternArgs, nullpats, wildcard, Flag(..), usage, ledgerFilePath)
|
module Options (parseOptions, parsePatternArgs, regexFor, nullpats, wildcard, Flag(..), usage, ledgerFilePath)
|
||||||
where
|
where
|
||||||
import System.Console.GetOpt
|
import System.Console.GetOpt
|
||||||
import System.Directory
|
import System.Directory
|
||||||
@ -76,10 +76,10 @@ 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.
|
||||||
-- No arguments implies match all. We convert the arguments to
|
-- No arguments implies match all. Here we gather these into two lists.
|
||||||
-- a pair of regexps.
|
-- parsePatternArgs :: [String] -> (Regex,Regex)
|
||||||
parsePatternArgs :: [String] -> (Regex,Regex)
|
parsePatternArgs :: [String] -> ([String],[String])
|
||||||
parsePatternArgs args = (regexFor as, regexFor ds')
|
parsePatternArgs args = (as, ds')
|
||||||
where (as, ds) = break (=="--") args
|
where (as, ds) = break (=="--") args
|
||||||
ds' = dropWhile (=="--") ds
|
ds' = dropWhile (=="--") ds
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ parsePatternArgs args = (regexFor as, regexFor ds')
|
|||||||
-- or a wildcard if there are none.
|
-- or a wildcard if there are none.
|
||||||
regexFor :: [String] -> Regex
|
regexFor :: [String] -> Regex
|
||||||
regexFor [] = wildcard
|
regexFor [] = wildcard
|
||||||
regexFor ss = mkRegex $ "(" ++ (unwords $ intersperse "|" ss) ++ ")"
|
regexFor ss = mkRegex $ concat $ ["("] ++ (intersperse "|" ss) ++ [")"]
|
||||||
|
|
||||||
wildcard :: Regex
|
wildcard :: Regex
|
||||||
wildcard = mkRegex ".*"
|
wildcard = mkRegex ".*"
|
||||||
|
|||||||
13
hledger.hs
13
hledger.hs
@ -55,7 +55,7 @@ main = do
|
|||||||
| cmd `isPrefixOf` "balance" = balance opts pats
|
| cmd `isPrefixOf` "balance" = balance opts pats
|
||||||
| otherwise = putStr usage
|
| otherwise = putStr usage
|
||||||
|
|
||||||
type Command = [Flag] -> (Regex,Regex) -> IO ()
|
type Command = [Flag] -> ([String],[String]) -> IO ()
|
||||||
|
|
||||||
selftest :: Command
|
selftest :: Command
|
||||||
selftest opts pats = do
|
selftest opts pats = do
|
||||||
@ -77,19 +77,18 @@ balance opts pats = parseLedgerAndDo opts pats printbalance
|
|||||||
where
|
where
|
||||||
showsubs = (ShowSubs `elem` opts)
|
showsubs = (ShowSubs `elem` opts)
|
||||||
depth = case (pats, showsubs) of
|
depth = case (pats, showsubs) of
|
||||||
-- when there are no filter patterns and no -s, show
|
-- when there is no -s or pattern args, show with depth 1
|
||||||
-- only to depth 1. (This was clearer when we used maybe.)
|
(([],[]), False) -> 1
|
||||||
(nullpats, False) -> 1
|
|
||||||
otherwise -> 9999
|
otherwise -> 9999
|
||||||
|
|
||||||
-- | 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 :: [Flag] -> (Regex,Regex) -> (Ledger -> IO ()) -> IO ()
|
parseLedgerAndDo :: [Flag] -> ([String],[String]) -> (Ledger -> IO ()) -> IO ()
|
||||||
parseLedgerAndDo opts pats cmd = do
|
parseLedgerAndDo opts (apats,dpats) cmd = do
|
||||||
path <- ledgerFilePath opts
|
path <- ledgerFilePath opts
|
||||||
parsed <- parseLedgerFile path
|
parsed <- parseLedgerFile path
|
||||||
case parsed of Left err -> parseError err
|
case parsed of Left err -> parseError err
|
||||||
Right l -> cmd $ cacheLedger l pats
|
Right l -> cmd $ cacheLedger l (regexFor apats, regexFor dpats)
|
||||||
|
|
||||||
-- ghci helpers
|
-- ghci helpers
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user