tags: add --parsed flag, hide empties without --empty
With --parsed flag, all tags or values are shown in the order they are parsed from the input data, including duplicates. With -E/--empty, any blank/empty values will also be shown, otherwise they are omitted.
This commit is contained in:
parent
febd8bb457
commit
fd00d9c1cc
@ -18,6 +18,7 @@ import Hledger.Cli.CliOptions
|
||||
tagsmode = hledgerCommandMode
|
||||
$(embedFileRelative "Hledger/Cli/Commands/Tags.txt")
|
||||
[flagNone ["values"] (setboolopt "values") "list tag values instead of tag names"
|
||||
,flagNone ["parsed"] (setboolopt "parsed") "show tags/values in the order they were parsed, including duplicates"
|
||||
]
|
||||
[generalflagsgroup1]
|
||||
hiddenflags
|
||||
@ -30,12 +31,16 @@ tags CliOpts{rawopts_=rawopts,reportopts_=ropts} j = do
|
||||
mtagpat = headMay args
|
||||
queryargs = drop 1 args
|
||||
values = boolopt "values" rawopts
|
||||
parsed = boolopt "parsed" rawopts
|
||||
empty = empty_ ropts
|
||||
q = queryFromOpts d $ ropts{query_ = unwords $ map quoteIfNeeded queryargs}
|
||||
txns = filter (q `matchesTransaction`) $ jtxns $ journalSelectingAmountFromOpts ropts j
|
||||
tagsorvalues =
|
||||
nubSort $
|
||||
[if values then v else t
|
||||
(if parsed then id else nubSort)
|
||||
[ r
|
||||
| (t,v) <- concatMap transactionAllTags txns
|
||||
, maybe True (`regexMatchesCI` T.unpack t) mtagpat
|
||||
, let r = if values then v else t
|
||||
, not (values && T.null v && not empty)
|
||||
]
|
||||
mapM_ T.putStrLn tagsorvalues
|
||||
|
||||
@ -1,7 +1,14 @@
|
||||
tags\
|
||||
List all the tag names used in the journal. With a TAGREGEX argument,
|
||||
List the unique tag names used in the journal. With a TAGREGEX argument,
|
||||
only tag names matching the regular expression (case insensitive) are shown.
|
||||
With QUERY arguments, only transactions matching the query are considered.
|
||||
With --values flag, the tags' unique values are listed instead.
|
||||
|
||||
With the --values flag, the tags' unique values are listed instead.
|
||||
|
||||
With --parsed flag, all tags or values are shown in the order they
|
||||
are parsed from the input data, including duplicates.
|
||||
|
||||
With -E/--empty, any blank/empty values will also be shown, otherwise
|
||||
they are omitted.
|
||||
|
||||
_FLAGS
|
||||
|
||||
Loading…
Reference in New Issue
Block a user