From fd00d9c1ccced4a013217c0036b7da5ee1f4cd48 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 14 Jul 2020 10:20:52 -0700 Subject: [PATCH] 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. --- hledger/Hledger/Cli/Commands/Tags.hs | 9 +++++++-- hledger/Hledger/Cli/Commands/Tags.md | 11 +++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/hledger/Hledger/Cli/Commands/Tags.hs b/hledger/Hledger/Cli/Commands/Tags.hs index 4b1f0e1a6..03242d4df 100755 --- a/hledger/Hledger/Cli/Commands/Tags.hs +++ b/hledger/Hledger/Cli/Commands/Tags.hs @@ -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 diff --git a/hledger/Hledger/Cli/Commands/Tags.md b/hledger/Hledger/Cli/Commands/Tags.md index 68cabb92c..1ce5c9584 100644 --- a/hledger/Hledger/Cli/Commands/Tags.md +++ b/hledger/Hledger/Cli/Commands/Tags.md @@ -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