mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-18 21:40:32 +00:00
Fix : and = precedence in parseopt.
This commit is contained in:
@@ -71,7 +71,7 @@ when not defined(createNimRtl):
|
||||
proc next*(p: var TOptParser) {.rtl, extern: "npo$1".}
|
||||
|
||||
proc nextOption(p: var TOptParser, token: string, allowEmpty: bool) =
|
||||
for splitchar in ['=', ':']:
|
||||
for splitchar in [':', '=']:
|
||||
if splitchar in token:
|
||||
let pos = token.find(splitchar)
|
||||
p.key = token[0..pos-1]
|
||||
|
||||
@@ -7,11 +7,12 @@ let argv = commandLineParams()
|
||||
|
||||
if argv == @[]:
|
||||
# this won't work with spaces
|
||||
assert execShellCmd(getAppFilename() & " \"foo bar\" --aa:bar --ab -c --a[baz]:doo") == 0
|
||||
assert execShellCmd(getAppFilename() & " \"foo bar\" --aa:bar=a --a=c:d --ab -c --a[baz]:doo") == 0
|
||||
else:
|
||||
let f = toSeq(getopt())
|
||||
echo f.repr
|
||||
assert f[0].kind == cmdArgument and f[0].key == "foo bar" and f[0].val == ""
|
||||
assert f[1].kind == cmdLongOption and f[1].key == "aa" and f[1].val == "bar"
|
||||
assert f[2].kind == cmdLongOption and f[2].key == "ab" and f[2].val == ""
|
||||
assert f[3].kind == cmdShortOption and f[3].key == "c" and f[3].val == ""
|
||||
assert f[1].kind == cmdLongOption and f[1].key == "aa" and f[1].val == "bar=a"
|
||||
assert f[2].kind == cmdLongOption and f[2].key == "a=c" and f[2].val == "d"
|
||||
assert f[3].kind == cmdLongOption and f[3].key == "ab" and f[3].val == ""
|
||||
assert f[4].kind == cmdShortOption and f[4].key == "c" and f[4].val == ""
|
||||
|
||||
Reference in New Issue
Block a user