fix cmdline bugs affecting nimBetterRun correctness (#12933) [backport]
This commit is contained in:
parent
cb0a20b9b4
commit
206a4cee77
1 changed files with 15 additions and 3 deletions
|
|
@ -40,19 +40,31 @@ proc prependCurDir(f: AbsoluteFile): AbsoluteFile =
|
||||||
else:
|
else:
|
||||||
result = f
|
result = f
|
||||||
|
|
||||||
|
proc addCmdPrefix*(result: var string, kind: CmdLineKind) =
|
||||||
|
# consider moving this to std/parseopt
|
||||||
|
case kind
|
||||||
|
of cmdLongOption: result.add "--"
|
||||||
|
of cmdShortOption: result.add "-"
|
||||||
|
of cmdArgument, cmdEnd: discard
|
||||||
|
|
||||||
proc processCmdLine(pass: TCmdLinePass, cmd: string; config: ConfigRef) =
|
proc processCmdLine(pass: TCmdLinePass, cmd: string; config: ConfigRef) =
|
||||||
var p = parseopt.initOptParser(cmd)
|
var p = parseopt.initOptParser(cmd)
|
||||||
var argsCount = 0
|
var argsCount = 0
|
||||||
|
|
||||||
|
config.commandLine.setLen 0
|
||||||
|
# bugfix: otherwise, config.commandLine ends up duplicated
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
parseopt.next(p)
|
parseopt.next(p)
|
||||||
case p.kind
|
case p.kind
|
||||||
of cmdEnd: break
|
of cmdEnd: break
|
||||||
of cmdLongOption, cmdShortOption:
|
of cmdLongOption, cmdShortOption:
|
||||||
config.commandLine.add " "
|
config.commandLine.add " "
|
||||||
config.commandLine.add p.key
|
config.commandLine.addCmdPrefix p.kind
|
||||||
|
config.commandLine.add p.key.quoteShell # quoteShell to be future proof
|
||||||
if p.val.len > 0:
|
if p.val.len > 0:
|
||||||
config.commandLine.add ':'
|
config.commandLine.add ':'
|
||||||
config.commandLine.add p.val
|
config.commandLine.add p.val.quoteShell
|
||||||
|
|
||||||
if p.key == " ":
|
if p.key == " ":
|
||||||
p.key = "-"
|
p.key = "-"
|
||||||
|
|
@ -61,7 +73,7 @@ proc processCmdLine(pass: TCmdLinePass, cmd: string; config: ConfigRef) =
|
||||||
processSwitch(pass, p, config)
|
processSwitch(pass, p, config)
|
||||||
of cmdArgument:
|
of cmdArgument:
|
||||||
config.commandLine.add " "
|
config.commandLine.add " "
|
||||||
config.commandLine.add p.key
|
config.commandLine.add p.key.quoteShell
|
||||||
if processArgument(pass, p, argsCount, config): break
|
if processArgument(pass, p, argsCount, config): break
|
||||||
if pass == passCmd2:
|
if pass == passCmd2:
|
||||||
if {optRun, optWasNimscript} * config.globalOptions == {} and
|
if {optRun, optWasNimscript} * config.globalOptions == {} and
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue