tag: first arg filters tag names, the rest filter transactions (#261)

This commit is contained in:
Simon Michael 2017-10-17 07:05:36 -07:00
parent bf234431ef
commit 24d8336728
2 changed files with 20 additions and 10 deletions

View File

@ -9,26 +9,34 @@ where
import Data.List import Data.List
import Data.String.Here import Data.String.Here
import qualified Data.Text.IO as T import qualified Data.Text as T
import Safe
import Hledger import Hledger
import Hledger.Cli.CliOptions import Hledger.Cli.CliOptions
tagsmode = hledgerCommandMode tagsmode = hledgerCommandMode
[here| tags [here| tags
List all the tag names in use. List all the tag names used in the journal. With a TAGREGEX argument,
With a query, only matched transactions' tags are shown. only tag names matching the regular expression (case insensitive) are shown.
With QUERY arguments, only transactions matching the query are considered.
Reads the default journal file, or another specified with -f. Reads the default journal file, or another specified with -f.
FLAGS FLAGS
|] |]
[] -- [flagNone ["strict"] (\opts -> setboolopt "strict" opts) "makes date comparing strict"] -- [] -- [flagNone ["strict"] (\opts -> setboolopt "strict" opts) "makes date comparing strict"] --
[generalflagsgroup1] [generalflagsgroup1]
[] []
([], Just $ argsFlag "[QUERY]") ([], Just $ argsFlag "[TAGREGEX [QUERY...]]")
tags CliOpts{rawopts_=_rawopts,reportopts_=ropts} j = do tags CliOpts{rawopts_=rawopts,reportopts_=ropts} j = do
d <- getCurrentDay d <- getCurrentDay
let let
q = queryFromOpts d ropts args = listofstringopt "args" rawopts
ts = filter (q `matchesTransaction`) $ jtxns $ journalSelectingAmountFromOpts ropts j mtagpats = headMay args
tags = nub $ sort $ map fst $ concatMap transactionAllTags ts queryargs = drop 1 args
mapM_ T.putStrLn tags q = queryFromOpts d $ ropts{query_ = unwords queryargs}
txns = filter (q `matchesTransaction`) $ jtxns $ journalSelectingAmountFromOpts ropts j
tags =
nub $ sort $
(maybe id (filter . regexMatchesCI) mtagpats) $
map (T.unpack . fst) $ concatMap transactionAllTags txns
mapM_ putStrLn tags

View File

@ -766,7 +766,9 @@ The stats command also supports `-o/--output-file`
for controlling [output destination](#output-destination). for controlling [output destination](#output-destination).
## tags ## tags
List all the tag names in use. List all the tag names used in the journal. With a TAGREGEX argument,
only tag names matching the regular expression (case insensitive) are shown.
With additional QUERY arguments, only transactions matching the query are considered.
## test ## test
Run built-in unit tests. Run built-in unit tests.