fix:repl: make the run command work in the REPL again
The now-required -- argument was being lost during REPL parsing. I think this is right, though it's hard to understand.
This commit is contained in:
parent
fd906bec95
commit
9ecc3a56d0
@ -235,19 +235,11 @@ main = withGhcDebug' $ do
|
|||||||
-- cmdname = the full unabbreviated command name, or ""
|
-- cmdname = the full unabbreviated command name, or ""
|
||||||
-- confcmdargs = arguments for the subcommand, from config file
|
-- confcmdargs = arguments for the subcommand, from config file
|
||||||
|
|
||||||
let
|
|
||||||
-- | cmdargs eats the first double-dash (--) argument, causing problems for
|
|
||||||
-- the run command. To work around it, we'll insert another.
|
|
||||||
-- This doesn't break anything that we know of.
|
|
||||||
doubleDoubleDash args
|
|
||||||
| "--" `elem` args = let (as,bs) = break (=="--") args in as <> ["--"] <> bs
|
|
||||||
| otherwise = args
|
|
||||||
|
|
||||||
-- Do some argument preprocessing to help cmdargs
|
-- Do some argument preprocessing to help cmdargs
|
||||||
cliargs <- getArgs
|
cliargs <- getArgs
|
||||||
>>= expandArgsAt -- interpolate @ARGFILEs
|
>>= expandArgsAt -- interpolate @ARGFILEs
|
||||||
<&> replaceNumericFlags -- convert -NUM to --depth=NUM
|
<&> replaceNumericFlags -- convert -NUM to --depth=NUM
|
||||||
<&> doubleDoubleDash -- repeat the -- arg as a cmdargs workaround
|
<&> argsAddDoubleDash -- repeat the first -- arg, as a cmdargs workaround
|
||||||
let
|
let
|
||||||
(clicmdarg, cliargswithoutcmd, cliargswithcmdfirst) = moveFlagsAfterCommand cliargs
|
(clicmdarg, cliargswithoutcmd, cliargswithcmdfirst) = moveFlagsAfterCommand cliargs
|
||||||
cliargswithcmdfirstwithoutclispecific = dropCliSpecificOpts cliargswithcmdfirst
|
cliargswithcmdfirstwithoutclispecific = dropCliSpecificOpts cliargswithcmdfirst
|
||||||
|
|||||||
@ -58,6 +58,7 @@ module Hledger.Cli.CliOptions (
|
|||||||
getHledgerCliOpts',
|
getHledgerCliOpts',
|
||||||
rawOptsToCliOpts,
|
rawOptsToCliOpts,
|
||||||
cliOptsDropArgs,
|
cliOptsDropArgs,
|
||||||
|
argsAddDoubleDash,
|
||||||
outputFormats,
|
outputFormats,
|
||||||
defaultOutputFormat,
|
defaultOutputFormat,
|
||||||
CommandHelpStr,
|
CommandHelpStr,
|
||||||
@ -632,6 +633,14 @@ rawOptsToCliOpts rawopts = do
|
|||||||
cliOptsDropArgs :: CliOpts -> CliOpts
|
cliOptsDropArgs :: CliOpts -> CliOpts
|
||||||
cliOptsDropArgs copts@CliOpts{rawopts_} = copts{rawopts_ = dropRawOpt "args" rawopts_}
|
cliOptsDropArgs copts@CliOpts{rawopts_} = copts{rawopts_ = dropRawOpt "args" rawopts_}
|
||||||
|
|
||||||
|
-- | cmdargs eats the first double-dash (--) argument when parsing a command line,
|
||||||
|
-- which causes problems for the run and repl commands.
|
||||||
|
-- Sometimes we work around this by duplicating that first -- argument.
|
||||||
|
-- This doesn't break anything that we know of yet.
|
||||||
|
argsAddDoubleDash args'
|
||||||
|
| "--" `elem` args' = let (as,bs) = break (=="--") args' in as <> ["--"] <> bs
|
||||||
|
| otherwise = args'
|
||||||
|
|
||||||
-- | A helper for addon commands: this parses options and arguments from
|
-- | A helper for addon commands: this parses options and arguments from
|
||||||
-- the current command line using the given hledger-style cmdargs mode,
|
-- the current command line using the given hledger-style cmdargs mode,
|
||||||
-- and returns a CliOpts. Or, with --help or -h present, it prints
|
-- and returns a CliOpts. Or, with --help or -h present, it prints
|
||||||
|
|||||||
@ -178,7 +178,7 @@ runREPL defaultJournalOverride findBuiltinCommand = do
|
|||||||
Just "quit" -> return ()
|
Just "quit" -> return ()
|
||||||
Just "exit" -> return ()
|
Just "exit" -> return ()
|
||||||
Just input -> do
|
Just input -> do
|
||||||
liftIO $ (runCommand defaultJournalOverride findBuiltinCommand $ parseCommand input)
|
liftIO $ (runCommand defaultJournalOverride findBuiltinCommand $ argsAddDoubleDash $ parseCommand input)
|
||||||
`catches`
|
`catches`
|
||||||
[Handler (\(e::ErrorCall) -> putStr $ show e)
|
[Handler (\(e::ErrorCall) -> putStr $ show e)
|
||||||
,Handler (\(_::ExitCode) -> return ())
|
,Handler (\(_::ExitCode) -> return ())
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user