cli: --forecast now rejects instead of silently ignoring an interval
Something that confused me when testing #1632.
This commit is contained in:
parent
d3d1b2cfc7
commit
993d0b5c54
@ -165,6 +165,7 @@ import Hledger.Reports.ReportOptions (ReportOpts(..), queryFromFlags, rawOptsToR
|
|||||||
import Hledger.Utils
|
import Hledger.Utils
|
||||||
import Text.Printf (printf)
|
import Text.Printf (printf)
|
||||||
import Hledger.Read.InputOptions
|
import Hledger.Read.InputOptions
|
||||||
|
import Data.String.Compat (unlines)
|
||||||
|
|
||||||
--- ** doctest setup
|
--- ** doctest setup
|
||||||
-- $setup
|
-- $setup
|
||||||
@ -254,15 +255,24 @@ rawOptsToInputOpts rawopts = do
|
|||||||
}
|
}
|
||||||
where noinferprice = boolopt "strict" rawopts || stringopt "args" rawopts == "balancednoautoconversion"
|
where noinferprice = boolopt "strict" rawopts || stringopt "args" rawopts == "balancednoautoconversion"
|
||||||
|
|
||||||
-- | Get period expression from --forecast option.
|
-- | Get the date span from --forecast's PERIODEXPR argument, if any.
|
||||||
-- This will fail with a usage error if the forecast period expression cannot be parsed.
|
-- This will fail with a usage error if the period expression cannot be parsed,
|
||||||
|
-- or if it contains a report interval.
|
||||||
forecastPeriodFromRawOpts :: Day -> RawOpts -> Maybe DateSpan
|
forecastPeriodFromRawOpts :: Day -> RawOpts -> Maybe DateSpan
|
||||||
forecastPeriodFromRawOpts d rawopts = case maybestringopt "forecast" rawopts of
|
forecastPeriodFromRawOpts d rawopts = case maybestringopt "forecast" rawopts of
|
||||||
Nothing -> Nothing
|
Nothing -> Nothing
|
||||||
Just "" -> Just forecastspanDefault
|
Just "" -> Just forecastspanDefault
|
||||||
Just str -> either (\e -> usageError $ "could not parse forecast period : "++customErrorBundlePretty e)
|
Just arg ->
|
||||||
(\(_,requestedspan) -> Just $ requestedspan `spanDefaultsFrom` forecastspanDefault) $
|
either
|
||||||
parsePeriodExpr d $ stripquotes $ T.pack str
|
(\e -> usageError $ "could not parse forecast period : "++customErrorBundlePretty e)
|
||||||
|
(\(interval, requestedspan) ->
|
||||||
|
case interval of
|
||||||
|
NoInterval -> Just $ requestedspan `spanDefaultsFrom` forecastspanDefault
|
||||||
|
_ -> usageError $ unlines
|
||||||
|
[ "--forecast's argument should not contain a report interval"
|
||||||
|
, "(" ++ show interval ++ " in \"" ++ arg ++ "\")"
|
||||||
|
])
|
||||||
|
(parsePeriodExpr d $ stripquotes $ T.pack arg)
|
||||||
where
|
where
|
||||||
-- "They end on or before the specified report end date, or 180 days from today if unspecified."
|
-- "They end on or before the specified report end date, or 180 days from today if unspecified."
|
||||||
mspecifiedend = dbg2 "specifieddates" $ queryEndDate False datequery
|
mspecifiedend = dbg2 "specifieddates" $ queryEndDate False datequery
|
||||||
|
|||||||
@ -3189,7 +3189,7 @@ Note:
|
|||||||
- the equals sign is required (a space won't work)
|
- the equals sign is required (a space won't work)
|
||||||
- PERIODEXPR can specify the forecast period's start and/or end dates
|
- PERIODEXPR can specify the forecast period's start and/or end dates
|
||||||
(similar to [Report start & end date](#report-start--end-date))
|
(similar to [Report start & end date](#report-start--end-date))
|
||||||
- PERIODEXPR shouldn't specify a report interval; that would be ignored, as it is specified by the periodic rules in the journal.
|
- PERIODEXPR shouldn't specify a report interval; each periodic transaction rule specifies its own.
|
||||||
|
|
||||||
Some examples: `--forecast=202001-202004`, `--forecast=jan-`, `--forecast=2020`.
|
Some examples: `--forecast=202001-202004`, `--forecast=jan-`, `--forecast=2020`.
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user