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:
Simon Michael 2020-07-14 10:20:52 -07:00
parent febd8bb457
commit fd00d9c1cc
2 changed files with 16 additions and 4 deletions

View File

@ -18,6 +18,7 @@ import Hledger.Cli.CliOptions
tagsmode = hledgerCommandMode tagsmode = hledgerCommandMode
$(embedFileRelative "Hledger/Cli/Commands/Tags.txt") $(embedFileRelative "Hledger/Cli/Commands/Tags.txt")
[flagNone ["values"] (setboolopt "values") "list tag values instead of tag names" [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] [generalflagsgroup1]
hiddenflags hiddenflags
@ -30,12 +31,16 @@ tags CliOpts{rawopts_=rawopts,reportopts_=ropts} j = do
mtagpat = headMay args mtagpat = headMay args
queryargs = drop 1 args queryargs = drop 1 args
values = boolopt "values" rawopts values = boolopt "values" rawopts
parsed = boolopt "parsed" rawopts
empty = empty_ ropts
q = queryFromOpts d $ ropts{query_ = unwords $ map quoteIfNeeded queryargs} q = queryFromOpts d $ ropts{query_ = unwords $ map quoteIfNeeded queryargs}
txns = filter (q `matchesTransaction`) $ jtxns $ journalSelectingAmountFromOpts ropts j txns = filter (q `matchesTransaction`) $ jtxns $ journalSelectingAmountFromOpts ropts j
tagsorvalues = tagsorvalues =
nubSort $ (if parsed then id else nubSort)
[if values then v else t [ r
| (t,v) <- concatMap transactionAllTags txns | (t,v) <- concatMap transactionAllTags txns
, maybe True (`regexMatchesCI` T.unpack t) mtagpat , 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 mapM_ T.putStrLn tagsorvalues

View File

@ -1,7 +1,14 @@
tags\ 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. only tag names matching the regular expression (case insensitive) are shown.
With QUERY arguments, only transactions matching the query are considered. 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 _FLAGS