bin: new hledger-tags addon, lists tags in matched transactions

This commit is contained in:
Simon Michael 2017-07-12 22:11:36 +01:00
parent 15e8d77968
commit e908d96fd9
5 changed files with 88 additions and 23 deletions

43
bin/hledger-tags.hs Executable file
View File

@ -0,0 +1,43 @@
#!/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
import Text.Printf
------------------------------------------------------------------------------
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

@ -124,3 +124,8 @@ helps ledger-autosync detect already-seen transactions when importing.
[hledger-rewrite.hs](https://github.com/simonmichael/hledger/blob/master/bin/hledger-rewrite.hs#L28) [hledger-rewrite.hs](https://github.com/simonmichael/hledger/blob/master/bin/hledger-rewrite.hs#L28)
Adds one or more custom postings to matched transactions. Adds one or more custom postings to matched transactions.
### tags
[hledger-tags.hs](https://github.com/simonmichael/hledger/blob/master/bin/hledger-tags.hs)
Lists tag names in use.

View File

@ -2432,6 +2432,9 @@ transactions when importing.
.PP .PP
hledger\-rewrite.hs Adds one or more custom postings to matched hledger\-rewrite.hs Adds one or more custom postings to matched
transactions. transactions.
.SS tags
.PP
hledger\-tags.hs Lists tag names in use.
.SH ENVIRONMENT .SH ENVIRONMENT
.PP .PP
\f[B]COLUMNS\f[] The screen width used by the register command. \f[B]COLUMNS\f[] The screen width used by the register command.

View File

@ -1972,6 +1972,7 @@ start making your own!
* print-unique:: * print-unique::
* register-match:: * register-match::
* rewrite:: * rewrite::
* tags::
 
File: hledger.1.info, Node: autosync, Next: budget, Up: Experimental add-ons File: hledger.1.info, Node: autosync, Next: budget, Up: Experimental add-ons
@ -2061,7 +2062,7 @@ hledger-register-match.hs helps ledger-autosync detect already-seen
transactions when importing. transactions when importing.
 
File: hledger.1.info, Node: rewrite, Prev: register-match, Up: Experimental add-ons File: hledger.1.info, Node: rewrite, Next: tags, Prev: register-match, Up: Experimental add-ons
5.3.11 rewrite 5.3.11 rewrite
-------------- --------------
@ -2069,6 +2070,14 @@ File: hledger.1.info, Node: rewrite, Prev: register-match, Up: Experimental a
hledger-rewrite.hs Adds one or more custom postings to matched hledger-rewrite.hs Adds one or more custom postings to matched
transactions. transactions.

File: hledger.1.info, Node: tags, Prev: rewrite, Up: Experimental add-ons
5.3.12 tags
-----------
hledger-tags.hs Lists tag names in use.
 
Tag Table: Tag Table:
Node: Top70 Node: Top70
@ -2170,27 +2179,29 @@ Node: irr64701
Ref: #irr64801 Ref: #irr64801
Node: Experimental add-ons64879 Node: Experimental add-ons64879
Ref: #experimental-add-ons65033 Ref: #experimental-add-ons65033
Node: autosync65426 Node: autosync65435
Ref: #autosync65540 Ref: #autosync65549
Node: budget65779 Node: budget65788
Ref: #budget65903 Ref: #budget65912
Node: chart65969 Node: chart65978
Ref: #chart66088 Ref: #chart66097
Node: check66159 Node: check66168
Ref: #check66283 Ref: #check66292
Node: check-dates66350 Node: check-dates66359
Ref: #check-dates66492 Ref: #check-dates66501
Node: check-dupes66565 Node: check-dupes66574
Ref: #check-dupes66708 Ref: #check-dupes66717
Node: equity66785 Node: equity66794
Ref: #equity66913 Ref: #equity66922
Node: prices67032 Node: prices67041
Ref: #prices67161 Ref: #prices67170
Node: print-unique67216 Node: print-unique67225
Ref: #print-unique67365 Ref: #print-unique67374
Node: register-match67458 Node: register-match67467
Ref: #register-match67614 Ref: #register-match67623
Node: rewrite67712 Node: rewrite67721
Ref: #rewrite67833 Ref: #rewrite67855
Node: tags67933
Ref: #tags68038
 
End Tag Table End Tag Table

View File

@ -1738,6 +1738,9 @@ ADD-ON COMMANDS
hledger-rewrite.hs Adds one or more custom postings to matched transac- hledger-rewrite.hs Adds one or more custom postings to matched transac-
tions. tions.
tags
hledger-tags.hs Lists tag names in use.
ENVIRONMENT ENVIRONMENT
COLUMNS The screen width used by the register command. Default: the COLUMNS The screen width used by the register command. Default: the
full terminal width. full terminal width.