Show error message on conflicting --sort and -H
This commit is contained in:
parent
4b564966c9
commit
b429f57afb
@ -16,6 +16,7 @@ module Hledger.Reports.PostingsReport (
|
||||
postingsReport,
|
||||
mkpostingsReportItem,
|
||||
SortSpec,
|
||||
defsortspec,
|
||||
|
||||
-- * Tests
|
||||
tests_PostingsReport
|
||||
@ -89,7 +90,7 @@ postingsReport rspec@ReportSpec{_rsReportOpts=ropts@ReportOpts{..}} j = items
|
||||
-- Posting report items ready for display.
|
||||
items =
|
||||
dbg4 "postingsReport items" $
|
||||
postingsReportItems sortedps (nullposting,Nothing) whichdate mdepth startbal runningcalc startnum
|
||||
postingsReportItems postings (nullposting,Nothing) whichdate mdepth startbal runningcalc startnum
|
||||
where
|
||||
-- In historical mode we'll need a starting balance, which we
|
||||
-- may be converting to value per hledger_options.m4.md "Effect
|
||||
@ -104,6 +105,10 @@ postingsReport rspec@ReportSpec{_rsReportOpts=ropts@ReportOpts{..}} j = items
|
||||
|
||||
runningcalc = registerRunningCalculationFn ropts
|
||||
startnum = if historical then length precedingps + 1 else 1
|
||||
postings | historical = if sortspec_ /= defsortspec
|
||||
then error "--historical and --sort should not be used together"
|
||||
else sortedps
|
||||
| otherwise = sortedps
|
||||
|
||||
-- | Based on the given report options, return a function that does the appropriate
|
||||
-- running calculation for the register report, ie a running average or running total.
|
||||
|
||||
@ -33,6 +33,7 @@ module Hledger.Reports.ReportOptions (
|
||||
defreportopts,
|
||||
rawOptsToReportOpts,
|
||||
defreportspec,
|
||||
defsortspec,
|
||||
setDefaultConversionOp,
|
||||
reportOptsToSpec,
|
||||
updateReportSpec,
|
||||
@ -678,9 +679,12 @@ data SortField
|
||||
= Date' Bool
|
||||
| Account' Bool
|
||||
| Amount' Bool
|
||||
deriving (Show)
|
||||
deriving (Show, Eq)
|
||||
type SortSpec = [SortField]
|
||||
|
||||
defsortspec :: SortSpec
|
||||
defsortspec = [Date' False]
|
||||
|
||||
-- Load a SortSpec from the argument given to --sort
|
||||
-- If there is no spec given, then sort by [Date' False] by default
|
||||
getSortSpec :: RawOpts -> SortSpec
|
||||
@ -696,7 +700,7 @@ getSortSpec opts =
|
||||
where isNegated = isPrefixOf "-" t
|
||||
trimmed = fromMaybe t (stripPrefix "-" t)
|
||||
in map termParser terms
|
||||
in maybe [Date' False] optParser opt
|
||||
in maybe defsortspec optParser opt
|
||||
|
||||
|
||||
-- Report dates.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user