payees: Split command into descriptions, payees, and notes

This commit is contained in:
Caleb Maclennan 2019-07-10 13:55:13 +03:00 committed by Simon Michael
parent 5d42578137
commit e68e558761
15 changed files with 204 additions and 22 deletions

View File

@ -28,10 +28,12 @@ module Hledger.Cli.Commands (
,module Hledger.Cli.Commands.Checkdupes ,module Hledger.Cli.Commands.Checkdupes
,module Hledger.Cli.Commands.Close ,module Hledger.Cli.Commands.Close
,module Hledger.Cli.Commands.Commodities ,module Hledger.Cli.Commands.Commodities
,module Hledger.Cli.Commands.Descriptions
,module Hledger.Cli.Commands.Diff ,module Hledger.Cli.Commands.Diff
,module Hledger.Cli.Commands.Help ,module Hledger.Cli.Commands.Help
,module Hledger.Cli.Commands.Import ,module Hledger.Cli.Commands.Import
,module Hledger.Cli.Commands.Incomestatement ,module Hledger.Cli.Commands.Incomestatement
,module Hledger.Cli.Commands.Notes
,module Hledger.Cli.Commands.Payees ,module Hledger.Cli.Commands.Payees
,module Hledger.Cli.Commands.Prices ,module Hledger.Cli.Commands.Prices
,module Hledger.Cli.Commands.Print ,module Hledger.Cli.Commands.Print
@ -71,11 +73,13 @@ 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.Commodities import Hledger.Cli.Commands.Commodities
import Hledger.Cli.Commands.Descriptions
import Hledger.Cli.Commands.Diff import Hledger.Cli.Commands.Diff
import Hledger.Cli.Commands.Files import Hledger.Cli.Commands.Files
import Hledger.Cli.Commands.Help import Hledger.Cli.Commands.Help
import Hledger.Cli.Commands.Import import Hledger.Cli.Commands.Import
import Hledger.Cli.Commands.Incomestatement import Hledger.Cli.Commands.Incomestatement
import Hledger.Cli.Commands.Notes
import Hledger.Cli.Commands.Payees import Hledger.Cli.Commands.Payees
import Hledger.Cli.Commands.Prices import Hledger.Cli.Commands.Prices
import Hledger.Cli.Commands.Print import Hledger.Cli.Commands.Print
@ -104,11 +108,13 @@ builtinCommands = [
,(checkdupesmode , checkdupes) ,(checkdupesmode , checkdupes)
,(closemode , close) ,(closemode , close)
,(commoditiesmode , commodities) ,(commoditiesmode , commodities)
,(descriptionsmode , descriptions)
,(helpmode , help') ,(helpmode , help')
,(importmode , importcmd) ,(importmode , importcmd)
,(filesmode , files) ,(filesmode , files)
,(diffmode , diff) ,(diffmode , diff)
,(incomestatementmode , incomestatement) ,(incomestatementmode , incomestatement)
,(notesmode , notes)
,(payeesmode , payees) ,(payeesmode , payees)
,(pricesmode , prices) ,(pricesmode , prices)
,(printmode , print') ,(printmode , print')
@ -175,8 +181,10 @@ commandsList = unlines [
," 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"
," commodities show commodity/currency symbols" ," commodities show commodity/currency symbols"
," descriptions show unique transaction descriptions"
," files show input file paths" ," files show input file paths"
," payees show payees" ," notes show unique note segments of transaction descriptions"
," payees show unique payee segments of transaction descriptions"
," prices show market price records" ," prices show market price records"
," print (p, txns) show transactions (journal entries)" ," print (p, txns) show transactions (journal entries)"
," print-unique show only transactions with unique descriptions" ," print-unique show only transactions with unique descriptions"

View File

@ -0,0 +1,44 @@
{-|
The @descriptions@ command lists allpayees seen in transactions.
-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE CPP #-}
module Hledger.Cli.Commands.Descriptions (
descriptionsmode
,descriptions
) where
#if !(MIN_VERSION_base(4,11,0))
import Data.Monoid
#endif
import Data.List
import qualified Data.Text.IO as T
import Hledger
import Hledger.Cli.CliOptions
-- | Command line options for this command.
descriptionsmode = hledgerCommandMode
$(embedFileRelative "Hledger/Cli/Commands/Descriptions.txt")
[]
[generalflagsgroup1]
hiddenflags
([], Just $ argsFlag "[QUERY]")
-- | The descriptions command.
descriptions :: CliOpts -> Journal -> IO ()
descriptions CliOpts{reportopts_=ropts} j = do
d <- getCurrentDay
let q = queryFromOpts d ropts
ts = entriesReport ropts q j
descriptions = nub $ sort $ map tdescription ts
mapM_ T.putStrLn descriptions

View File

@ -0,0 +1,15 @@
descriptions
Show descriptions.
_FLAGS_
This command lists all descriptions that appear in transactions.
Examples:
```shell
$ hledger descriptions
Store Name
Gas Station | Petrol
Person A
```

View File

@ -0,0 +1,13 @@
descriptions
Show descriptions.
_FLAGS_
This command lists all descriptions that appear in transactions.
Examples:
$ hledger descriptions
Store Name
Gas Station | Petrol
Person A

View File

@ -0,0 +1,44 @@
{-|
The @notes@ command lists allpayees seen in transactions.
-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE CPP #-}
module Hledger.Cli.Commands.Notes (
notesmode
,notes
) where
#if !(MIN_VERSION_base(4,11,0))
import Data.Monoid
#endif
import Data.List
import qualified Data.Text.IO as T
import Hledger
import Hledger.Cli.CliOptions
-- | Command line options for this command.
notesmode = hledgerCommandMode
$(embedFileRelative "Hledger/Cli/Commands/Notes.txt")
[]
[generalflagsgroup1]
hiddenflags
([], Just $ argsFlag "[QUERY]")
-- | The notes command.
notes :: CliOpts -> Journal -> IO ()
notes CliOpts{reportopts_=ropts} j = do
d <- getCurrentDay
let q = queryFromOpts d ropts
ts = entriesReport ropts q j
notes = nub $ sort $ map transactionNote ts
mapM_ T.putStrLn notes

View File

@ -0,0 +1,14 @@
notes
Show notes.
_FLAGS_
This command lists all notes that appear in transactions.
Examples:
```shell
$ hledger notes
Petrol
Snacks
```

View File

@ -0,0 +1,12 @@
notes
Show notes.
_FLAGS_
This command lists all notes that appear in transactions.
Examples:
$ hledger notes
Petrol
Snacks

View File

@ -1,8 +1,6 @@
{-| {-|
The @payees@ command lists payees: The @payees@ command lists allpayees seen in transactions.
- with the notes option the note field is included along with payees
-} -}
@ -20,10 +18,8 @@ module Hledger.Cli.Commands.Payees (
#if !(MIN_VERSION_base(4,11,0)) #if !(MIN_VERSION_base(4,11,0))
import Data.Monoid import Data.Monoid
#endif #endif
import Data.Function
import Data.List import Data.List
import qualified Data.Text.IO as T import qualified Data.Text.IO as T
import System.Console.CmdArgs.Explicit as C
import Hledger import Hledger
import Hledger.Cli.CliOptions import Hledger.Cli.CliOptions
@ -32,19 +28,17 @@ import Hledger.Cli.CliOptions
-- | Command line options for this command. -- | Command line options for this command.
payeesmode = hledgerCommandMode payeesmode = hledgerCommandMode
$(embedFileRelative "Hledger/Cli/Commands/Payees.txt") $(embedFileRelative "Hledger/Cli/Commands/Payees.txt")
[flagNone ["notes"] (setboolopt "notes") "include note field with payees" []
]
[generalflagsgroup1] [generalflagsgroup1]
hiddenflags hiddenflags
([], Just $ argsFlag "[QUERY]") ([], Just $ argsFlag "[QUERY]")
-- | The payees command. -- | The payees command.
payees :: CliOpts -> Journal -> IO () payees :: CliOpts -> Journal -> IO ()
payees CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do payees CliOpts{reportopts_=ropts} j = do
d <- getCurrentDay d <- getCurrentDay
let shownotes = boolopt "notes" rawopts let q = queryFromOpts d ropts
q = queryFromOpts d ropts
ts = entriesReport ropts q j ts = entriesReport ropts q j
payees = nub $ sort $ map (if shownotes then tdescription else transactionPayee) ts payees = nub $ sort $ map transactionPayee ts
mapM_ T.putStrLn payees mapM_ T.putStrLn payees

View File

@ -3,7 +3,7 @@ Show payee names.
_FLAGS_ _FLAGS_
This command lists all payee names that appear in transactions. With the optional notes directive (`--notes`) it will include the note field along with the base payee name. This command lists all payee names that appear in transactions.
Examples: Examples:

View File

@ -3,9 +3,7 @@ Show payee names.
_FLAGS_ _FLAGS_
This command lists all payee names that appear in transactions. With the This command lists all payee names that appear in transactions.
optional notes directive (--notes) it will include the note field along
with the base payee name.
Examples: Examples:

View File

@ -72,11 +72,13 @@ extra-source-files:
Hledger/Cli/Commands/Checkdupes.txt Hledger/Cli/Commands/Checkdupes.txt
Hledger/Cli/Commands/Close.txt Hledger/Cli/Commands/Close.txt
Hledger/Cli/Commands/Commodities.txt Hledger/Cli/Commands/Commodities.txt
Hledger/Cli/Commands/Descriptions.txt
Hledger/Cli/Commands/Diff.txt Hledger/Cli/Commands/Diff.txt
Hledger/Cli/Commands/Files.txt Hledger/Cli/Commands/Files.txt
Hledger/Cli/Commands/Help.txt Hledger/Cli/Commands/Help.txt
Hledger/Cli/Commands/Import.txt Hledger/Cli/Commands/Import.txt
Hledger/Cli/Commands/Incomestatement.txt Hledger/Cli/Commands/Incomestatement.txt
Hledger/Cli/Commands/Notes.txt
Hledger/Cli/Commands/Payees.txt Hledger/Cli/Commands/Payees.txt
Hledger/Cli/Commands/Prices.txt Hledger/Cli/Commands/Prices.txt
Hledger/Cli/Commands/Print.txt Hledger/Cli/Commands/Print.txt
@ -123,11 +125,13 @@ library
Hledger.Cli.Commands.Checkdupes Hledger.Cli.Commands.Checkdupes
Hledger.Cli.Commands.Close Hledger.Cli.Commands.Close
Hledger.Cli.Commands.Commodities Hledger.Cli.Commands.Commodities
Hledger.Cli.Commands.Descriptions
Hledger.Cli.Commands.Diff Hledger.Cli.Commands.Diff
Hledger.Cli.Commands.Help Hledger.Cli.Commands.Help
Hledger.Cli.Commands.Files Hledger.Cli.Commands.Files
Hledger.Cli.Commands.Import Hledger.Cli.Commands.Import
Hledger.Cli.Commands.Incomestatement Hledger.Cli.Commands.Incomestatement
Hledger.Cli.Commands.Notes
Hledger.Cli.Commands.Payees Hledger.Cli.Commands.Payees
Hledger.Cli.Commands.Prices Hledger.Cli.Commands.Prices
Hledger.Cli.Commands.Print Hledger.Cli.Commands.Print

View File

@ -65,11 +65,13 @@ extra-source-files:
- Hledger/Cli/Commands/Checkdupes.txt - Hledger/Cli/Commands/Checkdupes.txt
- Hledger/Cli/Commands/Close.txt - Hledger/Cli/Commands/Close.txt
- Hledger/Cli/Commands/Commodities.txt - Hledger/Cli/Commands/Commodities.txt
- Hledger/Cli/Commands/Descriptions.txt
- Hledger/Cli/Commands/Diff.txt - Hledger/Cli/Commands/Diff.txt
- Hledger/Cli/Commands/Files.txt - Hledger/Cli/Commands/Files.txt
- Hledger/Cli/Commands/Help.txt - Hledger/Cli/Commands/Help.txt
- Hledger/Cli/Commands/Import.txt - Hledger/Cli/Commands/Import.txt
- Hledger/Cli/Commands/Incomestatement.txt - Hledger/Cli/Commands/Incomestatement.txt
- Hledger/Cli/Commands/Notes.txt
- Hledger/Cli/Commands/Payees.txt - Hledger/Cli/Commands/Payees.txt
- Hledger/Cli/Commands/Prices.txt - Hledger/Cli/Commands/Prices.txt
- Hledger/Cli/Commands/Print.txt - Hledger/Cli/Commands/Print.txt
@ -168,11 +170,13 @@ library:
- Hledger.Cli.Commands.Checkdupes - Hledger.Cli.Commands.Checkdupes
- Hledger.Cli.Commands.Close - Hledger.Cli.Commands.Close
- Hledger.Cli.Commands.Commodities - Hledger.Cli.Commands.Commodities
- Hledger.Cli.Commands.Descriptions
- Hledger.Cli.Commands.Diff - Hledger.Cli.Commands.Diff
- Hledger.Cli.Commands.Help - Hledger.Cli.Commands.Help
- Hledger.Cli.Commands.Files - Hledger.Cli.Commands.Files
- Hledger.Cli.Commands.Import - Hledger.Cli.Commands.Import
- Hledger.Cli.Commands.Incomestatement - Hledger.Cli.Commands.Incomestatement
- Hledger.Cli.Commands.Notes
- Hledger.Cli.Commands.Payees - Hledger.Cli.Commands.Payees
- Hledger.Cli.Commands.Prices - Hledger.Cli.Commands.Prices
- Hledger.Cli.Commands.Print - Hledger.Cli.Commands.Print

19
tests/descriptions.test Normal file
View File

@ -0,0 +1,19 @@
# descriptions command
# basic descriptions report
<
2018/1/1 foo ; foo:
a
2018/1/1 bar | baz
a
$ hledger -f - descriptions
bar | baz
foo
>=
# filtering transactions by tag
$ hledger -f - descriptions tag:foo
foo
>=

19
tests/notes.test Normal file
View File

@ -0,0 +1,19 @@
# notes command
# basic notes report
<
2018/1/1 foo ; foo:
a
2018/1/1 bar | baz
a
$ hledger -f - notes
baz
foo
>=
# filtering transactions by tag
$ hledger -f - notes tag:foo
foo
>=

View File

@ -13,12 +13,6 @@ bar
foo foo
>= >=
# with payee and note fields togother
$ hledger -f - payees --notes
bar | baz
foo
>=
# filtering transactions by tag # filtering transactions by tag
$ hledger -f - payees tag:foo $ hledger -f - payees tag:foo
foo foo