bin: new hledger-tags addon, lists tags in matched transactions
This commit is contained in:
		
							parent
							
								
									15e8d77968
								
							
						
					
					
						commit
						e908d96fd9
					
				
							
								
								
									
										43
									
								
								bin/hledger-tags.hs
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										43
									
								
								bin/hledger-tags.hs
									
									
									
									
									
										Executable 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 | ||||
| @ -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) | ||||
| 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. | ||||
| 
 | ||||
|  | ||||
| @ -2432,6 +2432,9 @@ transactions when importing. | ||||
| .PP | ||||
| hledger\-rewrite.hs Adds one or more custom postings to matched | ||||
| transactions. | ||||
| .SS tags | ||||
| .PP | ||||
| hledger\-tags.hs Lists tag names in use. | ||||
| .SH ENVIRONMENT | ||||
| .PP | ||||
| \f[B]COLUMNS\f[] The screen width used by the register command. | ||||
|  | ||||
| @ -1972,6 +1972,7 @@ start making your own! | ||||
| * print-unique:: | ||||
| * register-match:: | ||||
| * rewrite:: | ||||
| * tags:: | ||||
| 
 | ||||
|  | ||||
| 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. | ||||
| 
 | ||||
|  | ||||
| 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 | ||||
| -------------- | ||||
| @ -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 | ||||
| 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: | ||||
| Node: Top70 | ||||
| @ -2170,27 +2179,29 @@ Node: irr64701 | ||||
| Ref: #irr64801 | ||||
| Node: Experimental add-ons64879 | ||||
| Ref: #experimental-add-ons65033 | ||||
| Node: autosync65426 | ||||
| Ref: #autosync65540 | ||||
| Node: budget65779 | ||||
| Ref: #budget65903 | ||||
| Node: chart65969 | ||||
| Ref: #chart66088 | ||||
| Node: check66159 | ||||
| Ref: #check66283 | ||||
| Node: check-dates66350 | ||||
| Ref: #check-dates66492 | ||||
| Node: check-dupes66565 | ||||
| Ref: #check-dupes66708 | ||||
| Node: equity66785 | ||||
| Ref: #equity66913 | ||||
| Node: prices67032 | ||||
| Ref: #prices67161 | ||||
| Node: print-unique67216 | ||||
| Ref: #print-unique67365 | ||||
| Node: register-match67458 | ||||
| Ref: #register-match67614 | ||||
| Node: rewrite67712 | ||||
| Ref: #rewrite67833 | ||||
| Node: autosync65435 | ||||
| Ref: #autosync65549 | ||||
| Node: budget65788 | ||||
| Ref: #budget65912 | ||||
| Node: chart65978 | ||||
| Ref: #chart66097 | ||||
| Node: check66168 | ||||
| Ref: #check66292 | ||||
| Node: check-dates66359 | ||||
| Ref: #check-dates66501 | ||||
| Node: check-dupes66574 | ||||
| Ref: #check-dupes66717 | ||||
| Node: equity66794 | ||||
| Ref: #equity66922 | ||||
| Node: prices67041 | ||||
| Ref: #prices67170 | ||||
| Node: print-unique67225 | ||||
| Ref: #print-unique67374 | ||||
| Node: register-match67467 | ||||
| Ref: #register-match67623 | ||||
| Node: rewrite67721 | ||||
| Ref: #rewrite67855 | ||||
| Node: tags67933 | ||||
| Ref: #tags68038 | ||||
|  | ||||
| End Tag Table | ||||
|  | ||||
| @ -1738,6 +1738,9 @@ ADD-ON COMMANDS | ||||
|        hledger-rewrite.hs Adds one or more custom postings to matched transac- | ||||
|        tions. | ||||
| 
 | ||||
|    tags | ||||
|        hledger-tags.hs Lists tag names in use. | ||||
| 
 | ||||
| ENVIRONMENT | ||||
|        COLUMNS  The  screen  width used by the register command.  Default: the | ||||
|        full terminal width. | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user