mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-25 19:31:44 +03:00
payees: Split command into descriptions, payees, and notes
This commit is contained in:
parent
5d42578137
commit
e68e558761
@ -28,10 +28,12 @@ module Hledger.Cli.Commands (
|
||||
,module Hledger.Cli.Commands.Checkdupes
|
||||
,module Hledger.Cli.Commands.Close
|
||||
,module Hledger.Cli.Commands.Commodities
|
||||
,module Hledger.Cli.Commands.Descriptions
|
||||
,module Hledger.Cli.Commands.Diff
|
||||
,module Hledger.Cli.Commands.Help
|
||||
,module Hledger.Cli.Commands.Import
|
||||
,module Hledger.Cli.Commands.Incomestatement
|
||||
,module Hledger.Cli.Commands.Notes
|
||||
,module Hledger.Cli.Commands.Payees
|
||||
,module Hledger.Cli.Commands.Prices
|
||||
,module Hledger.Cli.Commands.Print
|
||||
@ -71,11 +73,13 @@ import Hledger.Cli.Commands.Checkdates
|
||||
import Hledger.Cli.Commands.Checkdupes
|
||||
import Hledger.Cli.Commands.Close
|
||||
import Hledger.Cli.Commands.Commodities
|
||||
import Hledger.Cli.Commands.Descriptions
|
||||
import Hledger.Cli.Commands.Diff
|
||||
import Hledger.Cli.Commands.Files
|
||||
import Hledger.Cli.Commands.Help
|
||||
import Hledger.Cli.Commands.Import
|
||||
import Hledger.Cli.Commands.Incomestatement
|
||||
import Hledger.Cli.Commands.Notes
|
||||
import Hledger.Cli.Commands.Payees
|
||||
import Hledger.Cli.Commands.Prices
|
||||
import Hledger.Cli.Commands.Print
|
||||
@ -104,11 +108,13 @@ builtinCommands = [
|
||||
,(checkdupesmode , checkdupes)
|
||||
,(closemode , close)
|
||||
,(commoditiesmode , commodities)
|
||||
,(descriptionsmode , descriptions)
|
||||
,(helpmode , help')
|
||||
,(importmode , importcmd)
|
||||
,(filesmode , files)
|
||||
,(diffmode , diff)
|
||||
,(incomestatementmode , incomestatement)
|
||||
,(notesmode , notes)
|
||||
,(payeesmode , payees)
|
||||
,(pricesmode , prices)
|
||||
,(printmode , print')
|
||||
@ -175,8 +181,10 @@ commandsList = unlines [
|
||||
," activity show postings-per-interval bar charts"
|
||||
," balance (b, bal) show balance changes/end balances/budgets in accounts"
|
||||
," commodities show commodity/currency symbols"
|
||||
," descriptions show unique transaction descriptions"
|
||||
," 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"
|
||||
," print (p, txns) show transactions (journal entries)"
|
||||
," print-unique show only transactions with unique descriptions"
|
||||
|
44
hledger/Hledger/Cli/Commands/Descriptions.hs
Normal file
44
hledger/Hledger/Cli/Commands/Descriptions.hs
Normal 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
|
15
hledger/Hledger/Cli/Commands/Descriptions.md
Normal file
15
hledger/Hledger/Cli/Commands/Descriptions.md
Normal 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
|
||||
```
|
13
hledger/Hledger/Cli/Commands/Descriptions.txt
Normal file
13
hledger/Hledger/Cli/Commands/Descriptions.txt
Normal 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
|
44
hledger/Hledger/Cli/Commands/Notes.hs
Normal file
44
hledger/Hledger/Cli/Commands/Notes.hs
Normal 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
|
14
hledger/Hledger/Cli/Commands/Notes.md
Normal file
14
hledger/Hledger/Cli/Commands/Notes.md
Normal file
@ -0,0 +1,14 @@
|
||||
notes
|
||||
Show notes.
|
||||
|
||||
_FLAGS_
|
||||
|
||||
This command lists all notes that appear in transactions.
|
||||
|
||||
Examples:
|
||||
|
||||
```shell
|
||||
$ hledger notes
|
||||
Petrol
|
||||
Snacks
|
||||
```
|
12
hledger/Hledger/Cli/Commands/Notes.txt
Normal file
12
hledger/Hledger/Cli/Commands/Notes.txt
Normal file
@ -0,0 +1,12 @@
|
||||
notes
|
||||
Show notes.
|
||||
|
||||
_FLAGS_
|
||||
|
||||
This command lists all notes that appear in transactions.
|
||||
|
||||
Examples:
|
||||
|
||||
$ hledger notes
|
||||
Petrol
|
||||
Snacks
|
@ -1,8 +1,6 @@
|
||||
{-|
|
||||
|
||||
The @payees@ command lists payees:
|
||||
|
||||
- with the notes option the note field is included along with payees
|
||||
The @payees@ command lists allpayees seen in transactions.
|
||||
|
||||
-}
|
||||
|
||||
@ -20,10 +18,8 @@ module Hledger.Cli.Commands.Payees (
|
||||
#if !(MIN_VERSION_base(4,11,0))
|
||||
import Data.Monoid
|
||||
#endif
|
||||
import Data.Function
|
||||
import Data.List
|
||||
import qualified Data.Text.IO as T
|
||||
import System.Console.CmdArgs.Explicit as C
|
||||
|
||||
import Hledger
|
||||
import Hledger.Cli.CliOptions
|
||||
@ -32,19 +28,17 @@ import Hledger.Cli.CliOptions
|
||||
-- | Command line options for this command.
|
||||
payeesmode = hledgerCommandMode
|
||||
$(embedFileRelative "Hledger/Cli/Commands/Payees.txt")
|
||||
[flagNone ["notes"] (setboolopt "notes") "include note field with payees"
|
||||
]
|
||||
[]
|
||||
[generalflagsgroup1]
|
||||
hiddenflags
|
||||
([], Just $ argsFlag "[QUERY]")
|
||||
|
||||
-- | The payees command.
|
||||
payees :: CliOpts -> Journal -> IO ()
|
||||
payees CliOpts{rawopts_=rawopts, reportopts_=ropts} j = do
|
||||
payees CliOpts{reportopts_=ropts} j = do
|
||||
d <- getCurrentDay
|
||||
let shownotes = boolopt "notes" rawopts
|
||||
q = queryFromOpts d ropts
|
||||
let q = queryFromOpts d ropts
|
||||
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
|
||||
|
@ -3,7 +3,7 @@ Show payee names.
|
||||
|
||||
_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:
|
||||
|
||||
|
@ -3,9 +3,7 @@ Show payee names.
|
||||
|
||||
_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:
|
||||
|
||||
|
@ -72,11 +72,13 @@ extra-source-files:
|
||||
Hledger/Cli/Commands/Checkdupes.txt
|
||||
Hledger/Cli/Commands/Close.txt
|
||||
Hledger/Cli/Commands/Commodities.txt
|
||||
Hledger/Cli/Commands/Descriptions.txt
|
||||
Hledger/Cli/Commands/Diff.txt
|
||||
Hledger/Cli/Commands/Files.txt
|
||||
Hledger/Cli/Commands/Help.txt
|
||||
Hledger/Cli/Commands/Import.txt
|
||||
Hledger/Cli/Commands/Incomestatement.txt
|
||||
Hledger/Cli/Commands/Notes.txt
|
||||
Hledger/Cli/Commands/Payees.txt
|
||||
Hledger/Cli/Commands/Prices.txt
|
||||
Hledger/Cli/Commands/Print.txt
|
||||
@ -123,11 +125,13 @@ library
|
||||
Hledger.Cli.Commands.Checkdupes
|
||||
Hledger.Cli.Commands.Close
|
||||
Hledger.Cli.Commands.Commodities
|
||||
Hledger.Cli.Commands.Descriptions
|
||||
Hledger.Cli.Commands.Diff
|
||||
Hledger.Cli.Commands.Help
|
||||
Hledger.Cli.Commands.Files
|
||||
Hledger.Cli.Commands.Import
|
||||
Hledger.Cli.Commands.Incomestatement
|
||||
Hledger.Cli.Commands.Notes
|
||||
Hledger.Cli.Commands.Payees
|
||||
Hledger.Cli.Commands.Prices
|
||||
Hledger.Cli.Commands.Print
|
||||
|
@ -65,11 +65,13 @@ extra-source-files:
|
||||
- Hledger/Cli/Commands/Checkdupes.txt
|
||||
- Hledger/Cli/Commands/Close.txt
|
||||
- Hledger/Cli/Commands/Commodities.txt
|
||||
- Hledger/Cli/Commands/Descriptions.txt
|
||||
- Hledger/Cli/Commands/Diff.txt
|
||||
- Hledger/Cli/Commands/Files.txt
|
||||
- Hledger/Cli/Commands/Help.txt
|
||||
- Hledger/Cli/Commands/Import.txt
|
||||
- Hledger/Cli/Commands/Incomestatement.txt
|
||||
- Hledger/Cli/Commands/Notes.txt
|
||||
- Hledger/Cli/Commands/Payees.txt
|
||||
- Hledger/Cli/Commands/Prices.txt
|
||||
- Hledger/Cli/Commands/Print.txt
|
||||
@ -168,11 +170,13 @@ library:
|
||||
- Hledger.Cli.Commands.Checkdupes
|
||||
- Hledger.Cli.Commands.Close
|
||||
- Hledger.Cli.Commands.Commodities
|
||||
- Hledger.Cli.Commands.Descriptions
|
||||
- Hledger.Cli.Commands.Diff
|
||||
- Hledger.Cli.Commands.Help
|
||||
- Hledger.Cli.Commands.Files
|
||||
- Hledger.Cli.Commands.Import
|
||||
- Hledger.Cli.Commands.Incomestatement
|
||||
- Hledger.Cli.Commands.Notes
|
||||
- Hledger.Cli.Commands.Payees
|
||||
- Hledger.Cli.Commands.Prices
|
||||
- Hledger.Cli.Commands.Print
|
||||
|
19
tests/descriptions.test
Normal file
19
tests/descriptions.test
Normal 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
19
tests/notes.test
Normal 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
|
||||
>=
|
@ -13,12 +13,6 @@ bar
|
||||
foo
|
||||
>=
|
||||
|
||||
# with payee and note fields togother
|
||||
$ hledger -f - payees --notes
|
||||
bar | baz
|
||||
foo
|
||||
>=
|
||||
|
||||
# filtering transactions by tag
|
||||
$ hledger -f - payees tag:foo
|
||||
foo
|
||||
|
Loading…
Reference in New Issue
Block a user