diff --git a/hledger/Hledger/Cli/Commands.hs b/hledger/Hledger/Cli/Commands.hs index 07d58972e..88e5fb00d 100644 --- a/hledger/Hledger/Cli/Commands.hs +++ b/hledger/Hledger/Cli/Commands.hs @@ -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 diff --git a/bin/hledger-register-match.hs b/hledger/Hledger/Cli/Commands/Registermatch.hs similarity index 78% rename from bin/hledger-register-match.hs rename to hledger/Hledger/Cli/Commands/Registermatch.hs index e9a585593..1e8e4d515 100755 --- a/bin/hledger-register-match.hs +++ b/hledger/Hledger/Cli/Commands/Registermatch.hs @@ -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 diff --git a/hledger/doc/addons.m4.md b/hledger/doc/addons.m4.md index c4cada1c3..23eca7448 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. -### 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) diff --git a/hledger/doc/commands.m4.md b/hledger/doc/commands.m4.md index 677974c02..be8eb2543 100644 --- a/hledger/doc/commands.m4.md +++ b/hledger/doc/commands.m4.md @@ -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. diff --git a/hledger/hledger.cabal b/hledger/hledger.cabal index 0eef43b89..8d29abc5b 100644 --- a/hledger/hledger.cabal +++ b/hledger/hledger.cabal @@ -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 diff --git a/hledger/package.yaml b/hledger/package.yaml index 9feea0c16..5101701b0 100644 --- a/hledger/package.yaml +++ b/hledger/package.yaml @@ -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