;dev:cli: to help run's command line parsing, double the first -- [#2328]

So that when cmdargs eats it, another remains.
This commit is contained in:
Simon Michael 2025-03-06 09:54:19 -10:00
parent 0b20e11857
commit aee85df17b

View File

@ -235,15 +235,24 @@ 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
let let
(clicmdarg, cliargswithoutcmd, cliargswithcmdfirst) = moveFlagsAfterCommand cliargs (clicmdarg, cliargswithoutcmd, cliargswithcmdfirst) = moveFlagsAfterCommand cliargs
cliargswithcmdfirstwithoutclispecific = dropCliSpecificOpts cliargswithcmdfirst cliargswithcmdfirstwithoutclispecific = dropCliSpecificOpts cliargswithcmdfirst
(cliargsbeforecmd, cliargsaftercmd) = second (drop 1) $ break (==clicmdarg) cliargs (cliargsbeforecmd, cliargsaftercmd) = second (drop 1) $ break (==clicmdarg) cliargs
dbgIO "cli args" cliargs dbgIO "cli args, with some preprocessing like doubling --" cliargs
dbg1IO "cli args with options moved after command, if any" cliargswithcmdfirst dbg1IO "cli args with options moved after command, if any" cliargswithcmdfirst
dbgIO "cli command argument found" clicmdarg dbgIO "cli command argument found" clicmdarg
dbgIO "cli args before command" cliargsbeforecmd dbgIO "cli args before command" cliargsbeforecmd