aboutsummaryrefslogtreecommitdiff
path: root/src/pacman.nim
diff options
context:
space:
mode:
Diffstat (limited to 'src/pacman.nim')
-rw-r--r--src/pacman.nim93
1 files changed, 74 insertions, 19 deletions
diff --git a/src/pacman.nim b/src/pacman.nim
index 520a67e..ed80311 100644
--- a/src/pacman.nim
+++ b/src/pacman.nim
@@ -1,6 +1,6 @@
import
macros, options, posix, sequtils, sets, strutils, sugar, tables,
- args, config, utils, "listcomp"
+ args, config, utils
type
OpGroup* {.pure.} = enum
@@ -36,7 +36,10 @@ proc calculateOptionsWithParameter(opts: seq[CommandOption]): seq[OptionKey] {.c
else:
@[]
- lc[x | (y <- opts, x <- commandToSeq(y)), OptionKey]
+ collect(newSeq):
+ for y in opts:
+ for x in commandToSeq(y):
+ x
proc o(long: string): CommandOption {.compileTime.} =
((none(string), long), false, false, {})
@@ -200,7 +203,10 @@ proc getOperation*(args: seq[Argument]): OperationType =
proc filterOptions*(args: seq[Argument], removeMatches: bool, keepTargets: bool,
includeOperations: bool, opts: varargs[seq[CommandOption]]): seq[Argument] =
let optsSeq = @opts
- let optsPairSeq = lc[x.pair | (y <- optsSeq, x <- y), OptionPair]
+ let optsPairSeq = collect(newSeq):
+ for y in optsSeq:
+ for x in y:
+ x.pair
let work = if includeOperations:
(optsPairSeq & operations.map(o => o.pair))
@@ -234,16 +240,30 @@ proc filterExtensions*(args: seq[Argument], removeMatches: bool, keepTargets: bo
opts: varargs[seq[CommandOption]]): seq[Argument] =
let optsSeq = @opts
let optsFilter = if removeMatches:
- lc[x | (y <- optsSeq, x <- y), CommandOption]
+ collect(newSeq):
+ for y in optsSeq:
+ for x in y:
+ x
else: (block:
- let pairs = lc[x.pair | (y <- optsSeq, x <- y), OptionPair].toHashSet
- lc[x | (x <- allOptions, not (x.pair in pairs)), CommandOption])
-
- let argsSeq = lc[x.pair | (x <- optsFilter, x.extension), OptionPair]
- args.filter(removeMatches, keepTargets, argsSeq)
-
+ let pairs = collect(initHashSet):
+ for y in optsSeq:
+ for x in y:
+ {x.pair}
+ collect(newSeq):
+ for x in allOptions:
+ if not (x.pair in pairs):
+ x
+ )
+ let argsSeq = collect(newSeq):
+ for x in optsFilter:
+ if x.extension:
+ x.pair
+ args.filter(removeMatches,keepTargets,argsSeq)
proc obtainConflictsPairs(conflicts: seq[ConflictingOptions]): Table[string, seq[OptionPair]] =
- let all = lc[x | (y <- conflicts, x <- y.left & y.right), string].deduplicate
+ let all = collect(newSeq):
+ for y in conflicts:
+ for x in (y.left & y.right):
+ x
all.map(c => (c, allOptions.filter(o => o.pair.long == c)
.map(o => o.pair).deduplicate)).toTable
@@ -259,14 +279,32 @@ proc checkConflicts*(args: seq[Argument],
let table = conflicts.obtainConflictsPairs
template full(s: string): OptionPair = table[s][0]
- lc[(c.left, w) | (c <- conflicts, args.check(c.left.full),
- w <- c.right, args.check(w.full)), (string, string)].optFirst
+ when NimVersion >= "1.3.5":
+ optFirst:
+ collect(newSeq):
+ for c in conflicts:
+ if args.check(c.left.full):
+ for w in c.right:
+ if args.check(w.full):
+ (c.left,w)
+ else:
+ optFirst:
+ var tmp = newSeq[(string,string)]()
+ for c in conflicts:
+ if args.check(c.left.full):
+ for w in c.right:
+ if args.check(w.full):
+ tmp.add((c.left,w))
+ tmp
proc pacmanParams*(color: bool, args: varargs[Argument]): seq[string] =
let colorStr = if color: "always" else: "never"
let argsSeq = ("color", some(colorStr), ArgumentType.long) &
@args.filter(arg => not arg.matchOption(%%%"color"))
- lc[x | (y <- argsSeq, x <- y.collectArg), string]
+ collect(newSeq):
+ for y in argsSeq:
+ for x in y.collectArg:
+ x
proc pacmanExecInternal(root: bool, params: varargs[string]): int =
let exec = if root: sudoPrefix & pacmanCmd & @params else: pacmanCmd & @params
@@ -283,7 +321,20 @@ proc pacmanRun*(root: bool, color: bool, args: varargs[Argument]): int =
proc pacmanValidateAndThrow(args: varargs[tuple[arg: Argument, pass: bool]]): void =
let argsSeq = @args
- let collectedArgs = lc[x | (y <- argsSeq, y.pass, x <- y.arg.collectArg), string]
+ when NimVersion >= "1.3.5":
+ let collectedArgs = collect(newSeq):
+ for y in argsSeq:
+ if y.pass:
+ for x in y.arg.collectArg:
+ x
+ else:
+ let collectedArgs = block:
+ var tmp = newSeq[string]()
+ for y in argsSeq:
+ if y.pass:
+ for x in y.arg.collectArg:
+ tmp.add(x)
+ tmp
let code = forkWait(() => pacmanExecInternal(false, "-T" & collectedArgs))
if code != 0:
raise haltError(code)
@@ -346,10 +397,14 @@ proc obtainPacmanConfig*(args: seq[Argument]): PacmanConfig =
let debug = args.check(%%%"debug")
let progressBar = not args.check(%%%"noprogressbar")
- let ignorePkgs = lc[x | (y <- getAll(%%%"ignore"),
- x <- y.split(',')), string].toHashSet
- let ignoreGroups = lc[x | (y <- getAll(%%%"ignoregroup"),
- x <- y.split(',')), string].toHashSet
+ let ignorePkgs = collect(initHashSet):
+ for y in getAll(%%%"ignore"):
+ for x in y.split(','):
+ {x}
+ let ignoreGroups = collect(initHashSet):
+ for y in getAll(%%%"ignoregroup"):
+ for x in y.split(','):
+ {x}
let hasKeyserver = forkWaitRedirect(() => (block:
if dropPrivileges():