Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add a '-q' option to pkg check. This increasingly mis-named "quiet mode" is more intended for scripting use than anything else, so no progress meters and frequently work entirely silently if no errors are encountered.
Matthew Seaman committed 11 years ago
commit 60222bf4225519da34d27b402fadae055d0b522a
parent c3475cd00abfd38b11d99fa64d910dfabe297059
1 file changed +42 -28
modified src/check.c
@@ -73,8 +73,11 @@ check_deps(struct pkgdb *db, struct pkg *p, struct deps_head *dh, bool noinstall
	while (pkg_deps(p, &dep) == EPKG_OK) {
		/* do we have a missing dependency? */
		if (pkg_is_installed(db, pkg_dep_origin(dep)) != EPKG_OK) {
-
			 printf("%s has a missing dependency: %s\n", origin,
-
                               pkg_dep_origin(dep));
+
			if (quiet) 
+
				printf("%s\t%s\n", origin, pkg_dep_origin(dep));
+
			else
+
				printf("%s has a missing dependency: %s\n",
+
				    origin, pkg_dep_origin(dep));
			if (!noinstall)
				add_missing_dep(dep, dh, &nbpkgs);
		}
@@ -232,7 +235,7 @@ check_summary(struct pkgdb *db, struct deps_head *dh)
void
usage_check(void)
{
-
	fprintf(stderr, "Usage: pkg check [-Bdsr] [-vy] [-a | -Cgix <pattern>]\n\n");
+
	fprintf(stderr, "Usage: pkg check [-Bdsr] [-qvy] [-a | -Cgix <pattern>]\n\n");
	fprintf(stderr, "For more information see 'pkg help check'.\n");
}

@@ -267,6 +270,7 @@ exec_check(int argc, char **argv)
		{ "recompute",		no_argument,	NULL,	'r' },
		{ "checksums",		no_argument,	NULL,	's' },
		{ "verbose",		no_argument,	NULL,	'v' },
+
		{ "quiet",              no_argument,    NULL,   'q' },
		{ "regex",		no_argument,	NULL,	'x' },
		{ "yes",		no_argument,	NULL,	'y' },
		{ NULL,			0,		NULL,	0   },
@@ -276,7 +280,7 @@ exec_check(int argc, char **argv)

	processed = 0;

-
	while ((ch = getopt_long(argc, argv, "+aBCdginrsvxy", longopts, NULL)) != -1) {
+
	while ((ch = getopt_long(argc, argv, "+aBCdginqrsvxy", longopts, NULL)) != -1) {
		switch (ch) {
		case 'a':
			match = MATCH_ALL;
@@ -301,6 +305,9 @@ exec_check(int argc, char **argv)
		case 'n':
			noinstall = true;
			break;
+
		case 'q':
+
			quiet = true;
+
			break;
		case 'r':
			recompute = true;
			flags |= PKG_LOAD_FILES;
@@ -341,7 +348,8 @@ exec_check(int argc, char **argv)
		ret = pkgdb_access(PKGDB_MODE_READ, PKGDB_DB_LOCAL);

	if (ret == EPKG_ENODB) {
-
		warnx("No packages installed.  Nothing to do!");
+
		if (!quiet)
+
			warnx("No packages installed.  Nothing to do!");
		return (EX_OK);
	} else if (ret == EPKG_ENOACCESS) {
		warnx("Insufficient privileges to access the package database");
@@ -374,12 +382,14 @@ exec_check(int argc, char **argv)
		if (msg == NULL)
			msg = sbuf_new_auto();
		if (!verbose) {
-
			if (match == MATCH_ALL)
-
				progressbar_start("Checking all packages");
-
			else {
-
				sbuf_printf(msg, "Checking %s", argv[i]);
-
				sbuf_finish(msg);
-
				progressbar_start(sbuf_data(msg));
+
			if (!quiet) {
+
				if (match == MATCH_ALL)
+
					progressbar_start("Checking all packages");
+
				else {
+
					sbuf_printf(msg, "Checking %s", argv[i]);
+
					sbuf_finish(msg);
+
					progressbar_start(sbuf_data(msg));
+
				}
			}
			processed = 0;
			total = pkgdb_it_count(it);
@@ -391,19 +401,21 @@ exec_check(int argc, char **argv)
		}

		while (pkgdb_it_next(it, &pkg, flags) == EPKG_OK) {
-
			if (!verbose)
-
				progressbar_tick(processed, total);
-
			else {
-
				++nbdone;
-
				job_status_begin(msg);
-
				pkg_sbuf_printf(msg, "Checking %n-%v:",
-
				    pkg, pkg);
-
				sbuf_flush(msg);
+
			if (!quiet) {
+
				if (!verbose)
+
					progressbar_tick(processed, total);
+
				else {
+
					++nbdone;
+
					job_status_begin(msg);
+
					pkg_sbuf_printf(msg, "Checking %n-%v:",
+
					    pkg, pkg);
+
					sbuf_flush(msg);
+
				}
			}

			/* check for missing dependencies */
			if (dcheck) {
-
				if (verbose)
+
				if (!quiet && verbose)
					printf(" dependencies...");
				nbpkgs += check_deps(db, pkg, &dh, noinstall);
				if (noinstall && nbpkgs > 0) {
@@ -411,7 +423,7 @@ exec_check(int argc, char **argv)
				}
			}
			if (checksums) {
-
				if (verbose)
+
				if (!quiet && verbose)
					printf(" checksums...");
				if (pkg_test_filesum(pkg) != EPKG_OK) {
					rc = EX_DATAERR;
@@ -420,7 +432,7 @@ exec_check(int argc, char **argv)
			if (recompute) {
				if (pkgdb_upgrade_lock(db, PKGDB_LOCK_ADVISORY,
						PKGDB_LOCK_EXCLUSIVE) == EPKG_OK) {
-
					if (verbose)
+
					if (!quiet && verbose)
						printf(" recomputing...");
					if (pkg_recompute(db, pkg) != EPKG_OK) {
						rc = EX_DATAERR;
@@ -436,7 +448,7 @@ exec_check(int argc, char **argv)
			if (reanalyse_shlibs) {
				if (pkgdb_upgrade_lock(db, PKGDB_LOCK_ADVISORY,
						PKGDB_LOCK_EXCLUSIVE) == EPKG_OK) {
-
					if (verbose)
+
					if (!quiet && verbose)
						printf(" shared libraries...");
					if (pkgdb_reanalyse_shlibs(db, pkg) != EPKG_OK) {
						pkg_fprintf(stderr, "Failed to "
@@ -453,12 +465,14 @@ exec_check(int argc, char **argv)
				}
			}

-
			if (!verbose)
-
				++processed;
-
			else
-
				printf(" done\n");
+
			if (!quiet) {
+
				if (!verbose)
+
					++processed;
+
				else
+
					printf(" done\n");
+
			}
		}
-
		if (!verbose)
+
		if (!quiet && !verbose)
			progressbar_tick(processed, total);
		if (msg != NULL) {
			sbuf_delete(msg);