aboutsummaryrefslogtreecommitdiff
path: root/src/args.nim
diff options
context:
space:
mode:
authorBenjamin Shirley-Quirk2020-08-04 20:36:19 +0000
committerBenjamin Shirley-Quirk2020-08-04 20:36:19 +0000
commit0afaa2a8cd7e56f4eabcf6b54e83bcab6be39f42 (patch)
treef474af5f8864f191eb006f3cf69e9c65490fb2cb /src/args.nim
parent8c75dc9df518579cab48a6ded803bf8d493a3cab (diff)
compiles now on current devel (1.3.5)
Diffstat (limited to 'src/args.nim')
-rw-r--r--src/args.nim30
1 files changed, 23 insertions, 7 deletions
diff --git a/src/args.nim b/src/args.nim
index fd03ee0..490bd2b 100644
--- a/src/args.nim
+++ b/src/args.nim
@@ -104,9 +104,14 @@ proc splitArgs*(params: seq[string],
let argsResult = toSeq(splitSingle(current[1 .. ^1], optionsWithParameter, next))
let consumedNext = argsResult.map(a => a.consumedNext).foldl(a or b)
let newNext = next.filter(n => not consumedNext)
-
- return (lc[(x.key, x.value, ArgumentType.short) | (x <- argsResult), Argument],
- newNext, stdinConsumed, false)
+ when NimVersion >= "1.2":
+ let lc = collect(newSeq):
+ for x in argsResult:
+ (x.key,x.value,ArgumentType.short)
+ return (lc, newNext, stdinConsumed, false)
+ else:
+ return (lc[(x.key, x.value, ArgumentType.short) | (x <- argsResult), Argument],
+ newNext, stdinConsumed, false)
else:
return (@[(current, none(string), ArgumentType.target)], next, stdinConsumed, false)
@@ -132,14 +137,20 @@ proc splitArgs*(params: seq[string],
else:
input
- let cycle: ParseCycle = (params.map(some) & none(string))
+ let cycle: ParseCycle = (params.mapIt(some(it)) & none(string))
.foldl(buildArgs(a, b), (newSeq[ParseArgument](), false, false))
if cycle.stdinConsumed:
discard close(0)
discard open("/dev/tty", O_RDONLY)
- lc[x | (y <- cycle.args, x <- y.arg), Argument]
+ when NimVersion >= "1.2":
+ collect(newSeq):
+ for y in cycle.args:
+ for x in y.arg:
+ x
+ else:
+ lc[x | (y <- cycle.args, x <- y.arg), Argument]
proc isShort*(arg: Argument): bool = arg.atype == ArgumentType.short
proc isLong*(arg: Argument): bool = arg.atype == ArgumentType.long
@@ -168,8 +179,13 @@ iterator items*(op: OptionPair): OptionKey =
proc filter*(args: seq[Argument], removeMatches: bool, keepTargets: bool,
pairs: varargs[OptionPair]): seq[Argument] =
let pairsSeq = @pairs
- let argsSet = lc[x | (y <- pairsSeq, x <- y), OptionKey].toHashSet
-
+ when NimVersion >= "1.2":
+ let argsSet = collect(initHashSet):
+ for y in pairsSeq:
+ for x in y:
+ {x}
+ else:
+ let argsSet = lc[x | (y <- pairsSeq, x <- y), OptionKey].toHashSet
args.filter(arg => (arg.isShort and (removeMatches xor (arg.key, false) in argsSet)) or
(arg.isLong and (removeMatches xor (arg.key, true) in argsSet)) or
(arg.isTarget and keepTargets))