codes: new command for listing transaction codes
This commit is contained in:
parent
a7a01c0f9f
commit
3ad313d8fa
@ -27,6 +27,7 @@ module Hledger.Cli.Commands (
|
|||||||
,module Hledger.Cli.Commands.Checkdates
|
,module Hledger.Cli.Commands.Checkdates
|
||||||
,module Hledger.Cli.Commands.Checkdupes
|
,module Hledger.Cli.Commands.Checkdupes
|
||||||
,module Hledger.Cli.Commands.Close
|
,module Hledger.Cli.Commands.Close
|
||||||
|
,module Hledger.Cli.Commands.Codes
|
||||||
,module Hledger.Cli.Commands.Commodities
|
,module Hledger.Cli.Commands.Commodities
|
||||||
,module Hledger.Cli.Commands.Descriptions
|
,module Hledger.Cli.Commands.Descriptions
|
||||||
,module Hledger.Cli.Commands.Diff
|
,module Hledger.Cli.Commands.Diff
|
||||||
@ -72,6 +73,7 @@ import Hledger.Cli.Commands.Cashflow
|
|||||||
import Hledger.Cli.Commands.Checkdates
|
import Hledger.Cli.Commands.Checkdates
|
||||||
import Hledger.Cli.Commands.Checkdupes
|
import Hledger.Cli.Commands.Checkdupes
|
||||||
import Hledger.Cli.Commands.Close
|
import Hledger.Cli.Commands.Close
|
||||||
|
import Hledger.Cli.Commands.Codes
|
||||||
import Hledger.Cli.Commands.Commodities
|
import Hledger.Cli.Commands.Commodities
|
||||||
import Hledger.Cli.Commands.Descriptions
|
import Hledger.Cli.Commands.Descriptions
|
||||||
import Hledger.Cli.Commands.Diff
|
import Hledger.Cli.Commands.Diff
|
||||||
@ -107,6 +109,7 @@ builtinCommands = [
|
|||||||
,(checkdatesmode , checkdates)
|
,(checkdatesmode , checkdates)
|
||||||
,(checkdupesmode , checkdupes)
|
,(checkdupesmode , checkdupes)
|
||||||
,(closemode , close)
|
,(closemode , close)
|
||||||
|
,(codesmode , codes)
|
||||||
,(commoditiesmode , commodities)
|
,(commoditiesmode , commodities)
|
||||||
,(descriptionsmode , descriptions)
|
,(descriptionsmode , descriptions)
|
||||||
,(diffmode , diff)
|
,(diffmode , diff)
|
||||||
@ -180,6 +183,7 @@ commandsList = unlines [
|
|||||||
," accounts (a) show account names"
|
," accounts (a) show account names"
|
||||||
," activity show postings-per-interval bar charts"
|
," activity show postings-per-interval bar charts"
|
||||||
," balance (b, bal) show balance changes/end balances/budgets in accounts"
|
," balance (b, bal) show balance changes/end balances/budgets in accounts"
|
||||||
|
," codes show transaction codes"
|
||||||
," commodities show commodity/currency symbols"
|
," commodities show commodity/currency symbols"
|
||||||
," descriptions show unique transaction descriptions"
|
," descriptions show unique transaction descriptions"
|
||||||
," files show input file paths"
|
," files show input file paths"
|
||||||
|
|||||||
42
hledger/Hledger/Cli/Commands/Codes.hs
Normal file
42
hledger/Hledger/Cli/Commands/Codes.hs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
{-|
|
||||||
|
|
||||||
|
The @codes@ command lists the codes seen in transactions, in the order parsed.
|
||||||
|
|
||||||
|
-}
|
||||||
|
|
||||||
|
{-# LANGUAGE MultiWayIf #-}
|
||||||
|
{-# LANGUAGE NamedFieldPuns #-}
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE ScopedTypeVariables #-}
|
||||||
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
|
|
||||||
|
module Hledger.Cli.Commands.Codes (
|
||||||
|
codesmode
|
||||||
|
,codes
|
||||||
|
) where
|
||||||
|
|
||||||
|
import qualified Data.Text as T
|
||||||
|
import qualified Data.Text.IO as T
|
||||||
|
|
||||||
|
import Hledger
|
||||||
|
import Hledger.Cli.CliOptions
|
||||||
|
|
||||||
|
|
||||||
|
-- | Command line options for this command.
|
||||||
|
codesmode = hledgerCommandMode
|
||||||
|
$(embedFileRelative "Hledger/Cli/Commands/Codes.txt")
|
||||||
|
[]
|
||||||
|
[generalflagsgroup1]
|
||||||
|
hiddenflags
|
||||||
|
([], Just $ argsFlag "[QUERY]")
|
||||||
|
|
||||||
|
-- | The codes command.
|
||||||
|
codes :: CliOpts -> Journal -> IO ()
|
||||||
|
codes CliOpts{reportopts_=ropts@ReportOpts{empty_}} j = do
|
||||||
|
d <- getCurrentDay
|
||||||
|
let q = queryFromOpts d ropts
|
||||||
|
ts = entriesReport ropts q j
|
||||||
|
codes = (if empty_ then id else filter (not . T.null)) $
|
||||||
|
map tcode ts
|
||||||
|
|
||||||
|
mapM_ T.putStrLn codes
|
||||||
48
hledger/Hledger/Cli/Commands/Codes.md
Normal file
48
hledger/Hledger/Cli/Commands/Codes.md
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
codes\
|
||||||
|
List the codes seen in transactions, in the order parsed.
|
||||||
|
|
||||||
|
_FLAGS
|
||||||
|
|
||||||
|
This command prints the value of each transaction's code field, in the
|
||||||
|
order transactions were parsed. The transaction code is an optional
|
||||||
|
value written in parentheses between the date and description, often
|
||||||
|
used to store a cheque number, order number or similar.
|
||||||
|
|
||||||
|
Transactions aren't required to have a code, and missing or empty codes
|
||||||
|
will not be shown by default. With the `-E`/`--empty` flag, they will
|
||||||
|
be printed as blank lines.
|
||||||
|
|
||||||
|
You can add a query to select a subset of transactions.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
```journal
|
||||||
|
1/1 (123)
|
||||||
|
(a) 1
|
||||||
|
|
||||||
|
1/1 ()
|
||||||
|
(a) 1
|
||||||
|
|
||||||
|
1/1
|
||||||
|
(a) 1
|
||||||
|
|
||||||
|
1/1 (126)
|
||||||
|
(a) 1
|
||||||
|
```
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ hledger codes
|
||||||
|
123
|
||||||
|
124
|
||||||
|
126
|
||||||
|
```
|
||||||
|
|
||||||
|
```shell
|
||||||
|
$ hledger codes -E
|
||||||
|
123
|
||||||
|
124
|
||||||
|
|
||||||
|
|
||||||
|
126
|
||||||
|
```
|
||||||
|
|
||||||
41
hledger/Hledger/Cli/Commands/Codes.txt
Normal file
41
hledger/Hledger/Cli/Commands/Codes.txt
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
codes
|
||||||
|
List the codes seen in transactions, in the order parsed.
|
||||||
|
|
||||||
|
_FLAGS
|
||||||
|
|
||||||
|
This command prints the value of each transaction's code field, in the
|
||||||
|
order transactions were parsed. The transaction code is an optional
|
||||||
|
value written in parentheses between the date and description, often
|
||||||
|
used to store a cheque number, order number or similar.
|
||||||
|
|
||||||
|
Transactions aren't required to have a code, and missing or empty codes
|
||||||
|
will not be shown by default. With the -E/--empty flag, they will be
|
||||||
|
printed as blank lines.
|
||||||
|
|
||||||
|
You can add a query to select a subset of transactions.
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
1/1 (123)
|
||||||
|
(a) 1
|
||||||
|
|
||||||
|
1/1 ()
|
||||||
|
(a) 1
|
||||||
|
|
||||||
|
1/1
|
||||||
|
(a) 1
|
||||||
|
|
||||||
|
1/1 (126)
|
||||||
|
(a) 1
|
||||||
|
|
||||||
|
$ hledger codes
|
||||||
|
123
|
||||||
|
124
|
||||||
|
126
|
||||||
|
|
||||||
|
$ hledger codes -E
|
||||||
|
123
|
||||||
|
124
|
||||||
|
|
||||||
|
|
||||||
|
126
|
||||||
@ -1581,6 +1581,10 @@ _include_({{Hledger/Cli/Commands/Checkdupes.md}})
|
|||||||
|
|
||||||
_include_({{Hledger/Cli/Commands/Close.md}})
|
_include_({{Hledger/Cli/Commands/Close.md}})
|
||||||
|
|
||||||
|
## codes
|
||||||
|
|
||||||
|
_include_({{Hledger/Cli/Commands/Codes.md}})
|
||||||
|
|
||||||
## commodities
|
## commodities
|
||||||
|
|
||||||
_include_({{Hledger/Cli/Commands/Commodities.md}})
|
_include_({{Hledger/Cli/Commands/Commodities.md}})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user