aboutsummaryrefslogtreecommitdiff
path: root/src/feature/syncsearch.nim
diff options
context:
space:
mode:
authorkitsunyan2018-06-02 12:18:38 +0000
committerkitsunyan2018-06-02 12:18:38 +0000
commit1b3cca2815e8d8c3aa3fa11ed6cdccd7eae0421e (patch)
treeb38ef720bde5279c1cec47844e5cada3003970f4 /src/feature/syncsearch.nim
parent3d420e1b546c5636e38653cb21d5dc0f4306a30a (diff)
Abort sync operation if "--refresh" fails
Diffstat (limited to 'src/feature/syncsearch.nim')
-rw-r--r--src/feature/syncsearch.nim78
1 files changed, 40 insertions, 38 deletions
diff --git a/src/feature/syncsearch.nim b/src/feature/syncsearch.nim
index 4d0eb50..0b1aeae 100644
--- a/src/feature/syncsearch.nim
+++ b/src/feature/syncsearch.nim
@@ -5,49 +5,51 @@ import
"../wrapper/alpm"
proc handleSyncSearch*(args: seq[Argument], config: Config): int =
- let (_, callArgs) = checkAndRefresh(config.color, args)
-
- let quiet = args.check(%%%"quiet")
-
- let (aurPackages, aerrors) = findAurPackages(args.targets)
- for e in aerrors: printError(config.color, e)
+ let (refreshCode, callArgs) = checkAndRefresh(config.color, args)
+ if refreshCode != 0:
+ refreshCode
+ else:
+ let quiet = args.check(%%%"quiet")
- type Package = tuple[rpcInfo: RpcPackageInfo, installedVersion: Option[string]]
+ let (aurPackages, aerrors) = findAurPackages(args.targets)
+ for e in aerrors: printError(config.color, e)
- proc checkLocalPackages: seq[Package] =
- if quiet:
- aurPackages.map(pkg => (pkg, none(string)))
- elif aurPackages.len > 0:
- withAlpmConfig(config, false, handle, dbs, errors):
- for e in errors: printError(config.color, e)
+ type Package = tuple[rpcInfo: RpcPackageInfo, installedVersion: Option[string]]
- aurPackages.map(proc (rpcInfo: RpcPackageInfo): Package =
- let pkg = handle.local[rpcInfo.name]
- if pkg != nil:
- (rpcInfo, some($pkg.version))
- else:
- (rpcInfo, none(string)))
- else:
- @[]
+ proc checkLocalPackages: seq[Package] =
+ if quiet:
+ aurPackages.map(pkg => (pkg, none(string)))
+ elif aurPackages.len > 0:
+ withAlpmConfig(config, false, handle, dbs, errors):
+ for e in errors: printError(config.color, e)
+
+ aurPackages.map(proc (rpcInfo: RpcPackageInfo): Package =
+ let pkg = handle.local[rpcInfo.name]
+ if pkg != nil:
+ (rpcInfo, some($pkg.version))
+ else:
+ (rpcInfo, none(string)))
+ else:
+ @[]
- let pkgs = checkLocalPackages()
- .sorted((a, b) => cmp(a.rpcInfo.name, b.rpcInfo.name))
+ let pkgs = checkLocalPackages()
+ .sorted((a, b) => cmp(a.rpcInfo.name, b.rpcInfo.name))
- var code = min(aerrors.len, 1)
- if pkgs.len == 0:
- if code == 0:
- pacmanExec(false, config.color, callArgs)
+ var code = min(aerrors.len, 1)
+ if pkgs.len == 0:
+ if code == 0:
+ pacmanExec(false, config.color, callArgs)
+ else:
+ discard pacmanRun(false, config.color, callArgs)
+ code
else:
discard pacmanRun(false, config.color, callArgs)
- code
- else:
- discard pacmanRun(false, config.color, callArgs)
- for pkg in pkgs:
- if quiet:
- echo(pkg.rpcInfo.name)
- else:
- printPackageSearch(config.color, "aur", pkg.rpcInfo.name,
- pkg.rpcInfo.version, pkg.installedVersion, pkg.rpcInfo.description,
- some(formatPkgRating(pkg.rpcInfo.votes, pkg.rpcInfo.popularity)))
- 0
+ for pkg in pkgs:
+ if quiet:
+ echo(pkg.rpcInfo.name)
+ else:
+ printPackageSearch(config.color, "aur", pkg.rpcInfo.name,
+ pkg.rpcInfo.version, pkg.installedVersion, pkg.rpcInfo.description,
+ some(formatPkgRating(pkg.rpcInfo.votes, pkg.rpcInfo.popularity)))
+ 0