run: support @ARGFILEs (fixes #2330)
This commit is contained in:
parent
6569714d37
commit
88a4b0abae
@ -30,6 +30,7 @@ import Control.Monad (forM_)
|
||||
import Control.Monad.IO.Class (liftIO)
|
||||
import Control.Monad.Extra (concatMapM)
|
||||
|
||||
import System.Console.CmdArgs.Explicit (expandArgsAt)
|
||||
import System.Directory (doesFileExist)
|
||||
import System.IO.Unsafe (unsafePerformIO)
|
||||
import System.Console.Haskeline
|
||||
@ -92,7 +93,7 @@ parseCommand line =
|
||||
|
||||
runCommand :: (String -> Maybe (Mode RawOpts, CliOpts -> Journal -> IO ())) -> [String] -> IO ()
|
||||
runCommand findBuiltinCommand cmdline = do
|
||||
dbg1IO "running command" cmdline
|
||||
dbg1IO "runCommand for" cmdline
|
||||
-- # begins a comment, ignore everything after #
|
||||
case cmdline of
|
||||
"echo":args -> putStrLn $ unwords $ args
|
||||
@ -100,7 +101,11 @@ runCommand findBuiltinCommand cmdline = do
|
||||
case findBuiltinCommand cmdname of
|
||||
Nothing -> putStrLn $ unwords (cmdname:args)
|
||||
Just (cmdmode,cmdaction) -> do
|
||||
opts <- getHledgerCliOpts' cmdmode args
|
||||
-- Normally expandArgsAt is done by the Cli.hs, but it stops at the first '--', so we need
|
||||
-- to do it here as well to make sure that each command can use @ARGFILEs
|
||||
args' <- expandArgsAt args
|
||||
dbg1IO "runCommand final args" (cmdname,args')
|
||||
opts <- getHledgerCliOpts' cmdmode args'
|
||||
withJournalCached opts (cmdaction opts)
|
||||
[] -> return ()
|
||||
|
||||
|
||||
@ -33,8 +33,6 @@ You can use `#!/usr/bin/env hledger run` in the first line of the file to make i
|
||||
|
||||
- If you meant to provide file name as an argument, but made a mistake and a gave file name that does not exist, "run" will attempt to interpret it as a command.
|
||||
|
||||
- Numeric flags like `-3` do not work, use long form `--depth 3`
|
||||
|
||||
- You can pass `-f` to the `run` itself, and also to any commands given after it (or in the command file, or via REPL). When specific command does not have `-f` in its flags, it will use the journal(s) specified in the arguments of `run`. If command does have `-f` flag, this journal would be read and its contents would be cache, so if several commands specify the same `-f` flag, they will read the journal only once.
|
||||
|
||||
### Examples:
|
||||
|
||||
@ -42,8 +42,6 @@ Caveats:
|
||||
and a gave file name that does not exist, "run" will attempt to
|
||||
interpret it as a command.
|
||||
|
||||
- Numeric flags like -3 do not work, use long form --depth 3
|
||||
|
||||
- You can pass -f to the run itself, and also to any commands given
|
||||
after it (or in the command file, or via REPL). When specific
|
||||
command does not have -f in its flags, it will use the journal(s)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user