patterns now use not: and desc: prefixes instead of ^ and ^^
This is more like but not the same as ledger 3.
This commit is contained in:
parent
4037d56080
commit
46c09c6fac
@ -147,8 +147,9 @@ match_negative_pats pats str = (not $ null ns) && (any match ns)
|
|||||||
match "" = True
|
match "" = True
|
||||||
match p = matchregex (abspat p) str
|
match p = matchregex (abspat p) str
|
||||||
|
|
||||||
isnegativepat pat = take 1 pat `elem` ["-","^"]
|
negateprefix = "not:"
|
||||||
abspat pat = if isnegativepat pat then drop 1 pat else pat
|
isnegativepat pat = negateprefix `isPrefixOf` pat
|
||||||
|
abspat pat = if isnegativepat pat then drop (length negateprefix) pat else pat
|
||||||
positivepats = filter (not . isnegativepat)
|
positivepats = filter (not . isnegativepat)
|
||||||
negativepats = filter isnegativepat
|
negativepats = filter isnegativepat
|
||||||
matchregex pat str = containsRegex (mkRegexWithOpts pat True True) str
|
matchregex pat str = containsRegex (mkRegexWithOpts pat True True) str
|
||||||
|
|||||||
30
Options.hs
30
Options.hs
@ -21,7 +21,7 @@ timelogenvvar = "TIMELOG"
|
|||||||
|
|
||||||
usagehdr = printf (
|
usagehdr = printf (
|
||||||
"Usage: one of\n" ++
|
"Usage: one of\n" ++
|
||||||
" %s [OPTIONS] COMMAND [ACCTPATTERNS] [-- DESCPATTERNS]\n" ++
|
" %s [OPTIONS] COMMAND [PATTERNS]\n" ++
|
||||||
" %s [OPTIONS] [PERIOD [COMMAND [PATTERNS]]]\n" ++
|
" %s [OPTIONS] [PERIOD [COMMAND [PATTERNS]]]\n" ++
|
||||||
"\n" ++
|
"\n" ++
|
||||||
"Commands (can be abbreviated):\n" ++
|
"Commands (can be abbreviated):\n" ++
|
||||||
@ -37,6 +37,10 @@ usagehdr = printf (
|
|||||||
#ifdef HAPPS
|
#ifdef HAPPS
|
||||||
" happs - run a web server providing a minimal web ui\n" ++
|
" happs - run a web server providing a minimal web ui\n" ++
|
||||||
#endif
|
#endif
|
||||||
|
"\n" ++
|
||||||
|
"PATTERNS are regular expressions which filter by account name.\n" ++
|
||||||
|
"Or, prefix with desc: to filter by entry description.\n" ++
|
||||||
|
"Or, prefix with not: to negate a pattern. (When using both, not: comes last.)\n" ++
|
||||||
"\n" ++
|
"\n" ++
|
||||||
"Options:"
|
"Options:"
|
||||||
) progname timeprogname
|
) progname timeprogname
|
||||||
@ -46,10 +50,6 @@ usageftr = printf (
|
|||||||
"\n" ++
|
"\n" ++
|
||||||
"All dates can be y/m/d or ledger-style smart dates like \"last month\".\n" ++
|
"All dates can be y/m/d or ledger-style smart dates like \"last month\".\n" ++
|
||||||
"\n" ++
|
"\n" ++
|
||||||
"Account and description patterns are regular expressions which filter by\n" ++
|
|
||||||
"account name and entry description. Prefix a pattern with ^ to negate it,\n" ++
|
|
||||||
"and separate account and description patterns with ^^.\n" ++
|
|
||||||
"\n" ++
|
|
||||||
"Also: %s [-v] test [TESTPATTERNS] to run self-tests.\n" ++
|
"Also: %s [-v] test [TESTPATTERNS] to run self-tests.\n" ++
|
||||||
"\n"
|
"\n"
|
||||||
) progname
|
) progname
|
||||||
@ -231,14 +231,16 @@ tildeExpand ('~':'/':xs) = getHomeDirectory >>= return . (++ ('/':xs))
|
|||||||
-- return (homeDirectory pw ++ path)
|
-- return (homeDirectory pw ++ path)
|
||||||
tildeExpand xs = return xs
|
tildeExpand xs = return xs
|
||||||
|
|
||||||
-- | Gather any ledger-style account/description pattern arguments into
|
-- | Gather any pattern arguments into a list of account patterns and a
|
||||||
-- two lists. These are 0 or more account patterns optionally followed by
|
-- list of description patterns. For now we interpret pattern arguments as
|
||||||
-- a separator and then 0 or more description patterns. Each pattern may
|
-- follows: those prefixed with "desc:" are description patterns, all
|
||||||
-- have a negation prefix. The separator and negation prefix are, for now,
|
-- others are account patterns. Also patterns prefixed with "not:" are
|
||||||
-- ^^ and ^ .
|
-- negated. not: should come after desc: if both are used.
|
||||||
|
-- This is different from ledger 2 and 3.
|
||||||
parseAccountDescriptionArgs :: [Opt] -> [String] -> ([String],[String])
|
parseAccountDescriptionArgs :: [Opt] -> [String] -> ([String],[String])
|
||||||
parseAccountDescriptionArgs opts args = (as, ds')
|
parseAccountDescriptionArgs opts args = (as, ds')
|
||||||
where (as, ds) = break (==patseparator) args
|
where
|
||||||
ds' = dropWhile (==patseparator) ds
|
descprefix = "desc:"
|
||||||
patseparator = replicate 2 negchar
|
(ds, as) = partition (descprefix `isPrefixOf`) args
|
||||||
negchar = '^'
|
ds' = map (drop (length descprefix)) ds
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user