diff --git a/hledger/Hledger/Cli/Commands/Import.hs b/hledger/Hledger/Cli/Commands/Import.hs index c754085f5..536901af8 100644 --- a/hledger/Hledger/Cli/Commands/Import.hs +++ b/hledger/Hledger/Cli/Commands/Import.hs @@ -18,6 +18,7 @@ import Text.Printf import Hledger import Hledger.Cli.CliOptions import Hledger.Cli.Commands.Add (journalAddTransaction) +import System.IO (stderr) importmode = hledgerCommandMode $(embedFileRelative "Hledger/Cli/Commands/Import.txt") @@ -63,20 +64,20 @@ importcmd opts@CliOpts{rawopts_=rawopts,inputopts_=iopts} j = do [] -> do -- in this case, we vary the output depending on --dry-run, which is a bit awkward let semicolon = if dryrun then "; " else "" :: String - printf "%sno new transactions found in %s\n\n" semicolon inputstr + hPrintf stderr "%sno new transactions found in %s\n\n" semicolon inputstr newts | catchup -> if dryrun - then printf "--catchup would skip %d transactions (dry run)\n\n" (length newts) + then hPrintf stderr "would skip %d new transactions (dry run)\n\n" (length newts) else do - printf "marked %s as caught up, skipping %d transactions\n\n" inputstr (length newts) + hPrintf stderr "marked %s as caught up, skipping %d transactions\n\n" inputstr (length newts) saveLatestDatesForFiles latestdatesforfiles newts -> do if dryrun then do -- show txns to be imported - printf "; would import %d new transactions from %s:\n\n" (length newts) inputstr + hPrintf stderr "would import %d new transactions from %s:\n\n" (length newts) inputstr mapM_ (T.putStr . showTransaction) newts -- then check the whole journal with them added, if in strict mode @@ -92,7 +93,7 @@ importcmd opts@CliOpts{rawopts_=rawopts,inputopts_=iopts} j = do -- mixed line endings in the file. See also writeFileWithBackupIfChanged. foldM_ (`journalAddTransaction` opts) j newts -- gets forced somehow.. (how ?) - printf "imported %d new transactions from %s to %s\n" (length newts) inputstr (journalFilePath j) + hPrintf stderr "imported %d new transactions from %s to %s\n" (length newts) inputstr (journalFilePath j) -- and if we got this far, update each file's .latest file saveLatestDatesForFiles latestdatesforfiles diff --git a/hledger/test/import/import.test b/hledger/test/import/import.test index ee4e68d43..fb5e6ce4e 100644 --- a/hledger/test/import/import.test +++ b/hledger/test/import/import.test @@ -1,9 +1,10 @@ # import applies the receiving journal's commodity styles to imported amounts $ hledger -f a.j import --dry-run a.csv -; would import 1 new transactions from a.csv: - 2020-01-01 expenses:unknown 1.000.000,00 income:unknown -1.000.000,00 +>2 +would import 1 new transactions from a.csv: + >= diff --git a/hledger/test/import/match.test b/hledger/test/import/match.test index 5be198609..3f13ed094 100644 --- a/hledger/test/import/match.test +++ b/hledger/test/import/match.test @@ -1,10 +1,11 @@ # Various match group interpolation tests. See the comments # in match.rules for specifics. $ hledger -f a.j import --rules match.rules --dry-run match.csv -; would import 1 new transactions from match.csv: - 2022-12-15 Zettle_*Robert W. Bell expenses:snacks £ 7.90 ; Bell=Bell. income:unknown £ -7.90 ; date:2022-12-01 +>2 +would import 1 new transactions from match.csv: + >=