lib: Remove checkReportOpts and checkRawOpts.
checkRawOpts has been a no-op for at least four years, and checkReportOpts only makes sure that depth_ is positive, which is taken care of by the maybeposintopt parser.
This commit is contained in:
parent
906da6e6bd
commit
f76cdc4317
@ -16,7 +16,6 @@ module Hledger.Reports.ReportOptions (
|
|||||||
FormatStr,
|
FormatStr,
|
||||||
defreportopts,
|
defreportopts,
|
||||||
rawOptsToReportOpts,
|
rawOptsToReportOpts,
|
||||||
checkReportOpts,
|
|
||||||
flat_,
|
flat_,
|
||||||
tree_,
|
tree_,
|
||||||
reportOptsToggleStatus,
|
reportOptsToggleStatus,
|
||||||
@ -173,69 +172,45 @@ defreportopts = ReportOpts
|
|||||||
def
|
def
|
||||||
|
|
||||||
rawOptsToReportOpts :: RawOpts -> IO ReportOpts
|
rawOptsToReportOpts :: RawOpts -> IO ReportOpts
|
||||||
rawOptsToReportOpts rawopts = checkReportOpts <$> do
|
rawOptsToReportOpts rawopts = do
|
||||||
let rawopts' = checkRawOpts rawopts
|
|
||||||
d <- getCurrentDay
|
d <- getCurrentDay
|
||||||
no_color <- isJust <$> lookupEnv "NO_COLOR"
|
no_color <- isJust <$> lookupEnv "NO_COLOR"
|
||||||
supports_color <- hSupportsANSIColor stdout
|
supports_color <- hSupportsANSIColor stdout
|
||||||
let colorflag = stringopt "color" rawopts
|
let colorflag = stringopt "color" rawopts
|
||||||
return defreportopts{
|
return defreportopts{
|
||||||
today_ = Just d
|
today_ = Just d
|
||||||
,period_ = periodFromRawOpts d rawopts'
|
,period_ = periodFromRawOpts d rawopts
|
||||||
,interval_ = intervalFromRawOpts rawopts'
|
,interval_ = intervalFromRawOpts rawopts
|
||||||
,statuses_ = statusesFromRawOpts rawopts'
|
,statuses_ = statusesFromRawOpts rawopts
|
||||||
,value_ = valuationTypeFromRawOpts rawopts'
|
,value_ = valuationTypeFromRawOpts rawopts
|
||||||
,infer_value_ = boolopt "infer-value" rawopts'
|
,infer_value_ = boolopt "infer-value" rawopts
|
||||||
,depth_ = maybeposintopt "depth" rawopts'
|
,depth_ = maybeposintopt "depth" rawopts
|
||||||
,date2_ = boolopt "date2" rawopts'
|
,date2_ = boolopt "date2" rawopts
|
||||||
,empty_ = boolopt "empty" rawopts'
|
,empty_ = boolopt "empty" rawopts
|
||||||
,no_elide_ = boolopt "no-elide" rawopts'
|
,no_elide_ = boolopt "no-elide" rawopts
|
||||||
,real_ = boolopt "real" rawopts'
|
,real_ = boolopt "real" rawopts
|
||||||
,format_ = maybestringopt "format" rawopts' -- XXX move to CliOpts or move validation from Cli.CliOptions to here
|
,format_ = maybestringopt "format" rawopts -- XXX move to CliOpts or move validation from Cli.CliOptions to here
|
||||||
,query_ = unwords . map quoteIfNeeded $ listofstringopt "args" rawopts' -- doesn't handle an arg like "" right
|
,query_ = unwords . map quoteIfNeeded $ listofstringopt "args" rawopts -- doesn't handle an arg like "" right
|
||||||
,average_ = boolopt "average" rawopts'
|
,average_ = boolopt "average" rawopts
|
||||||
,related_ = boolopt "related" rawopts'
|
,related_ = boolopt "related" rawopts
|
||||||
,txn_dates_ = boolopt "txn-dates" rawopts'
|
,txn_dates_ = boolopt "txn-dates" rawopts
|
||||||
,balancetype_ = balancetypeopt rawopts'
|
,balancetype_ = balancetypeopt rawopts
|
||||||
,accountlistmode_ = accountlistmodeopt rawopts'
|
,accountlistmode_ = accountlistmodeopt rawopts
|
||||||
,drop_ = posintopt "drop" rawopts'
|
,drop_ = posintopt "drop" rawopts
|
||||||
,row_total_ = boolopt "row-total" rawopts'
|
,row_total_ = boolopt "row-total" rawopts
|
||||||
,no_total_ = boolopt "no-total" rawopts'
|
,no_total_ = boolopt "no-total" rawopts
|
||||||
,sort_amount_ = boolopt "sort-amount" rawopts'
|
,sort_amount_ = boolopt "sort-amount" rawopts
|
||||||
,percent_ = boolopt "percent" rawopts'
|
,percent_ = boolopt "percent" rawopts
|
||||||
,invert_ = boolopt "invert" rawopts'
|
,invert_ = boolopt "invert" rawopts
|
||||||
,pretty_tables_ = boolopt "pretty-tables" rawopts'
|
,pretty_tables_ = boolopt "pretty-tables" rawopts
|
||||||
,color_ = and [not no_color
|
,color_ = and [not no_color
|
||||||
,not $ colorflag `elem` ["never","no"]
|
,not $ colorflag `elem` ["never","no"]
|
||||||
,colorflag `elem` ["always","yes"] || supports_color
|
,colorflag `elem` ["always","yes"] || supports_color
|
||||||
]
|
]
|
||||||
,forecast_ = forecastPeriodFromRawOpts d rawopts'
|
,forecast_ = forecastPeriodFromRawOpts d rawopts
|
||||||
,transpose_ = boolopt "transpose" rawopts'
|
,transpose_ = boolopt "transpose" rawopts
|
||||||
}
|
}
|
||||||
|
|
||||||
-- | Do extra validation of raw option values, raising an error if there's a problem.
|
|
||||||
checkRawOpts :: RawOpts -> RawOpts
|
|
||||||
checkRawOpts rawopts
|
|
||||||
-- our standard behaviour is to accept conflicting options actually,
|
|
||||||
-- using the last one - more forgiving for overriding command-line aliases
|
|
||||||
-- | countopts ["change","cumulative","historical"] > 1
|
|
||||||
-- = usageError "please specify at most one of --change, --cumulative, --historical"
|
|
||||||
-- | countopts ["flat","tree"] > 1
|
|
||||||
-- = usageError "please specify at most one of --flat, --tree"
|
|
||||||
-- | countopts ["daily","weekly","monthly","quarterly","yearly"] > 1
|
|
||||||
-- = usageError "please specify at most one of --daily, "
|
|
||||||
| otherwise = rawopts
|
|
||||||
-- where
|
|
||||||
-- countopts = length . filter (`boolopt` rawopts)
|
|
||||||
|
|
||||||
-- | Do extra validation of report options, raising an error if there's a problem.
|
|
||||||
checkReportOpts :: ReportOpts -> ReportOpts
|
|
||||||
checkReportOpts ropts@ReportOpts{..} =
|
|
||||||
either usageError (const ropts) $ do
|
|
||||||
case depth_ of
|
|
||||||
Just d | d < 0 -> Left "--depth should have a positive number"
|
|
||||||
_ -> Right ()
|
|
||||||
|
|
||||||
accountlistmodeopt :: RawOpts -> AccountListMode
|
accountlistmodeopt :: RawOpts -> AccountListMode
|
||||||
accountlistmodeopt =
|
accountlistmodeopt =
|
||||||
fromMaybe ALFlat . choiceopt parse where
|
fromMaybe ALFlat . choiceopt parse where
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user