diff --git a/hledger/Hledger/Cli/Commands.hs b/hledger/Hledger/Cli/Commands.hs index 851067267..cdf3f8513 100644 --- a/hledger/Hledger/Cli/Commands.hs +++ b/hledger/Hledger/Cli/Commands.hs @@ -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" diff --git a/hledger/Hledger/Cli/Commands/Descriptions.hs b/hledger/Hledger/Cli/Commands/Descriptions.hs new file mode 100644 index 000000000..e13d373ca --- /dev/null +++ b/hledger/Hledger/Cli/Commands/Descriptions.hs @@ -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 diff --git a/hledger/Hledger/Cli/Commands/Descriptions.md b/hledger/Hledger/Cli/Commands/Descriptions.md new file mode 100644 index 000000000..f6fb01dbb --- /dev/null +++ b/hledger/Hledger/Cli/Commands/Descriptions.md @@ -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 +``` diff --git a/hledger/Hledger/Cli/Commands/Descriptions.txt b/hledger/Hledger/Cli/Commands/Descriptions.txt new file mode 100644 index 000000000..6654538a8 --- /dev/null +++ b/hledger/Hledger/Cli/Commands/Descriptions.txt @@ -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 diff --git a/hledger/Hledger/Cli/Commands/Notes.hs b/hledger/Hledger/Cli/Commands/Notes.hs new file mode 100644 index 000000000..ae9423815 --- /dev/null +++ b/hledger/Hledger/Cli/Commands/Notes.hs @@ -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 diff --git a/hledger/Hledger/Cli/Commands/Notes.md b/hledger/Hledger/Cli/Commands/Notes.md new file mode 100644 index 000000000..7ea63d421 --- /dev/null +++ b/hledger/Hledger/Cli/Commands/Notes.md @@ -0,0 +1,14 @@ +notes +Show notes. + +_FLAGS_ + +This command lists all notes that appear in transactions. + +Examples: + +```shell +$ hledger notes +Petrol +Snacks +``` diff --git a/hledger/Hledger/Cli/Commands/Notes.txt b/hledger/Hledger/Cli/Commands/Notes.txt new file mode 100644 index 000000000..44fa12f8e --- /dev/null +++ b/hledger/Hledger/Cli/Commands/Notes.txt @@ -0,0 +1,12 @@ +notes +Show notes. + +_FLAGS_ + +This command lists all notes that appear in transactions. + +Examples: + +$ hledger notes +Petrol +Snacks diff --git a/hledger/Hledger/Cli/Commands/Payees.hs b/hledger/Hledger/Cli/Commands/Payees.hs index 55efb8dc0..f958a8e4b 100644 --- a/hledger/Hledger/Cli/Commands/Payees.hs +++ b/hledger/Hledger/Cli/Commands/Payees.hs @@ -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 diff --git a/hledger/Hledger/Cli/Commands/Payees.md b/hledger/Hledger/Cli/Commands/Payees.md index 275e6c0a8..798d0ac5c 100644 --- a/hledger/Hledger/Cli/Commands/Payees.md +++ b/hledger/Hledger/Cli/Commands/Payees.md @@ -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: diff --git a/hledger/Hledger/Cli/Commands/Payees.txt b/hledger/Hledger/Cli/Commands/Payees.txt index e22b818b3..59ddeb1f5 100644 --- a/hledger/Hledger/Cli/Commands/Payees.txt +++ b/hledger/Hledger/Cli/Commands/Payees.txt @@ -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: diff --git a/hledger/hledger.cabal b/hledger/hledger.cabal index 125761883..af6a202de 100644 --- a/hledger/hledger.cabal +++ b/hledger/hledger.cabal @@ -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 diff --git a/hledger/package.yaml b/hledger/package.yaml index c96bc120a..b341efb5e 100644 --- a/hledger/package.yaml +++ b/hledger/package.yaml @@ -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 diff --git a/tests/descriptions.test b/tests/descriptions.test new file mode 100644 index 000000000..23ec1f4ce --- /dev/null +++ b/tests/descriptions.test @@ -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 +>= diff --git a/tests/notes.test b/tests/notes.test new file mode 100644 index 000000000..a15272202 --- /dev/null +++ b/tests/notes.test @@ -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 +>= diff --git a/tests/payees.test b/tests/payees.test index 29974a5db..e5d510144 100644 --- a/tests/payees.test +++ b/tests/payees.test @@ -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