diff options
Diffstat (limited to 'src/pacman.nim')
-rw-r--r-- | src/pacman.nim | 121 |
1 files changed, 43 insertions, 78 deletions
diff --git a/src/pacman.nim b/src/pacman.nim index f9fc978..ed80311 100644 --- a/src/pacman.nim +++ b/src/pacman.nim @@ -36,13 +36,10 @@ proc calculateOptionsWithParameter(opts: seq[CommandOption]): seq[OptionKey] {.c else: @[] - when NimVersion >= "1.2": - collect(newSeq): - for y in opts: - for x in commandToSeq(y): - x - 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, {}) @@ -206,13 +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 - when NimVersion >= "1.2": - let optsPairSeq = collect(newSeq): - for y in optsSeq: - for x in y: - x.pair - else: - 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)) @@ -246,45 +240,30 @@ proc filterExtensions*(args: seq[Argument], removeMatches: bool, keepTargets: bo opts: varargs[seq[CommandOption]]): seq[Argument] = let optsSeq = @opts let optsFilter = if removeMatches: - when NimVersion >= "1.2": - collect(newSeq): - for y in optsSeq: - for x in y: - x - else: - lc[x | (y <- optsSeq, x <- y), CommandOption] + collect(newSeq): + for y in optsSeq: + for x in y: + x else: (block: - when NimVersion >= "1.2": - 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 - else: - let pairs = lc[x.pair | (y <- optsSeq, x <- y), OptionPair].toHashSet - lc[x | (x <- allOptions, not (x.pair in pairs)), CommandOption] + 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 ) - - when NimVersion >= "1.2": - let argsSeq = collect(newSeq): - for x in optsFilter: - if x.extension: - x.pair - else: - let argsSeq = lc[x.pair | (x <- optsFilter, x.extension), OptionPair] - args.filter(removeMatches, keepTargets, argsSeq) - + 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]] = - when NimVersion >= "1.2": - let all = collect(newSeq): - for y in conflicts: - for x in (y.left & y.right): - x - else: - 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 @@ -308,7 +287,7 @@ proc checkConflicts*(args: seq[Argument], for w in c.right: if args.check(w.full): (c.left,w) - elif NimVersion >= "1.2": + else: optFirst: var tmp = newSeq[(string,string)]() for c in conflicts: @@ -317,21 +296,15 @@ proc checkConflicts*(args: seq[Argument], if args.check(w.full): tmp.add((c.left,w)) tmp - else: - lc[(c.left, w) | (c <- conflicts, args.check(c.left.full), - w <- c.right, args.check(w.full)), (string, string)].optFirst 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")) - when NimVersion >= "1.2": - collect(newSeq): - for y in argsSeq: - for x in y.collectArg: - x - else: - 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 @@ -354,7 +327,7 @@ proc pacmanValidateAndThrow(args: varargs[tuple[arg: Argument, pass: bool]]): vo if y.pass: for x in y.arg.collectArg: x - elif NimVersion >= "1.2": + else: let collectedArgs = block: var tmp = newSeq[string]() for y in argsSeq: @@ -362,8 +335,6 @@ proc pacmanValidateAndThrow(args: varargs[tuple[arg: Argument, pass: bool]]): vo for x in y.arg.collectArg: tmp.add(x) tmp - else: - let collectedArgs = lc[x | (y <- argsSeq, y.pass, x <- y.arg.collectArg), string] let code = forkWait(() => pacmanExecInternal(false, "-T" & collectedArgs)) if code != 0: raise haltError(code) @@ -426,20 +397,14 @@ proc obtainPacmanConfig*(args: seq[Argument]): PacmanConfig = let debug = args.check(%%%"debug") let progressBar = not args.check(%%%"noprogressbar") - when NimVersion >= "1.2": - 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} - else: - 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(): |