validate --depth/depth:'s argument is positive

This commit is contained in:
Simon Michael 2015-08-28 09:57:30 -07:00
parent 4dd1e9c725
commit 0d02262463
2 changed files with 9 additions and 2 deletions

View File

@ -256,7 +256,11 @@ parseQueryTerm _ ('s':'t':'a':'t':'u':'s':':':s) =
parseQueryTerm _ ('r':'e':'a':'l':':':s) = Left $ Real $ parseBool s || null s
parseQueryTerm _ ('a':'m':'t':':':s) = Left $ Amt ord q where (ord, q) = parseAmountQueryTerm s
parseQueryTerm _ ('e':'m':'p':'t':'y':':':s) = Left $ Empty $ parseBool s
parseQueryTerm _ ('d':'e':'p':'t':'h':':':s) = Left $ Depth $ readDef 0 s
parseQueryTerm _ ('d':'e':'p':'t':'h':':':s)
| n >= 0 = Left $ Depth n
| otherwise = error' "depth: should have a positive number"
where n = readDef 0 s
parseQueryTerm _ ('c':'u':'r':':':s) = Left $ Sym s -- support cur: as an alias
parseQueryTerm _ ('t':'a':'g':':':s) = Left $ Tag n v where (n,v) = parseTag s
parseQueryTerm _ "" = Left $ Any

View File

@ -162,7 +162,10 @@ rawOptsToReportOpts rawopts = checkReportOpts <$> do
-- | Do extra validation of opts, raising an error if there is trouble.
checkReportOpts :: ReportOpts -> ReportOpts
checkReportOpts ropts@ReportOpts{..} =
ropts
either optserror (const ropts) $ do
case depth_ of
Just d | d < 0 -> Left "--depth should have a positive number"
_ -> Right ()
accountlistmodeopt :: RawOpts -> AccountListMode
accountlistmodeopt rawopts =