imp:import: show info output on stderr, not stdout

This commit is contained in:
Simon Michael 2025-08-14 12:53:44 +01:00
parent 76dc6d089a
commit 9766f65ac7
3 changed files with 12 additions and 9 deletions

View File

@ -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

View File

@ -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:
>=

View File

@ -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:
>=