parent
e17321aa24
commit
0a8762eb7b
3 changed files with 94 additions and 68 deletions
|
|
@ -171,7 +171,7 @@ proc computeNotesVerbosity(): array[0..3, TNoteKinds] =
|
||||||
warnGcUnsafe, hintPath, hintDependency, hintCodeBegin, hintCodeEnd,
|
warnGcUnsafe, hintPath, hintDependency, hintCodeBegin, hintCodeEnd,
|
||||||
hintSource, hintGlobalVar, hintGCStats}
|
hintSource, hintGlobalVar, hintGCStats}
|
||||||
result[0] = result[1] - {hintSuccessX, hintSuccess, hintConf,
|
result[0] = result[1] - {hintSuccessX, hintSuccess, hintConf,
|
||||||
hintProcessing, hintPattern, hintExecuting, hintLinking}
|
hintProcessing, hintPattern, hintExecuting, hintLinking, hintCC}
|
||||||
|
|
||||||
const
|
const
|
||||||
NotesVerbosity* = computeNotesVerbosity()
|
NotesVerbosity* = computeNotesVerbosity()
|
||||||
|
|
|
||||||
|
|
@ -73,24 +73,6 @@ proc parseWord(s: string, i: int, w: var string,
|
||||||
inc(result)
|
inc(result)
|
||||||
|
|
||||||
when declared(os.paramCount):
|
when declared(os.paramCount):
|
||||||
proc quote(s: string): string =
|
|
||||||
if find(s, {' ', '\t'}) >= 0 and s.len > 0 and s[0] != '"':
|
|
||||||
if s[0] == '-':
|
|
||||||
result = newStringOfCap(s.len)
|
|
||||||
var i = parseWord(s, 0, result, {' ', '\t', ':', '='})
|
|
||||||
if i < s.len and s[i] in {':','='}:
|
|
||||||
result.add s[i]
|
|
||||||
inc i
|
|
||||||
result.add '"'
|
|
||||||
while i < s.len:
|
|
||||||
result.add s[i]
|
|
||||||
inc i
|
|
||||||
result.add '"'
|
|
||||||
else:
|
|
||||||
result = '"' & s & '"'
|
|
||||||
else:
|
|
||||||
result = s
|
|
||||||
|
|
||||||
# we cannot provide this for NimRtl creation on Posix, because we can't
|
# we cannot provide this for NimRtl creation on Posix, because we can't
|
||||||
# access the command line arguments then!
|
# access the command line arguments then!
|
||||||
|
|
||||||
|
|
@ -228,11 +210,7 @@ proc next*(p: var OptParser) {.rtl, extern: "npo$1".} =
|
||||||
when declared(os.paramCount):
|
when declared(os.paramCount):
|
||||||
proc cmdLineRest*(p: OptParser): TaintedString {.rtl, extern: "npo$1".} =
|
proc cmdLineRest*(p: OptParser): TaintedString {.rtl, extern: "npo$1".} =
|
||||||
## retrieves the rest of the command line that has not been parsed yet.
|
## retrieves the rest of the command line that has not been parsed yet.
|
||||||
var res = ""
|
result = p.cmds[p.idx .. ^1].quoteShellCommand.TaintedString
|
||||||
for i in p.idx..<p.cmds.len:
|
|
||||||
if i > p.idx: res.add ' '
|
|
||||||
res.add quote(p.cmds[i])
|
|
||||||
result = res.TaintedString
|
|
||||||
|
|
||||||
proc remainingArgs*(p: OptParser): seq[TaintedString] {.rtl, extern: "npo$1".} =
|
proc remainingArgs*(p: OptParser): seq[TaintedString] {.rtl, extern: "npo$1".} =
|
||||||
## retrieves the rest of the command line that has not been parsed yet.
|
## retrieves the rest of the command line that has not been parsed yet.
|
||||||
|
|
|
||||||
|
|
@ -30,11 +30,20 @@ kind: cmdLongOption key:val -- debug:3
|
||||||
kind: cmdShortOption key:val -- l:4
|
kind: cmdShortOption key:val -- l:4
|
||||||
kind: cmdShortOption key:val -- r:2'''
|
kind: cmdShortOption key:val -- r:2'''
|
||||||
"""
|
"""
|
||||||
from parseopt import nil
|
|
||||||
from parseopt2 import nil
|
|
||||||
|
|
||||||
|
when defined(testament_tparseopt):
|
||||||
|
import os
|
||||||
|
proc main() =
|
||||||
|
let args = commandLineParams()
|
||||||
|
echo args
|
||||||
|
for i, ai in args:
|
||||||
|
echo "arg ", i, " ai.len:", ai.len, " :{", ai, "}"
|
||||||
|
main()
|
||||||
|
else:
|
||||||
|
from parseopt import nil
|
||||||
|
from parseopt2 import nil
|
||||||
|
|
||||||
block:
|
block:
|
||||||
echo "parseopt"
|
echo "parseopt"
|
||||||
for kind, key, val in parseopt.getopt():
|
for kind, key, val in parseopt.getopt():
|
||||||
echo "kind: ", kind, "\tkey:val -- ", key, ":", val
|
echo "kind: ", kind, "\tkey:val -- ", key, ":", val
|
||||||
|
|
@ -52,11 +61,12 @@ block:
|
||||||
echo "kind: ", kind, "\tkey:val -- ", key, ":", val
|
echo "kind: ", kind, "\tkey:val -- ", key, ":", val
|
||||||
|
|
||||||
# bug #9619
|
# bug #9619
|
||||||
var x = parseopt.initOptParser(@["--foo:", "--path"], allowWhitespaceAfterColon = false)
|
var x = parseopt.initOptParser(@["--foo:", "--path"],
|
||||||
|
allowWhitespaceAfterColon = false)
|
||||||
for kind, key, val in parseopt.getopt(x):
|
for kind, key, val in parseopt.getopt(x):
|
||||||
echo kind, " ", key
|
echo kind, " ", key
|
||||||
|
|
||||||
block:
|
block:
|
||||||
echo "parseoptNoVal"
|
echo "parseoptNoVal"
|
||||||
# test NoVal mode with custom cmdline arguments
|
# test NoVal mode with custom cmdline arguments
|
||||||
var argv = "--left --debug:3 -l -r:2 --debug 2 --debug=1 -r1 -r=0 -lr4"
|
var argv = "--left --debug:3 -l -r:2 --debug 2 --debug=1 -r1 -r=0 -lr4"
|
||||||
|
|
@ -65,7 +75,7 @@ block:
|
||||||
for kind, key, val in parseopt.getopt(p):
|
for kind, key, val in parseopt.getopt(p):
|
||||||
echo "kind: ", kind, "\tkey:val -- ", key, ":", val
|
echo "kind: ", kind, "\tkey:val -- ", key, ":", val
|
||||||
|
|
||||||
block:
|
block:
|
||||||
echo "parseopt2"
|
echo "parseopt2"
|
||||||
for kind, key, val in parseopt2.getopt():
|
for kind, key, val in parseopt2.getopt():
|
||||||
echo "kind: ", kind, "\tkey:val -- ", key, ":", val
|
echo "kind: ", kind, "\tkey:val -- ", key, ":", val
|
||||||
|
|
@ -81,3 +91,41 @@ block:
|
||||||
echo "second round"
|
echo "second round"
|
||||||
for kind, key, val in parseopt2.getopt(p):
|
for kind, key, val in parseopt2.getopt(p):
|
||||||
echo "kind: ", kind, "\tkey:val -- ", key, ":", val
|
echo "kind: ", kind, "\tkey:val -- ", key, ":", val
|
||||||
|
|
||||||
|
import osproc, os, strutils
|
||||||
|
from stdtest/specialpaths import buildDir
|
||||||
|
import "../.." / compiler/unittest_light
|
||||||
|
|
||||||
|
block: # fix #9951
|
||||||
|
var p = parseopt.initOptParser(@["echo \"quoted\""])
|
||||||
|
assertEquals parseopt.cmdLineRest(p), """'echo "quoted"'"""
|
||||||
|
let args = @["a1b", "a2 b", "", "a4\"b", "a5'b", r"a6\b", "a7\'b"]
|
||||||
|
var p2 = parseopt.initOptParser(args)
|
||||||
|
assertEquals parseopt.cmdLineRest(p2),
|
||||||
|
"""a1b 'a2 b' '' 'a4"b' 'a5'"'"'b' 'a6\b' 'a7'"'"'b'"""
|
||||||
|
doAssert "a5'b" == "a5\'b"
|
||||||
|
|
||||||
|
block: # fix #9842
|
||||||
|
let exe = buildDir / "D20190112T145450".addFileExt(ExeExt)
|
||||||
|
defer: removeFile exe
|
||||||
|
let args = @["a1b", "a2 b", "", "a4\"b", "a5'b", r"a6\b", "a7\'b"]
|
||||||
|
let cmd = "$# c -r --verbosity:0 -o:$# -d:testament_tparseopt $# $#" %
|
||||||
|
[getCurrentCompilerExe(), exe, currentSourcePath(),
|
||||||
|
args.quoteShellCommand]
|
||||||
|
var ret = execCmdEx(cmd, options = {})
|
||||||
|
if ret.exitCode != 0:
|
||||||
|
# before bug fix, running cmd would show:
|
||||||
|
# sh: -c: line 0: unexpected EOF while looking for matching `"'\n
|
||||||
|
echo "exitCode: ", ret.exitCode, " cmd:", cmd
|
||||||
|
doAssert false
|
||||||
|
stripLineEnd(ret.output)
|
||||||
|
assertEquals ret.output,
|
||||||
|
"""
|
||||||
|
@["a1b", "a2 b", "", "a4\"b", "a5\'b", "a6\\b", "a7\'b"]
|
||||||
|
arg 0 ai.len:3 :{a1b}
|
||||||
|
arg 1 ai.len:4 :{a2 b}
|
||||||
|
arg 2 ai.len:0 :{}
|
||||||
|
arg 3 ai.len:4 :{a4"b}
|
||||||
|
arg 4 ai.len:4 :{a5'b}
|
||||||
|
arg 5 ai.len:4 :{a6\b}
|
||||||
|
arg 6 ai.len:4 :{a7'b}"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue