diff options
Diffstat (limited to 'lib/pure/parseopt.nim')
-rw-r--r-- | lib/pure/parseopt.nim | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/lib/pure/parseopt.nim b/lib/pure/parseopt.nim index c91134738..fe3d3186f 100644 --- a/lib/pure/parseopt.nim +++ b/lib/pure/parseopt.nim @@ -44,9 +44,9 @@ type cmdShortOption ## a short option ``-c`` detected OptParser* = object of RootObj ## this object implements the command line parser - cmd*: string # cmd,pos exported so caller can catch "--" as.. pos*: int # ..empty key or subcmd cmdArg & handle specially inShortState: bool + allowWhitespaceAfterColon: bool shortNoVal: set[char] longNoVal: seq[string] cmds: seq[string] @@ -95,7 +95,8 @@ when declared(os.paramCount): # access the command line arguments then! proc initOptParser*(cmdline = "", shortNoVal: set[char]={}, - longNoVal: seq[string] = @[]): OptParser = + longNoVal: seq[string] = @[]; + allowWhitespaceAfterColon = true): OptParser = ## inits the option parser. If ``cmdline == ""``, the real command line ## (as provided by the ``OS`` module) is taken. If ``shortNoVal`` is ## provided command users do not need to delimit short option keys and @@ -108,23 +109,21 @@ when declared(os.paramCount): result.inShortState = false result.shortNoVal = shortNoVal result.longNoVal = longNoVal + result.allowWhitespaceAfterColon = allowWhitespaceAfterColon if cmdline != "": - result.cmd = cmdline result.cmds = parseCmdLine(cmdline) else: - result.cmd = "" result.cmds = newSeq[string](paramCount()) for i in countup(1, paramCount()): result.cmds[i-1] = paramStr(i).string - result.cmd.add quote(result.cmds[i-1]) - result.cmd.add ' ' result.kind = cmdEnd result.key = TaintedString"" result.val = TaintedString"" proc initOptParser*(cmdline: seq[TaintedString], shortNoVal: set[char]={}, - longNoVal: seq[string] = @[]): OptParser = + longNoVal: seq[string] = @[]; + allowWhitespaceAfterColon = true): OptParser = ## inits the option parser. If ``cmdline.len == 0``, the real command line ## (as provided by the ``OS`` module) is taken. ``shortNoVal`` and ## ``longNoVal`` behavior is the same as for ``initOptParser(string,...)``. @@ -133,19 +132,15 @@ when declared(os.paramCount): result.inShortState = false result.shortNoVal = shortNoVal result.longNoVal = longNoVal - result.cmd = "" + result.allowWhitespaceAfterColon = allowWhitespaceAfterColon if cmdline.len != 0: result.cmds = newSeq[string](cmdline.len) for i in 0..<cmdline.len: result.cmds[i] = cmdline[i].string - result.cmd.add quote(cmdline[i].string) - result.cmd.add ' ' else: result.cmds = newSeq[string](paramCount()) for i in countup(1, paramCount()): result.cmds[i-1] = paramStr(i).string - result.cmd.add quote(result.cmds[i-1]) - result.cmd.add ' ' result.kind = cmdEnd result.key = TaintedString"" result.val = TaintedString"" @@ -210,7 +205,7 @@ proc next*(p: var OptParser) {.rtl, extern: "npo$1".} = inc(i) while i < p.cmds[p.idx].len and p.cmds[p.idx][i] in {'\t', ' '}: inc(i) # if we're at the end, use the next command line option: - if i >= p.cmds[p.idx].len and p.idx < p.cmds.len: + if i >= p.cmds[p.idx].len and p.idx < p.cmds.len and p.allowWhitespaceAfterColon: inc p.idx i = 0 p.val = TaintedString p.cmds[p.idx].substr(i) |