From 7fdb2f7fe6a9d519137f285b053069e978a4650b Mon Sep 17 00:00:00 2001 From: Dmitry Astapov Date: Thu, 6 Mar 2025 21:35:04 +0000 Subject: [PATCH] ;run: use leading -- to decide whether to read from files or not --- hledger/Hledger/Cli/Commands/Run.hs | 16 +++++----------- hledger/test/run.test | 4 ++-- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/hledger/Hledger/Cli/Commands/Run.hs b/hledger/Hledger/Cli/Commands/Run.hs index 72031e275..35b8c5433 100644 --- a/hledger/Hledger/Cli/Commands/Run.hs +++ b/hledger/Hledger/Cli/Commands/Run.hs @@ -33,8 +33,6 @@ import Control.Monad.IO.Class (liftIO) import Control.Monad.Extra (concatMapM) import System.Exit (ExitCode) -import System.Console.CmdArgs.Explicit (expandArgsAt) -import System.Directory (doesFileExist) import System.IO (stdin, hIsTerminalDevice, hIsOpen) import System.IO.Unsafe (unsafePerformIO) 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" 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 - allAreFiles <- and <$> mapM (doesFileExist . snd . splitReaderPrefix) args - case allAreFiles of - True -> runFromFiles key findBuiltinCommand args - False -> - case args of - "--":_ -> runFromArgs key findBuiltinCommand args - _ -> error' $ "'run' expects '--' before first command, found none" + -- Check if arguments start with "--". + -- If not, assume that they are files with commands + case args of + "--":_ -> runFromArgs key findBuiltinCommand args + _ -> runFromFiles key findBuiltinCommand args -- | The actual repl command. repl :: (String -> Maybe (Mode RawOpts, CliOpts -> Journal -> IO ())) -> CliOpts -> IO () diff --git a/hledger/test/run.test b/hledger/test/run.test index 062f980ad..e45ad5f08 100644 --- a/hledger/test/run.test +++ b/hledger/test/run.test @@ -5,8 +5,8 @@ 2017-01-01 groceries assets:cash -$100 expenses:food -$ hledger run -f- register cash ->2 /hledger: Error: 'run' expects '--' before first command, found none/ +$ hledger run -f- aregister cash +>2 /hledger: aregister: openFile: does not exist \(No such file or directory\)/ >=1 # ** 0. Run refuses to read input file and commands from stdin