Refactor initOptParser (#19656)
Co-authored-by: flywind <xzsflywind@gmail.com>
This commit is contained in:
parent
80e739f2bf
commit
fd257a9a0f
1 changed files with 5 additions and 22 deletions
|
|
@ -192,6 +192,10 @@ proc parseWord(s: string, i: int, w: var string,
|
||||||
add(w, s[result])
|
add(w, s[result])
|
||||||
inc(result)
|
inc(result)
|
||||||
|
|
||||||
|
proc initOptParser*(cmdline: seq[string], shortNoVal: set[char] = {},
|
||||||
|
longNoVal: seq[string] = @[];
|
||||||
|
allowWhitespaceAfterColon = true): OptParser
|
||||||
|
|
||||||
proc initOptParser*(cmdline = "", shortNoVal: set[char] = {},
|
proc initOptParser*(cmdline = "", shortNoVal: set[char] = {},
|
||||||
longNoVal: seq[string] = @[];
|
longNoVal: seq[string] = @[];
|
||||||
allowWhitespaceAfterColon = true): OptParser =
|
allowWhitespaceAfterColon = true): OptParser =
|
||||||
|
|
@ -214,28 +218,7 @@ proc initOptParser*(cmdline = "", shortNoVal: set[char] = {},
|
||||||
p = initOptParser("--left --debug:3 -l -r:2",
|
p = initOptParser("--left --debug:3 -l -r:2",
|
||||||
shortNoVal = {'l'}, longNoVal = @["left"])
|
shortNoVal = {'l'}, longNoVal = @["left"])
|
||||||
|
|
||||||
result.pos = 0
|
initOptParser(parseCmdLine(cmdline), shortNoVal, longNoVal, allowWhitespaceAfterColon)
|
||||||
result.idx = 0
|
|
||||||
result.inShortState = false
|
|
||||||
result.shortNoVal = shortNoVal
|
|
||||||
result.longNoVal = longNoVal
|
|
||||||
result.allowWhitespaceAfterColon = allowWhitespaceAfterColon
|
|
||||||
if cmdline != "":
|
|
||||||
result.cmds = parseCmdLine(cmdline)
|
|
||||||
else:
|
|
||||||
when declared(paramCount):
|
|
||||||
result.cmds = newSeq[string](paramCount())
|
|
||||||
for i in countup(1, paramCount()):
|
|
||||||
result.cmds[i-1] = paramStr(i)
|
|
||||||
else:
|
|
||||||
# we cannot provide this for NimRtl creation on Posix, because we can't
|
|
||||||
# access the command line arguments then!
|
|
||||||
doAssert false, "empty command line given but" &
|
|
||||||
" real command line is not accessible"
|
|
||||||
|
|
||||||
result.kind = cmdEnd
|
|
||||||
result.key = ""
|
|
||||||
result.val = ""
|
|
||||||
|
|
||||||
proc initOptParser*(cmdline: seq[string], shortNoVal: set[char] = {},
|
proc initOptParser*(cmdline: seq[string], shortNoVal: set[char] = {},
|
||||||
longNoVal: seq[string] = @[];
|
longNoVal: seq[string] = @[];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue