cli: make tags a builtin command

This commit is contained in:
Simon Michael 2017-09-12 19:54:39 -07:00
parent d2d7dbbce0
commit e3902ebc6f
7 changed files with 43 additions and 47 deletions

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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.

View File

@ -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.

View File

@ -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:

View File

@ -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: