mirror of
https://github.com/simonmichael/hledger.git
synced 2024-09-19 18:29:36 +03:00
cli: make print-unique a builtin command
This commit is contained in:
parent
258efdf83c
commit
bf99c74198
@ -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
|
@ -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
|
||||
|
||||
|
47
hledger/Hledger/Cli/Commands/Printunique.hs
Executable file
47
hledger/Hledger/Cli/Commands/Printunique.hs
Executable file
@ -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
|
@ -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)
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user