import: --catchup marks all transactions imported, without importing

This commit is contained in:
Simon Michael 2019-09-13 08:15:03 -07:00
parent 35a90004ca
commit 807273d9de
2 changed files with 9 additions and 2 deletions

View File

@ -18,7 +18,9 @@ import Text.Printf
importmode = hledgerCommandMode importmode = hledgerCommandMode
$(embedFileRelative "Hledger/Cli/Commands/Import.txt") $(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] [generalflagsgroup1]
hiddenflags hiddenflags
([], Just $ argsFlag "FILE [...]") ([], Just $ argsFlag "FILE [...]")
@ -26,6 +28,8 @@ importmode = hledgerCommandMode
importcmd opts@CliOpts{rawopts_=rawopts,inputopts_=iopts} j = do importcmd opts@CliOpts{rawopts_=rawopts,inputopts_=iopts} j = do
let let
inputfiles = listofstringopt "args" rawopts inputfiles = listofstringopt "args" rawopts
inputstr = intercalate ", " inputfiles
catchup = boolopt "catchup" rawopts
dryrun = boolopt "dry-run" rawopts dryrun = boolopt "dry-run" rawopts
iopts' = iopts{new_=True, new_save_=not dryrun} iopts' = iopts{new_=True, new_save_=not dryrun}
case inputfiles of case inputfiles of
@ -43,6 +47,8 @@ importcmd opts@CliOpts{rawopts_=rawopts,inputopts_=iopts} j = do
-- TODO how to force output here ? -- TODO how to force output here ?
-- length (jtxns newj) `seq` print' opts{rawopts_=("explicit",""):rawopts} newj -- length (jtxns newj) `seq` print' opts{rawopts_=("explicit",""):rawopts} newj
mapM_ (putStr . showTransactionUnelided) newts mapM_ (putStr . showTransactionUnelided) newts
newts | catchup -> do
printf "marked %s as caught up, skipping %d unimported transactions\n\n" inputstr (length newts)
newts -> do newts -> do
foldM_ (`journalAddTransaction` opts) j newts -- gets forced somehow.. (how ?) foldM_ (`journalAddTransaction` opts) j newts -- gets forced somehow.. (how ?)
printf "imported %d new transactions\n" (length newts) printf "imported %d new transactions\n" (length newts)

View File

@ -1,7 +1,8 @@
import\ import\
Read new transactions added to each FILE since last run, and add them to 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 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_ _FLAGS_