From 807273d9deed118f34164a1d3153490ef9ce98f8 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 13 Sep 2019 08:15:03 -0700 Subject: [PATCH] import: --catchup marks all transactions imported, without importing --- hledger/Hledger/Cli/Commands/Import.hs | 8 +++++++- hledger/Hledger/Cli/Commands/Import.md | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/hledger/Hledger/Cli/Commands/Import.hs b/hledger/Hledger/Cli/Commands/Import.hs index 6543d3e2e..b1a6385e1 100755 --- a/hledger/Hledger/Cli/Commands/Import.hs +++ b/hledger/Hledger/Cli/Commands/Import.hs @@ -18,7 +18,9 @@ import Text.Printf importmode = hledgerCommandMode $(embedFileRelative "Hledger/Cli/Commands/Import.txt") - [flagNone ["dry-run"] (setboolopt "dry-run") "just show the transactions to be imported"] + [flagNone ["catchup"] (setboolopt "catchup") "just mark all transactions as already imported" + ,flagNone ["dry-run"] (setboolopt "dry-run") "just show the transactions to be imported" + ] [generalflagsgroup1] hiddenflags ([], Just $ argsFlag "FILE [...]") @@ -26,6 +28,8 @@ importmode = hledgerCommandMode importcmd opts@CliOpts{rawopts_=rawopts,inputopts_=iopts} j = do let inputfiles = listofstringopt "args" rawopts + inputstr = intercalate ", " inputfiles + catchup = boolopt "catchup" rawopts dryrun = boolopt "dry-run" rawopts iopts' = iopts{new_=True, new_save_=not dryrun} case inputfiles of @@ -43,6 +47,8 @@ importcmd opts@CliOpts{rawopts_=rawopts,inputopts_=iopts} j = do -- TODO how to force output here ? -- length (jtxns newj) `seq` print' opts{rawopts_=("explicit",""):rawopts} newj mapM_ (putStr . showTransactionUnelided) newts + newts | catchup -> do + printf "marked %s as caught up, skipping %d unimported transactions\n\n" inputstr (length newts) newts -> do foldM_ (`journalAddTransaction` opts) j newts -- gets forced somehow.. (how ?) printf "imported %d new transactions\n" (length newts) diff --git a/hledger/Hledger/Cli/Commands/Import.md b/hledger/Hledger/Cli/Commands/Import.md index 90ec39004..f4a8c0ed8 100644 --- a/hledger/Hledger/Cli/Commands/Import.md +++ b/hledger/Hledger/Cli/Commands/Import.md @@ -1,7 +1,8 @@ import\ Read new transactions added to each FILE since last run, and add them to the main journal file. Or with --dry-run, just print the transactions -that would be added. +that would be added. Or with --catchup, just mark all of the FILEs' +transactions as imported, without actually importing any. _FLAGS_