;run: use leading -- to decide whether to read from files or not

This commit is contained in:
Dmitry Astapov 2025-03-06 21:35:04 +00:00 committed by Simon Michael
parent 4dbeac284c
commit 7fdb2f7fe6
2 changed files with 7 additions and 13 deletions

View File

@ -33,8 +33,6 @@ import Control.Monad.IO.Class (liftIO)
import Control.Monad.Extra (concatMapM) import Control.Monad.Extra (concatMapM)
import System.Exit (ExitCode) import System.Exit (ExitCode)
import System.Console.CmdArgs.Explicit (expandArgsAt)
import System.Directory (doesFileExist)
import System.IO (stdin, hIsTerminalDevice, hIsOpen) import System.IO (stdin, hIsTerminalDevice, hIsOpen)
import System.IO.Unsafe (unsafePerformIO) import System.IO.Unsafe (unsafePerformIO)
import System.Console.Haskeline import System.Console.Haskeline
@ -89,15 +87,11 @@ run defaultJournalOverride findBuiltinCommand cliopts@CliOpts{rawopts_=rawopts}
then error' "'run' can't read commands from stdin, as one of the input files was stdin as well" then error' "'run' can't read commands from stdin, as one of the input files was stdin as well"
else runREPL key findBuiltinCommand else runREPL key findBuiltinCommand
else do else do
-- Check if arguments could be interpreted as files. -- Check if arguments start with "--".
-- If not, assume that they are commands specified directly on the command line -- If not, assume that they are files with commands
allAreFiles <- and <$> mapM (doesFileExist . snd . splitReaderPrefix) args case args of
case allAreFiles of "--":_ -> runFromArgs key findBuiltinCommand args
True -> runFromFiles key findBuiltinCommand args _ -> runFromFiles key findBuiltinCommand args
False ->
case args of
"--":_ -> runFromArgs key findBuiltinCommand args
_ -> error' $ "'run' expects '--' before first command, found none"
-- | The actual repl command. -- | The actual repl command.
repl :: (String -> Maybe (Mode RawOpts, CliOpts -> Journal -> IO ())) -> CliOpts -> IO () repl :: (String -> Maybe (Mode RawOpts, CliOpts -> Journal -> IO ())) -> CliOpts -> IO ()

View File

@ -5,8 +5,8 @@
2017-01-01 groceries 2017-01-01 groceries
assets:cash -$100 assets:cash -$100
expenses:food expenses:food
$ hledger run -f- register cash $ hledger run -f- aregister cash
>2 /hledger: Error: 'run' expects '--' before first command, found none/ >2 /hledger: aregister: openFile: does not exist \(No such file or directory\)/
>=1 >=1
# ** 0. Run refuses to read input file and commands from stdin # ** 0. Run refuses to read input file and commands from stdin