diff --git a/hledger/Hledger/Cli.hs b/hledger/Hledger/Cli.hs index 40614755e..314558c0a 100644 --- a/hledger/Hledger/Cli.hs +++ b/hledger/Hledger/Cli.hs @@ -235,15 +235,24 @@ main = withGhcDebug' $ do -- cmdname = the full unabbreviated command name, or "" -- 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 cliargs <- getArgs >>= expandArgsAt -- interpolate @ARGFILEs <&> replaceNumericFlags -- convert -NUM to --depth=NUM + <&> doubleDoubleDash -- repeat the -- arg as a cmdargs workaround let (clicmdarg, cliargswithoutcmd, cliargswithcmdfirst) = moveFlagsAfterCommand cliargs cliargswithcmdfirstwithoutclispecific = dropCliSpecificOpts cliargswithcmdfirst (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 dbgIO "cli command argument found" clicmdarg dbgIO "cli args before command" cliargsbeforecmd