imp: reg --sort: show supported keys in help and error message [#2211]
This commit is contained in:
parent
3b73360584
commit
5cbbdb4670
@ -23,6 +23,7 @@ module Hledger.Reports.ReportOptions (
|
|||||||
HasReportSpec(..),
|
HasReportSpec(..),
|
||||||
SortField(..),
|
SortField(..),
|
||||||
SortSpec,
|
SortSpec,
|
||||||
|
sortKeysDescription,
|
||||||
overEither,
|
overEither,
|
||||||
setEither,
|
setEither,
|
||||||
BalanceCalculation(..),
|
BalanceCalculation(..),
|
||||||
@ -696,18 +697,20 @@ getSortSpec opts =
|
|||||||
optParser s =
|
optParser s =
|
||||||
let terms = map strip $ splitAtElement ',' s
|
let terms = map strip $ splitAtElement ',' s
|
||||||
termParser t = case trimmed of
|
termParser t = case trimmed of
|
||||||
"date" -> Date' isNegated
|
"date" -> Date' isNegated
|
||||||
"account" -> Account' isNegated
|
"desc" -> Description' isNegated
|
||||||
"amount" -> Amount' isNegated
|
|
||||||
"desc" -> Description' isNegated
|
|
||||||
"description" -> Description' isNegated
|
"description" -> Description' isNegated
|
||||||
"absamount" -> AbsAmount' isNegated
|
"account" -> Account' isNegated
|
||||||
_ -> error' $ "unsupported field '" ++ t ++ "' given to --sort"
|
"amount" -> Amount' isNegated
|
||||||
|
"absamount" -> AbsAmount' isNegated
|
||||||
|
_ -> error' $ "unknown --sort key " ++ t ++ ". Supported keys are: " <> sortKeysDescription <> "."
|
||||||
where isNegated = isPrefixOf "-" t
|
where isNegated = isPrefixOf "-" t
|
||||||
trimmed = fromMaybe t (stripPrefix "-" t)
|
trimmed = fromMaybe t (stripPrefix "-" t)
|
||||||
in map termParser terms
|
in map termParser terms
|
||||||
in maybe defsortspec optParser opt
|
in maybe defsortspec optParser opt
|
||||||
|
|
||||||
|
-- for option's help and parse error message
|
||||||
|
sortKeysDescription = "date, desc, account, amount, absamount" -- 'description' is also accepted
|
||||||
|
|
||||||
-- Report dates.
|
-- Report dates.
|
||||||
|
|
||||||
|
|||||||
@ -50,7 +50,8 @@ registermode = hledgerCommandMode
|
|||||||
,flagNone ["related","r"] (setboolopt "related") "show postings' siblings instead"
|
,flagNone ["related","r"] (setboolopt "related") "show postings' siblings instead"
|
||||||
,flagNone ["invert"] (setboolopt "invert") "display all amounts with reversed sign"
|
,flagNone ["invert"] (setboolopt "invert") "display all amounts with reversed sign"
|
||||||
,flagReq ["sort"] (\s opts -> Right $ setopt "sort" s opts) "FIELDS"
|
,flagReq ["sort"] (\s opts -> Right $ setopt "sort" s opts) "FIELDS"
|
||||||
"comma-separated list of fields used to sort transactions"
|
("sort by: " <> sortKeysDescription
|
||||||
|
<> ", or a comma-separated combination of these. For a descending sort, prefix with -. (Default: date)")
|
||||||
,flagReq ["width","w"] (\s opts -> Right $ setopt "width" s opts) "N"
|
,flagReq ["width","w"] (\s opts -> Right $ setopt "width" s opts) "N"
|
||||||
("set output width (default: " ++
|
("set output width (default: " ++
|
||||||
#ifdef mingw32_HOST_OS
|
#ifdef mingw32_HOST_OS
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user