imp:import: show info output on stderr, not stdout
This commit is contained in:
parent
76dc6d089a
commit
9766f65ac7
@ -18,6 +18,7 @@ import Text.Printf
|
|||||||
import Hledger
|
import Hledger
|
||||||
import Hledger.Cli.CliOptions
|
import Hledger.Cli.CliOptions
|
||||||
import Hledger.Cli.Commands.Add (journalAddTransaction)
|
import Hledger.Cli.Commands.Add (journalAddTransaction)
|
||||||
|
import System.IO (stderr)
|
||||||
|
|
||||||
importmode = hledgerCommandMode
|
importmode = hledgerCommandMode
|
||||||
$(embedFileRelative "Hledger/Cli/Commands/Import.txt")
|
$(embedFileRelative "Hledger/Cli/Commands/Import.txt")
|
||||||
@ -63,20 +64,20 @@ importcmd opts@CliOpts{rawopts_=rawopts,inputopts_=iopts} j = do
|
|||||||
[] -> do
|
[] -> do
|
||||||
-- in this case, we vary the output depending on --dry-run, which is a bit awkward
|
-- in this case, we vary the output depending on --dry-run, which is a bit awkward
|
||||||
let semicolon = if dryrun then "; " else "" :: String
|
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 ->
|
newts | catchup ->
|
||||||
if dryrun
|
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
|
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
|
saveLatestDatesForFiles latestdatesforfiles
|
||||||
|
|
||||||
newts -> do
|
newts -> do
|
||||||
if dryrun
|
if dryrun
|
||||||
then do
|
then do
|
||||||
-- show txns to be imported
|
-- 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
|
mapM_ (T.putStr . showTransaction) newts
|
||||||
|
|
||||||
-- then check the whole journal with them added, if in strict mode
|
-- 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.
|
-- mixed line endings in the file. See also writeFileWithBackupIfChanged.
|
||||||
foldM_ (`journalAddTransaction` opts) j newts -- gets forced somehow.. (how ?)
|
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
|
-- and if we got this far, update each file's .latest file
|
||||||
saveLatestDatesForFiles latestdatesforfiles
|
saveLatestDatesForFiles latestdatesforfiles
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
# import applies the receiving journal's commodity styles to imported amounts
|
# import applies the receiving journal's commodity styles to imported amounts
|
||||||
$ hledger -f a.j import --dry-run a.csv
|
$ hledger -f a.j import --dry-run a.csv
|
||||||
; would import 1 new transactions from a.csv:
|
|
||||||
|
|
||||||
2020-01-01
|
2020-01-01
|
||||||
expenses:unknown 1.000.000,00
|
expenses:unknown 1.000.000,00
|
||||||
income:unknown -1.000.000,00
|
income:unknown -1.000.000,00
|
||||||
|
|
||||||
|
>2
|
||||||
|
would import 1 new transactions from a.csv:
|
||||||
|
|
||||||
>=
|
>=
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
# Various match group interpolation tests. See the comments
|
# Various match group interpolation tests. See the comments
|
||||||
# in match.rules for specifics.
|
# in match.rules for specifics.
|
||||||
$ hledger -f a.j import --rules match.rules --dry-run match.csv
|
$ 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
|
2022-12-15 Zettle_*Robert W. Bell
|
||||||
expenses:snacks £ 7.90 ; Bell=Bell.
|
expenses:snacks £ 7.90 ; Bell=Bell.
|
||||||
income:unknown £ -7.90 ; date:2022-12-01
|
income:unknown £ -7.90 ; date:2022-12-01
|
||||||
|
|
||||||
|
>2
|
||||||
|
would import 1 new transactions from match.csv:
|
||||||
|
|
||||||
>=
|
>=
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user