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
cute-signatures
Natanael Copa 2012-05-07 08:54:41 +02:00
parent 9154b8b5e4
commit 08595072ae
1 changed files with 4 additions and 0 deletions

View File

@ -130,6 +130,10 @@ static void ver_print_package_status(struct ver_ctx *ictx, struct apk_database *
opstr = apk_version_op_string(r); opstr = apk_version_op_string(r);
if ((ictx->limchars != NULL) && (strchr(ictx->limchars, *opstr) == NULL)) if ((ictx->limchars != NULL) && (strchr(ictx->limchars, *opstr) == NULL))
return; return;
if (apk_verbosity <= 0) {
printf("%s\n", pkg->name->name);
return;
}
snprintf(pkgname, sizeof(pkgname), PKG_VER_FMT, snprintf(pkgname, sizeof(pkgname), PKG_VER_FMT,
PKG_VER_PRINTF(pkg)); PKG_VER_PRINTF(pkg));
printf("%-40s%s " BLOB_FMT, pkgname, opstr, BLOB_PRINTF(*latest)); printf("%-40s%s " BLOB_FMT, pkgname, opstr, BLOB_PRINTF(*latest));