aboutsummaryrefslogtreecommitdiff
path: root/src/args.nim
diff options
context:
space:
mode:
authorzqqw2020-08-05 13:53:43 +0000
committerGitHub2020-08-05 13:53:43 +0000
commitf2a93bea278e9f43cad98ca8e74f9a423f36e333 (patch)
tree721da2b78793860b6fb020194efe2eccea88bac9 /src/args.nim
parentb2321b0ded6f4a9803daf9dbcbd88d56321a9305 (diff)
parent4bbf3dc2097f1de206fa053fac32f675d4ae2927 (diff)
Merge pull request #4 from shirleyquirk/lc_useVersion
I mean it this time
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))