fixes #2874
This commit is contained in:
parent
0d7e0e1b4f
commit
30829ffec4
1 changed files with 56 additions and 37 deletions
|
|
@ -42,25 +42,6 @@ type
|
|||
|
||||
{.deprecated: [TCmdLineKind: CmdLineKind, TOptParser: OptParser].}
|
||||
|
||||
when declared(os.paramCount):
|
||||
# we cannot provide this for NimRtl creation on Posix, because we can't
|
||||
# access the command line arguments then!
|
||||
|
||||
proc initOptParser*(cmdline = ""): OptParser =
|
||||
## inits the option parser. If ``cmdline == ""``, the real command line
|
||||
## (as provided by the ``OS`` module) is taken.
|
||||
result.pos = 0
|
||||
result.inShortState = false
|
||||
if cmdline != "":
|
||||
result.cmd = cmdline
|
||||
else:
|
||||
result.cmd = ""
|
||||
for i in countup(1, paramCount()):
|
||||
result.cmd = result.cmd & quoteIfContainsWhite(paramStr(i).string) & ' '
|
||||
result.kind = cmdEnd
|
||||
result.key = TaintedString""
|
||||
result.val = TaintedString""
|
||||
|
||||
proc parseWord(s: string, i: int, w: var string,
|
||||
delim: set[char] = {'\x09', ' ', '\0'}): int =
|
||||
result = i
|
||||
|
|
@ -75,6 +56,44 @@ proc parseWord(s: string, i: int, w: var string,
|
|||
add(w, s[result])
|
||||
inc(result)
|
||||
|
||||
when declared(os.paramCount):
|
||||
proc quote(s: string): string =
|
||||
if find(s, {' ', '\t'}) >= 0 and s[0] != '"':
|
||||
if s[0] == '-':
|
||||
result = newStringOfCap(s.len)
|
||||
var i = parseWord(s, 0, result, {'\0', ' ', '\x09', ':', '='})
|
||||
if 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
|
||||
# access the command line arguments then!
|
||||
|
||||
proc initOptParser*(cmdline = ""): OptParser =
|
||||
## inits the option parser. If ``cmdline == ""``, the real command line
|
||||
## (as provided by the ``OS`` module) is taken.
|
||||
result.pos = 0
|
||||
result.inShortState = false
|
||||
if cmdline != "":
|
||||
result.cmd = cmdline
|
||||
else:
|
||||
result.cmd = ""
|
||||
for i in countup(1, paramCount()):
|
||||
result.cmd.add quote(paramStr(i).string)
|
||||
result.cmd.add ' '
|
||||
result.kind = cmdEnd
|
||||
result.key = TaintedString""
|
||||
result.val = TaintedString""
|
||||
|
||||
proc handleShortOption(p: var OptParser) =
|
||||
var i = p.pos
|
||||
p.kind = cmdShortOption
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue