diff --git a/hledger/Hledger/Cli/Commands/Run.hs b/hledger/Hledger/Cli/Commands/Run.hs index 01498787a..72031e275 100644 --- a/hledger/Hledger/Cli/Commands/Run.hs +++ b/hledger/Hledger/Cli/Commands/Run.hs @@ -82,7 +82,12 @@ run defaultJournalOverride findBuiltinCommand cliopts@CliOpts{rawopts_=rawopts} let args = dbg1 "args" $ listofstringopt "args" rawopts isTerminal <- isStdinTerminal if args == [] && not isTerminal - then runREPL key findBuiltinCommand + then do + inputFiles <- journalFilePathFromOpts cliopts + let journalFromStdin = any (== "-") $ map (snd . splitReaderPrefix) $ NE.toList inputFiles + if journalFromStdin + then error' "'run' can't read commands from stdin, as one of the input files was stdin as well" + else runREPL key findBuiltinCommand else do -- Check if arguments could be interpreted as files. -- If not, assume that they are commands specified directly on the command line diff --git a/hledger/test/run.test b/hledger/test/run.test index e9ba65284..062f980ad 100644 --- a/hledger/test/run.test +++ b/hledger/test/run.test @@ -9,6 +9,12 @@ $ hledger run -f- register cash >2 /hledger: Error: 'run' expects '--' before first command, found none/ >=1 +# ** 0. Run refuses to read input file and commands from stdin +< +$ hledger run -f- +>2 /hledger: Error: 'run' can't read commands from stdin, as one of the input files was stdin as well/ +>=1 + # ** 0. Run one command from command line < 2017-01-01 groceries