mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-15 07:43:26 +00:00
parseopt2.cmdLineRest is now correct too (#10304)
This commit is contained in:
committed by
Andreas Rumpf
parent
beed27b75d
commit
795e5e11ef
@@ -112,10 +112,10 @@ proc next(p: var OptParser) =
|
||||
p.key = token
|
||||
p.val = ""
|
||||
|
||||
proc cmdLineRest*(p: OptParser): TaintedString {.rtl, extern: "npo2$1", deprecated.} =
|
||||
## Returns part of command line string that has not been parsed yet.
|
||||
## Do not use - does not correctly handle whitespace.
|
||||
return p.cmd[p.pos..p.cmd.len-1].join(" ")
|
||||
proc cmdLineRest*(p: OptParser): TaintedString {.rtl, extern: "npo2$1".} =
|
||||
## Returns the part of command line string that has not been parsed yet,
|
||||
## properly quoted.
|
||||
return p.cmd[p.pos..p.cmd.len-1].quoteShellCommand
|
||||
|
||||
type
|
||||
GetoptResult* = tuple[kind: CmdLineKind, key, val: TaintedString]
|
||||
|
||||
@@ -97,24 +97,27 @@ else:
|
||||
from stdtest/specialpaths import buildDir
|
||||
import "../.." / compiler/unittest_light
|
||||
|
||||
block: # fix #9951
|
||||
var p = parseopt.initOptParser(@["echo \"quoted\""])
|
||||
let expected = when defined(windows):
|
||||
""""echo \"quoted\"""""
|
||||
else:
|
||||
"""'echo "quoted"'"""
|
||||
assertEquals parseopt.cmdLineRest(p), expected
|
||||
block: # fix #9951 (and make it work for parseopt and parseopt2)
|
||||
template runTest(parseoptCustom) =
|
||||
var p = parseoptCustom.initOptParser(@["echo \"quoted\""])
|
||||
let expected = when defined(windows):
|
||||
""""echo \"quoted\"""""
|
||||
else:
|
||||
"""'echo "quoted"'"""
|
||||
assertEquals parseoptCustom.cmdLineRest(p), expected
|
||||
|
||||
doAssert "a5'b" == "a5\'b"
|
||||
doAssert "a5'b" == "a5\'b"
|
||||
|
||||
let args = @["a1b", "a2 b", "", "a4\"b", "a5'b", r"a6\b", "a7\'b"]
|
||||
var p2 = parseopt.initOptParser(args)
|
||||
let expected2 = when defined(windows):
|
||||
"""a1b "a2 b" "" a4\"b a5'b a6\b a7'b"""
|
||||
else:
|
||||
"""a1b 'a2 b' '' 'a4"b' 'a5'"'"'b' 'a6\b' 'a7'"'"'b'"""
|
||||
doAssert "a5'b" == "a5\'b"
|
||||
assertEquals parseopt.cmdLineRest(p2), expected2
|
||||
let args = @["a1b", "a2 b", "", "a4\"b", "a5'b", r"a6\b", "a7\'b"]
|
||||
var p2 = parseoptCustom.initOptParser(args)
|
||||
let expected2 = when defined(windows):
|
||||
"""a1b "a2 b" "" a4\"b a5'b a6\b a7'b"""
|
||||
else:
|
||||
"""a1b 'a2 b' '' 'a4"b' 'a5'"'"'b' 'a6\b' 'a7'"'"'b'"""
|
||||
doAssert "a5'b" == "a5\'b"
|
||||
assertEquals parseoptCustom.cmdLineRest(p2), expected2
|
||||
runTest(parseopt)
|
||||
runTest(parseopt2)
|
||||
|
||||
block: # fix #9842
|
||||
let exe = buildDir / "D20190112T145450".addFileExt(ExeExt)
|
||||
|
||||
Reference in New Issue
Block a user