cli: make register-match a builtin command

This commit is contained in:
Simon Michael 2017-09-12 19:43:41 -07:00
parent bf99c74198
commit 89f694707b
6 changed files with 23 additions and 29 deletions

View File

@ -27,6 +27,7 @@ module Hledger.Cli.Commands (
,module Hledger.Cli.Commands.Print
,module Hledger.Cli.Commands.Printunique
,module Hledger.Cli.Commands.Register
,module Hledger.Cli.Commands.Registermatch
,module Hledger.Cli.Commands.Stats
)
where
@ -61,6 +62,7 @@ import Hledger.Cli.Commands.Prices
import Hledger.Cli.Commands.Print
import Hledger.Cli.Commands.Printunique
import Hledger.Cli.Commands.Register
import Hledger.Cli.Commands.Registermatch
import Hledger.Cli.Commands.Stats

View File

@ -1,46 +1,35 @@
#!/usr/bin/env stack
{- stack runghc --verbosity info
--package hledger-lib
--package hledger
--package here
--package text
-}
{-# OPTIONS_GHC -Wno-missing-signatures -Wno-name-shadowing #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
module Hledger.Cli.Commands.Registermatch (
registermatchmode
,registermatch
)
where
import Data.Char (toUpper)
import Data.List
import Data.String.Here
import qualified Data.Text as T
-- import System.Console.CmdArgs
-- import System.Console.CmdArgs.Explicit
import Hledger
import Hledger.Cli.CliOptions
import Hledger.Cli ( withJournalDo, postingsReportAsText )
import Hledger.Cli.Commands.Register
------------------------------------------------------------------------------
cmdmode = hledgerCommandMode
registermatchmode = hledgerCommandMode
[here| register-match
A helper for ledger-autosync. This prints the one posting whose transaction
description is closest to DESC, in the style of the register command.
Print the one posting whose transaction description is closest to DESC,
in the style of the register command.
If there are multiple equally good matches, it shows the most recent.
Query options (options, not arguments) can be used to restrict the search space.
Helps ledger-autosync detect already-seen transactions when importing.
|]
[]
[generalflagsgroup1]
[]
([], Nothing)
------------------------------------------------------------------------------
main = do
opts <- getHledgerCliOpts cmdmode
withJournalDo opts match
match :: CliOpts -> Journal -> IO ()
match opts@CliOpts{rawopts_=rawopts,reportopts_=ropts} j = do
registermatch :: CliOpts -> Journal -> IO ()
registermatch opts@CliOpts{rawopts_=rawopts,reportopts_=ropts} j = do
let args' = listofstringopt "args" rawopts
case args' of
[desc] -> do

View File

@ -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.
### register-match
[hledger-register-match.hs](https://github.com/simonmichael/hledger/blob/master/bin/hledger-register-match.hs#L23)
helps ledger-autosync detect already-seen transactions when importing.
### rewrite
[hledger-rewrite.hs](https://github.com/simonmichael/hledger/blob/master/bin/hledger-rewrite.hs#L28)

View File

@ -680,6 +680,11 @@ The register command also supports the
`-o/--output-file` and `-O/--output-format` options for controlling
[output destination](#output-destination) and [CSV output](#csv-output).
## register-match
Print the one posting whose transaction description is closest to DESC,
in the style of the register command.
Helps ledger-autosync detect already-seen transactions when importing.
## stats
Show some journal statistics.

View File

@ -136,7 +136,9 @@ library
Hledger.Cli.Commands.Incomestatement
Hledger.Cli.Commands.Prices
Hledger.Cli.Commands.Print
Hledger.Cli.Commands.Printunique
Hledger.Cli.Commands.Register
Hledger.Cli.Commands.Registermatch
Hledger.Cli.Commands.Stats
Hledger.Cli.CompoundBalanceCommand
Text.Tabular.AsciiWide

View File

@ -119,6 +119,7 @@ library:
- Hledger.Cli.Commands.Print
- Hledger.Cli.Commands.Printunique
- Hledger.Cli.Commands.Register
- Hledger.Cli.Commands.Registermatch
- Hledger.Cli.Commands.Stats
- Hledger.Cli.CompoundBalanceCommand
- Text.Tabular.AsciiWide