aboutsummaryrefslogtreecommitdiff
path: root/src/args.nim
diff options
context:
space:
mode:
Diffstat (limited to 'src/args.nim')
-rw-r--r--src/args.nim20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/args.nim b/src/args.nim
index 6da84fd..cd778f6 100644
--- a/src/args.nim
+++ b/src/args.nim
@@ -1,6 +1,6 @@
import
options, os, posix, sequtils, sets, strutils, sugar,
- utils, "listcomp"
+ utils
type
ArgumentType* {.pure.} = enum
@@ -104,9 +104,10 @@ 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)
+ return((block:collect(newSeq):
+ for x in argsResult:
+ (x.key,x.value,ArgumentType.short)
+ ), newNext, stdinConsumed, false)
else:
return (@[(current, none(string), ArgumentType.target)], next, stdinConsumed, false)
@@ -139,7 +140,10 @@ proc splitArgs*(params: seq[string],
discard close(0)
discard open("/dev/tty", O_RDONLY)
- lc[x | (y <- cycle.args, x <- y.arg), Argument]
+ collect(newSeq):
+ for y in cycle.args:
+ for x in y.arg:
+ x
proc isShort*(arg: Argument): bool = arg.atype == ArgumentType.short
proc isLong*(arg: Argument): bool = arg.atype == ArgumentType.long
@@ -168,8 +172,10 @@ 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
-
+ let argsSet = collect(initHashSet):
+ for y in pairsSeq:
+ for x in y:
+ {x}
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))