aboutsummaryrefslogtreecommitdiffstats
path: root/main/apk-tools/0004-ver-make-quiet-output-suitable-for-scripting-piping.patch
blob: 36eb225cd447144522937d8eb30cfc4f9553d44c (plain)
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
30
31
32
33
34
35
36
37
From 08595072ae2156a399253d34b41748da99e84bfc Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Mon, 7 May 2012 08:54:41 +0200
Subject: [PATCH 4/5] ver: make --quiet output suitable for scripting/piping

Do not print version numbers or compare result char when in quiet
mode. This makes the output suitable for be used in scripts or pipes.

For example:

  # Upgrade all packages that matches a given regexp
  apk version --limit '<' --quiet | grep $regexp | apk fix --reinstall

  # Delete all packages that are removed from repository
  apk version --limit '?' --quiet | xargs apk del
---
 src/ver.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/ver.c b/src/ver.c
index 90b6cd6..05ffce9 100644
--- a/src/ver.c
+++ b/src/ver.c
@@ -130,6 +130,10 @@ static void ver_print_package_status(struct ver_ctx *ictx, struct apk_database *
 	opstr = apk_version_op_string(r);
 	if ((ictx->limchars != NULL) && (strchr(ictx->limchars, *opstr) == NULL))
 		return;
+	if (apk_verbosity <= 0) {
+		printf("%s\n", pkg->name->name);
+		return;
+	}
 	snprintf(pkgname, sizeof(pkgname), PKG_VER_FMT,
 		 PKG_VER_PRINTF(pkg));
 	printf("%-40s%s " BLOB_FMT, pkgname, opstr, BLOB_PRINTF(*latest));
-- 
1.7.10