diff --git a/bin/hledger-tags.hs b/bin/hledger-tags.hs deleted file mode 100755 index 325dd3327..000000000 --- a/bin/hledger-tags.hs +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env stack -{- stack runghc --verbosity info - --package hledger-lib - --package hledger - --package here - --package text --} - -{-# OPTIONS_GHC -Wno-missing-signatures -Wno-name-shadowing #-} -{-# LANGUAGE QuasiQuotes #-} - -import Data.List -import Data.String.Here -import qualified Data.Text.IO as T -import Hledger -import Hledger.Cli - ------------------------------------------------------------------------------- -cmdmode = hledgerCommandMode - [here| tags -List all the tag names in use. -With a query, only matched transactions' tags are shown. -Reads the default journal file, or another specified with -f. -FLAGS - |] - [] -- [flagNone ["strict"] (\opts -> setboolopt "strict" opts) "makes date comparing strict"] -- - [generalflagsgroup1] - [] - ([], Just $ argsFlag "[QUERY]") ------------------------------------------------------------------------------- - -main :: IO () -main = do - opts <- getHledgerCliOpts cmdmode - withJournalDo opts $ - \CliOpts{rawopts_=_rawopts,reportopts_=ropts} j -> do - d <- getCurrentDay - let - q = queryFromOpts d ropts - ts = filter (q `matchesTransaction`) $ jtxns $ journalSelectingAmountFromOpts ropts j - tags = nub $ sort $ map fst $ concatMap transactionAllTags ts - mapM_ T.putStrLn tags diff --git a/hledger/Hledger/Cli/Commands.hs b/hledger/Hledger/Cli/Commands.hs index 261362efd..b468226aa 100644 --- a/hledger/Hledger/Cli/Commands.hs +++ b/hledger/Hledger/Cli/Commands.hs @@ -30,6 +30,7 @@ module Hledger.Cli.Commands ( ,module Hledger.Cli.Commands.Registermatch ,module Hledger.Cli.Commands.Rewrite ,module Hledger.Cli.Commands.Stats + ,module Hledger.Cli.Commands.Tags ) where @@ -66,6 +67,7 @@ import Hledger.Cli.Commands.Register import Hledger.Cli.Commands.Registermatch import Hledger.Cli.Commands.Rewrite import Hledger.Cli.Commands.Stats +import Hledger.Cli.Commands.Tags -- | The cmdargs subcommand mode and IO action for each builtin command. diff --git a/hledger/Hledger/Cli/Commands/Tags.hs b/hledger/Hledger/Cli/Commands/Tags.hs new file mode 100755 index 000000000..dae289c70 --- /dev/null +++ b/hledger/Hledger/Cli/Commands/Tags.hs @@ -0,0 +1,34 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE QuasiQuotes #-} + +module Hledger.Cli.Commands.Tags ( + tagsmode + ,tags +) +where + +import Data.List +import Data.String.Here +import qualified Data.Text.IO as T +import Hledger +import Hledger.Cli.CliOptions + +tagsmode = hledgerCommandMode + [here| tags +List all the tag names in use. +With a query, only matched transactions' tags are shown. +Reads the default journal file, or another specified with -f. +FLAGS + |] + [] -- [flagNone ["strict"] (\opts -> setboolopt "strict" opts) "makes date comparing strict"] -- + [generalflagsgroup1] + [] + ([], Just $ argsFlag "[QUERY]") + +tags CliOpts{rawopts_=_rawopts,reportopts_=ropts} j = do + d <- getCurrentDay + let + q = queryFromOpts d ropts + ts = filter (q `matchesTransaction`) $ jtxns $ journalSelectingAmountFromOpts ropts j + tags = nub $ sort $ map fst $ concatMap transactionAllTags ts + mapM_ T.putStrLn tags diff --git a/hledger/doc/addons.m4.md b/hledger/doc/addons.m4.md index 63ea08bdc..ea0017e6e 100644 --- a/hledger/doc/addons.m4.md +++ b/hledger/doc/addons.m4.md @@ -89,8 +89,3 @@ is an old pie chart generator, in need of some love. [hledger-check.hs](https://github.com/simonmichael/hledger/blob/master/bin/hledger-check.hs) checks more powerful account balance assertions. -### tags - -[hledger-tags.hs](https://github.com/simonmichael/hledger/blob/master/bin/hledger-tags.hs) -Lists tag names in use. - diff --git a/hledger/doc/commands.m4.md b/hledger/doc/commands.m4.md index a707f5442..5aecd600a 100644 --- a/hledger/doc/commands.m4.md +++ b/hledger/doc/commands.m4.md @@ -715,6 +715,9 @@ it shows a report for each report period. The stats command also supports `-o/--output-file` for controlling [output destination](#output-destination). +## tags +List all the tag names in use. + ## test Run built-in unit tests. diff --git a/hledger/hledger.cabal b/hledger/hledger.cabal index 8d29abc5b..7628cb47d 100644 --- a/hledger/hledger.cabal +++ b/hledger/hledger.cabal @@ -97,6 +97,7 @@ library , cmdargs >=0.10 && <0.11 , csv , data-default >=0.5 + , Diff , hashable >=1.2.4 , haskeline >=0.6 && <=0.8 , HUnit @@ -139,7 +140,9 @@ library Hledger.Cli.Commands.Printunique Hledger.Cli.Commands.Register Hledger.Cli.Commands.Registermatch + Hledger.Cli.Commands.Rewrite Hledger.Cli.Commands.Stats + Hledger.Cli.Commands.Tags Hledger.Cli.CompoundBalanceCommand Text.Tabular.AsciiWide other-modules: diff --git a/hledger/package.yaml b/hledger/package.yaml index c28fce5ff..53cc23534 100644 --- a/hledger/package.yaml +++ b/hledger/package.yaml @@ -122,6 +122,7 @@ library: - Hledger.Cli.Commands.Registermatch - Hledger.Cli.Commands.Rewrite - Hledger.Cli.Commands.Stats + - Hledger.Cli.Commands.Tags - Hledger.Cli.CompoundBalanceCommand - Text.Tabular.AsciiWide dependencies: