diff --git a/bin/hledger-print-unique.hs b/bin/hledger-print-unique.hs deleted file mode 100755 index 26c9631d4..000000000 --- a/bin/hledger-print-unique.hs +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env stack -{- stack runghc --verbosity info - --package hledger-lib - --package hledger - --package here --} - - {-# OPTIONS_GHC -Wno-missing-signatures -Wno-name-shadowing #-} - {-# LANGUAGE QuasiQuotes #-} - -import Data.List -import Data.Ord -import Data.String.Here -import Hledger.Cli - ------------------------------------------------------------------------------- -cmdmode = hledgerCommandMode - [here| print-unique -Remove transactions which reuse an already-seen description. - -FLAGS - -Example: -```shell -$ cat unique.journal -1/1 test - (acct:one) 1 -2/2 test - (acct:two) 2 -$ LEDGER_FILE=unique.journal hledger print-unique -(-f option not supported) -2015/01/01 test - (acct:one) 1 -``` - |] - [] - [generalflagsgroup1] - [] - ([], Nothing) ------------------------------------------------------------------------------- - -main = do - opts <- getHledgerCliOpts cmdmode - withJournalDo opts $ - \opts j@Journal{jtxns=ts} -> print' opts j{jtxns=uniquify ts} - where - uniquify = nubBy (\t1 t2 -> thingToCompare t1 == thingToCompare t2) . sortBy (comparing thingToCompare) - thingToCompare = tdescription - -- thingToCompare = tdate diff --git a/hledger/Hledger/Cli/Commands.hs b/hledger/Hledger/Cli/Commands.hs index 8eabab1eb..07d58972e 100644 --- a/hledger/Hledger/Cli/Commands.hs +++ b/hledger/Hledger/Cli/Commands.hs @@ -25,6 +25,7 @@ module Hledger.Cli.Commands ( ,module Hledger.Cli.Commands.Incomestatement ,module Hledger.Cli.Commands.Prices ,module Hledger.Cli.Commands.Print + ,module Hledger.Cli.Commands.Printunique ,module Hledger.Cli.Commands.Register ,module Hledger.Cli.Commands.Stats ) @@ -58,6 +59,7 @@ import Hledger.Cli.Commands.Help import Hledger.Cli.Commands.Incomestatement import Hledger.Cli.Commands.Prices import Hledger.Cli.Commands.Print +import Hledger.Cli.Commands.Printunique import Hledger.Cli.Commands.Register import Hledger.Cli.Commands.Stats diff --git a/hledger/Hledger/Cli/Commands/Printunique.hs b/hledger/Hledger/Cli/Commands/Printunique.hs new file mode 100755 index 000000000..ec7bc71b1 --- /dev/null +++ b/hledger/Hledger/Cli/Commands/Printunique.hs @@ -0,0 +1,47 @@ +{-# LANGUAGE QuasiQuotes #-} + +{-# LANGUAGE QuasiQuotes #-} + +module Hledger.Cli.Commands.Printunique ( + printuniquemode + ,printunique +) +where + +import Data.List +import Data.Ord +import Data.String.Here +import Hledger +import Hledger.Cli.CliOptions +import Hledger.Cli.Commands.Print + +printuniquemode = hledgerCommandMode + [here| print-unique +Print transactions which do not reuse an already-seen description. + +FLAGS + +Example: +```shell +$ cat unique.journal +1/1 test + (acct:one) 1 +2/2 test + (acct:two) 2 +$ LEDGER_FILE=unique.journal hledger print-unique +(-f option not supported) +2015/01/01 test + (acct:one) 1 +``` + |] + [] + [generalflagsgroup1] + [] + ([], Nothing) + +printunique opts j@Journal{jtxns=ts} = do + print' opts j{jtxns=uniquify ts} + where + uniquify = nubBy (\t1 t2 -> thingToCompare t1 == thingToCompare t2) . sortBy (comparing thingToCompare) + thingToCompare = tdescription + -- thingToCompare = tdate diff --git a/hledger/doc/addons.m4.md b/hledger/doc/addons.m4.md index e166ebe8d..c4cada1c3 100644 --- a/hledger/doc/addons.m4.md +++ b/hledger/doc/addons.m4.md @@ -89,11 +89,6 @@ is an old pie chart generator, in need of some love. [hledger-check.hs](https://github.com/simonmichael/hledger/blob/master/bin/hledger-check.hs) checks more powerful account balance assertions. -### print-unique - -[hledger-print-unique.hs](https://github.com/simonmichael/hledger/blob/master/bin/hledger-print-unique.hs#L15) -prints transactions which do not reuse an already-seen description. - ### register-match [hledger-register-match.hs](https://github.com/simonmichael/hledger/blob/master/bin/hledger-register-match.hs#L23) diff --git a/hledger/doc/commands.m4.md b/hledger/doc/commands.m4.md index a0028460a..677974c02 100644 --- a/hledger/doc/commands.m4.md +++ b/hledger/doc/commands.m4.md @@ -547,6 +547,8 @@ $ hledger print -Ocsv (Those names are not accurate in the accounting sense; it just puts negative amounts under credit and zero or greater amounts under debit.) +## print-unique +Print transactions which do not reuse an already-seen description. ## register Show postings and their running total. Alias: reg. diff --git a/hledger/package.yaml b/hledger/package.yaml index 9a172dc13..9feea0c16 100644 --- a/hledger/package.yaml +++ b/hledger/package.yaml @@ -117,6 +117,7 @@ library: - Hledger.Cli.Commands.Incomestatement - Hledger.Cli.Commands.Prices - Hledger.Cli.Commands.Print + - Hledger.Cli.Commands.Printunique - Hledger.Cli.Commands.Register - Hledger.Cli.Commands.Stats - Hledger.Cli.CompoundBalanceCommand