aboutsummaryrefslogtreecommitdiff
path: root/src/feature/localquery.nim
blob: f8436cde032471d224cd33678f4635f41d7713d4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import
  algorithm, future, options, sequtils, sets, strutils, tables,
  "../args", "../common", "../config", "../format", "../package", "../pacman", "../utils",
  "../wrapper/alpm"

proc handleQueryOrphans*(args: seq[Argument], config: Config): int =
  let (installed, orphans, _) = withAlpmConfig(config, false, handle, dbs, errors):
    for e in errors: printError(config.color, e)
    queryUnrequired(handle, true, false, initSet[string]())

  let targets = args.targets.map(t => (if t[0 .. 5] == "local/": t[6 .. ^1] else: t))

  # Provide similar output for not installed packages
  let unknownTargets = targets.toSet - installed
  let results = if targets.len > 0:
      targets.filter(t => t in orphans or t in unknownTargets)
    else:
      toSeq(orphans.items).sorted(cmp)

  if results.len > 0:
    let newArgs = args.filter(arg => not arg.isTarget and
      not arg.matchOption(%%%"unrequired") and
      not arg.matchOption(%%%"deps")) &
      results.map(r => (r, none(string), ArgumentType.target))
    pacmanExec(false, config.color, newArgs)
  elif targets.len == 0:
    0
  else:
    1