diff options
author | Nan Xiao <nan@chinadtrace.org> | 2022-09-28 03:00:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-27 15:00:57 -0400 |
commit | fd257a9a0f363bd31cb0702c729193ee7f8fe8ef (patch) | |
tree | 7df631817e2372fb0207523f2f508c2176b64086 | |
parent | 80e739f2bf5a3e40df7000566a9cbb9cfab29ac4 (diff) | |
download | Nim-fd257a9a0f363bd31cb0702c729193ee7f8fe8ef.tar.gz |
Refactor initOptParser (#19656)
Co-authored-by: flywind <xzsflywind@gmail.com>
-rw-r--r-- | lib/pure/parseopt.nim | 27 |
1 files changed, 5 insertions, 22 deletions
diff --git a/lib/pure/parseopt.nim b/lib/pure/parseopt.nim index fef354733..f8d03e092 100644 --- a/lib/pure/parseopt.nim +++ b/lib/pure/parseopt.nim @@ -192,6 +192,10 @@ proc parseWord(s: string, i: int, w: var string, add(w, s[result]) inc(result) +proc initOptParser*(cmdline: seq[string], shortNoVal: set[char] = {}, + longNoVal: seq[string] = @[]; + allowWhitespaceAfterColon = true): OptParser + proc initOptParser*(cmdline = "", shortNoVal: set[char] = {}, longNoVal: seq[string] = @[]; allowWhitespaceAfterColon = true): OptParser = @@ -214,28 +218,7 @@ proc initOptParser*(cmdline = "", shortNoVal: set[char] = {}, p = initOptParser("--left --debug:3 -l -r:2", shortNoVal = {'l'}, longNoVal = @["left"]) - result.pos = 0 - 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 = "" + initOptParser(parseCmdLine(cmdline), shortNoVal, longNoVal, allowWhitespaceAfterColon) proc initOptParser*(cmdline: seq[string], shortNoVal: set[char] = {}, longNoVal: seq[string] = @[]; |