Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
pkg -q == quiet
Baptiste Daroussin committed 14 years ago
commit 7b31c9983f7205e4d08a7bffd757d0fd0dbc1aa3
parent b68cafd
6 files changed +137 -103
modified pkg/delete.c
@@ -127,7 +127,8 @@ exec_delete(int argc, char **argv)
	/* check if we have something to deinstall */
	if (pkg_jobs_is_empty(jobs)) {
		if (argc == 0) {
-
			printf("Nothing to do\n");
+
			if (!quiet)
+
				printf("Nothing to do\n");
			retcode = EXIT_SUCCESS;
		} else {
			fprintf(stderr, "Package(s) not found\n");
@@ -145,25 +146,27 @@ exec_delete(int argc, char **argv)
	}

	pkg = NULL;
-
	printf("The following packages will be deinstalled:\n");
-
	while (pkg_jobs(jobs, &pkg) == EPKG_OK) {
-
		const char *name, *version;
+
	if (!quiet) {
+
		printf("The following packages will be deinstalled:\n");
+
		while (pkg_jobs(jobs, &pkg) == EPKG_OK) {
+
			const char *name, *version;

-
		pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version);
-
		printf("\t%s-%s\n", name, version);
-
	}
+
			pkg_get(pkg, PKG_NAME, &name, PKG_VERSION, &version);
+
			printf("\t%s-%s\n", name, version);
+
		}

-
	if (oldsize > newsize)
-
		printf("\nThe deinstallation will save %s\n", size);
-
	else if (newsize > oldsize)
-
		printf("\nThe deinstallation will require %s more space\n", size);
+
		if (oldsize > newsize)
+
			printf("\nThe deinstallation will save %s\n", size);
+
		else if (newsize > oldsize)
+
			printf("\nThe deinstallation will require %s more space\n", size);

-
	if (yes == false)
-
		pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes);
-
	if (yes == false)
-
		yes = query_yesno("\nProceed with deinstalling packages [y/N]: ");
+
		if (!yes)
+
			pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes);
+
		if (!yes)
+
			yes = query_yesno("\nProceed with deinstalling packages [y/N]: ");

-
	if (yes == true) {
+
	}
+
	if (yes) {
		if ((retcode = pkg_jobs_apply(jobs, force)) != EPKG_OK)
			goto cleanup;
	} else
modified pkg/event.c
@@ -48,7 +48,7 @@ event_callback(void *data, struct pkg_event *ev)
	struct pkg_dep *dep = NULL;
	const char *message;
	int *debug = data;
-
	(void)debug;
+
	(void) debug;
	const char *name, *version, *newversion;

	switch(ev->type) {
@@ -59,6 +59,8 @@ event_callback(void *data, struct pkg_event *ev)
		warnx("%s", ev->e_pkg_error.msg);
		break;
	case PKG_EVENT_FETCHING:
+
		if (quiet)
+
			break;
		if (fetched == 0) {
			strlcpy(url, ev->e_fetching.url, sizeof(url));
			start_progress_meter(url, ev->e_fetching.total, &fetched);
@@ -70,11 +72,15 @@ event_callback(void *data, struct pkg_event *ev)
		}
		break;
	case PKG_EVENT_INSTALL_BEGIN:
+
		if (quiet)
+
			break;
		pkg_get(ev->e_install_begin.pkg, PKG_NAME, &name, PKG_VERSION, &version);
		printf("Installing %s-%s...", name, version);
		fflush(stdout);
		break;
	case PKG_EVENT_INSTALL_FINISHED:
+
		if (quiet)
+
			break;
		printf(" done\n");
		pkg_get(ev->e_install_finished.pkg, PKG_MESSAGE, &message);
		if (message != NULL && message[0] != '\0') {
@@ -84,21 +90,31 @@ event_callback(void *data, struct pkg_event *ev)
		}
		break;
	case PKG_EVENT_INTEGRITYCHECK_BEGIN:
+
		if (quiet)
+
			break;
		printf("Checking integrity...");
		fflush(stdout);
		break;
	case PKG_EVENT_INTEGRITYCHECK_FINISHED:
+
		if (quiet)
+
			break;
		printf(" done\n");
		break;
	case PKG_EVENT_DEINSTALL_BEGIN:
+
		if (quiet)
+
			break;
		pkg_get(ev->e_deinstall_begin.pkg, PKG_NAME, &name, PKG_VERSION, &version);
		printf("Deinstalling %s-%s...", name, version);
		fflush(stdout);
		break;
	case PKG_EVENT_DEINSTALL_FINISHED:
+
		if (quiet)
+
			break;
		printf(" done\n");
		break;
	case PKG_EVENT_UPGRADE_BEGIN:
+
		if (quiet)
+
			break;
		pkg_get(ev->e_upgrade_finished.pkg, PKG_NAME, &name, PKG_VERSION, &version,
		    PKG_NEWVERSION, &newversion);
		switch (pkg_version_cmp(version, newversion)) {
@@ -115,6 +131,8 @@ event_callback(void *data, struct pkg_event *ev)
		fflush(stdout);
		break;
	case PKG_EVENT_UPGRADE_FINISHED:
+
		if (quiet)
+
			break;
		printf(" done\n");
		break;
	case PKG_EVENT_REQUIRED:
modified pkg/install.c
@@ -122,7 +122,8 @@ exec_install(int argc, char **argv)

	if (pkg_jobs_is_empty(jobs)) {
		if (argc == 0) {
-
			printf("Nothing to do\n");
+
			if (!quiet)
+
				printf("Nothing to do\n");
			retcode = EXIT_SUCCESS;
		} else {
			fprintf(stderr, "Package(s) not found in the repositories\n");
@@ -133,50 +134,52 @@ exec_install(int argc, char **argv)

	/* print a summary before applying the jobs */
	pkg = NULL;
-
	printf("The following packages will be installed:\n");
-

-
	while (pkg_jobs(jobs, &pkg) == EPKG_OK) {
-
		const char *name, *version, *newversion;
-
		int64_t flatsize, newflatsize, pkgsize;
-
		pkg_get(pkg, PKG_NEWVERSION, &newversion, PKG_NAME, &name,
-
		    PKG_VERSION, &version, PKG_FLATSIZE, &flatsize,
-
		    PKG_NEW_FLATSIZE, &newflatsize, PKG_NEW_PKGSIZE, &pkgsize);
-
		dlsize += pkgsize;
-
		if (newversion != NULL) {
-
			switch (pkg_version_cmp(version, newversion)) {
-
				case 1:
-
					printf("\tDowngrading %s: %s -> %s\n", name, version, newversion);
-
					break;
-
				case 0:
-
					printf("\tReinstalling %s-%s\n", name, version);
-
					break;
-
				case -1:
-
					printf("\tUpgrading %s: %s -> %s\n", name, version, newversion);
-
					break;
+
	if (!quiet) {
+
		printf("The following packages will be installed:\n");
+

+
		while (pkg_jobs(jobs, &pkg) == EPKG_OK) {
+
			const char *name, *version, *newversion;
+
			int64_t flatsize, newflatsize, pkgsize;
+
			pkg_get(pkg, PKG_NEWVERSION, &newversion, PKG_NAME, &name,
+
					PKG_VERSION, &version, PKG_FLATSIZE, &flatsize,
+
					PKG_NEW_FLATSIZE, &newflatsize, PKG_NEW_PKGSIZE, &pkgsize);
+
			dlsize += pkgsize;
+
			if (newversion != NULL) {
+
				switch (pkg_version_cmp(version, newversion)) {
+
					case 1:
+
						printf("\tDowngrading %s: %s -> %s\n", name, version, newversion);
+
						break;
+
					case 0:
+
						printf("\tReinstalling %s-%s\n", name, version);
+
						break;
+
					case -1:
+
						printf("\tUpgrading %s: %s -> %s\n", name, version, newversion);
+
						break;
+
				}
+
				oldsize += flatsize;
+
				newsize += newflatsize;
+
			} else {
+
				newsize += flatsize;
+
				printf("\tInstalling %s: %s\n", name, version);
			}
-
			oldsize += flatsize;
-
			newsize += newflatsize;
+
		}
+

+
		if (oldsize > newsize) {
+
			newsize *= -1;
+
			humanize_number(size, sizeof(size), oldsize - newsize, "B", HN_AUTOSCALE, 0);
+
			printf("\nthe installation will save %s\n", size);
		} else {
-
			newsize += flatsize;
-
			printf("\tInstalling %s: %s\n", name, version);
+
			humanize_number(size, sizeof(size), newsize - oldsize, "B", HN_AUTOSCALE, 0);
+
			printf("\nthe installation will require %s more space\n", size);
		}
-
	}
+
		humanize_number(size, sizeof(size), dlsize, "B", HN_AUTOSCALE, 0);
+
		printf("%s to be downloaded\n", size);

-
	if (oldsize > newsize) {
-
		newsize *= -1;
-
		humanize_number(size, sizeof(size), oldsize - newsize, "B", HN_AUTOSCALE, 0);
-
		printf("\nthe installation will save %s\n", size);
-
	} else {
-
		humanize_number(size, sizeof(size), newsize - oldsize, "B", HN_AUTOSCALE, 0);
-
		printf("\nthe installation will require %s more space\n", size);
+
		if (!yes)
+
			pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes);
+
		if (!yes)
+
			yes = query_yesno("\nProceed with installing packages [y/N]: ");
	}
-
	humanize_number(size, sizeof(size), dlsize, "B", HN_AUTOSCALE, 0);
-
	printf("%s to be downloaded\n", size);
-

-
	if (!yes)
-
		pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes);
-
	if (!yes)
-
		yes = query_yesno("\nProceed with installing packages [y/N]: ");

	if (yes)
		if (pkg_jobs_apply(jobs, 0) != EPKG_OK)
modified pkg/main.c
@@ -51,6 +51,7 @@
static void usage(void);
static void usage_help(void);
static int exec_help(int, char **);
+
bool quiet = false;

static struct commands {
	const char * const name;
@@ -89,6 +90,7 @@ usage(void)
{
	fprintf(stderr, "usage: pkg [-v] [-d] [-j <jail name or id>|-c <chroot path>] <command> [<args>]\n\n");
	fprintf(stderr, "Global options supported:\n");
+
	fprintf(stderr, "\t%-15s%s\n", "-q", "Quiet has much as possible");
	fprintf(stderr, "\t%-15s%s\n", "-d", "Increment debug level");
	fprintf(stderr, "\t%-15s%s\n", "-j", "Execute pkg(1) inside a jail(8)");
	fprintf(stderr, "\t%-15s%s\n", "-c", "Execute pkg(1) inside a chroot(8)");
@@ -156,14 +158,12 @@ main(int argc, char **argv)
	size_t len;
	signed char ch;
	int debug = 0;
-
	int ret = EX_USAGE;
+
	int ret = EXIT_SUCCESS;

	if (argc < 2)
		usage();

-
	pkg_event_register(&event_callback, &debug);
-

-
	while ((ch = getopt(argc, argv, "dj:c:v")) != -1) {
+
	while ((ch = getopt(argc, argv, "dj:c:vq")) != -1) {
		switch(ch) {
			case 'd':
				debug++;
@@ -178,6 +178,9 @@ main(int argc, char **argv)
				printf(PKGVERSION""GITHASH"\n");
				exit(EXIT_SUCCESS);
				break; /* NOT REACHED */
+
			case 'q':
+
				quiet = true;
+
				break;
			default:
				break;
		}
@@ -188,6 +191,8 @@ main(int argc, char **argv)
	if (argc == 0)
		usage();

+
	pkg_event_register(&event_callback, &debug);
+

	/* reset getopt for the next call */
	optreset = 1;
	optind = 1;
modified pkg/pkgcli.h
@@ -27,6 +27,8 @@
#ifndef _PKGCLI_H
#define _PKGCLI_H

+
extern bool quiet;
+

/* pkg add */
int exec_add(int, char **);
void usage_add(void);
modified pkg/upgrade.c
@@ -106,56 +106,59 @@ exec_upgrade(int argc, char **argv)
	pkgdb_it_free(it);

	if (pkg_jobs_is_empty(jobs)) {
-
		printf("Nothing to do\n");
-
		retcode = 0;
+
		if (!quiet)
+
			printf("Nothing to do\n");
+
		retcode = EXIT_SUCCESS;
		goto cleanup;
	}

-
	printf("The following packages will be upgraded: \n");
	pkg = NULL;
-
	while (pkg_jobs(jobs, &pkg) == EPKG_OK) {
-
		const char *newversion, *name, *version;
-
		int64_t newpkgsize, flatsize, newflatsize;
-

-
		pkg_get(pkg, PKG_NEWVERSION, &newversion, PKG_NAME, &name, PKG_VERSION, &version,
-
		    PKG_NEW_PKGSIZE, &newpkgsize, PKG_NEW_FLATSIZE, &newflatsize,
-
		    PKG_FLATSIZE, &flatsize);
-
		dlsize += newpkgsize;
-
		if (newversion != NULL) {
-
			switch (pkg_version_cmp(version, newversion)) {
-
				case 1:
-
					printf("\tDowngrading %s: %s -> %s\n", name, version, newversion);
-
					break;
-
				case 0:
-
					printf("\tReinstalling %s-%s\n", name, version);
-
					break;
-
				case -1:
-
					printf("\tUpgrading %s: %s -> %s\n", name, version, newversion);
-
					break;
+
	if (!quiet) {
+
		printf("The following packages will be upgraded: \n");
+
		while (pkg_jobs(jobs, &pkg) == EPKG_OK) {
+
			const char *newversion, *name, *version;
+
			int64_t newpkgsize, flatsize, newflatsize;
+

+
			pkg_get(pkg, PKG_NEWVERSION, &newversion, PKG_NAME, &name, PKG_VERSION, &version,
+
					PKG_NEW_PKGSIZE, &newpkgsize, PKG_NEW_FLATSIZE, &newflatsize,
+
					PKG_FLATSIZE, &flatsize);
+
			dlsize += newpkgsize;
+
			if (newversion != NULL) {
+
				switch (pkg_version_cmp(version, newversion)) {
+
					case 1:
+
						printf("\tDowngrading %s: %s -> %s\n", name, version, newversion);
+
						break;
+
					case 0:
+
						printf("\tReinstalling %s-%s\n", name, version);
+
						break;
+
					case -1:
+
						printf("\tUpgrading %s: %s -> %s\n", name, version, newversion);
+
						break;
+
				}
+
				oldsize += flatsize;
+
				newsize += newflatsize;
+
			} else {
+
				newsize += flatsize;
+
				printf("\tInstalling %s: %s\n", name, version);
			}
-
			oldsize += flatsize;
-
			newsize += newflatsize;
+
		}
+

+
		if (oldsize > newsize) {
+
			newsize *= -1;
+
			humanize_number(size, sizeof(size), oldsize - newsize, "B", HN_AUTOSCALE, 0);
+
			printf("\nthe upgrade will save %s\n", size);
		} else {
-
			newsize += flatsize;
-
			printf("\tInstalling %s: %s\n", name, version);
+
			humanize_number(size, sizeof(size), newsize - oldsize, "B", HN_AUTOSCALE, 0);
+
			printf("\nthe upgrade will require %s more space\n", size);
		}
-
	}
+
		humanize_number(size, sizeof(size), dlsize, "B", HN_AUTOSCALE, 0);
+
		printf("%s to be downloaded\n", size);

-
	if (oldsize > newsize) {
-
		newsize *= -1;
-
		humanize_number(size, sizeof(size), oldsize - newsize, "B", HN_AUTOSCALE, 0);
-
		printf("\nthe upgrade will save %s\n", size);
-
	} else {
-
		humanize_number(size, sizeof(size), newsize - oldsize, "B", HN_AUTOSCALE, 0);
-
		printf("\nthe upgrade will require %s more space\n", size);
+
		if (!yes)
+
			pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes);
+
		if (!yes)
+
			yes = query_yesno("\nProceed with upgrading packages [y/N]: ");
	}
-
	humanize_number(size, sizeof(size), dlsize, "B", HN_AUTOSCALE, 0);
-
	printf("%s to be downloaded\n", size);
-

-
	if (!yes)
-
		pkg_config_bool(PKG_CONFIG_ASSUME_ALWAYS_YES, &yes);
-
	if (!yes)
-
		yes = query_yesno("\nProceed with upgrading packages [y/N]: ");

	if (yes)
		if (pkg_jobs_apply(jobs, 0) != EPKG_OK)
@@ -166,7 +169,7 @@ exec_upgrade(int argc, char **argv)
		printf("%s", sbuf_data(messages));
	}

-
	retcode = 0;
+
	retcode = EXIT_SUCCESS;

	cleanup:
	pkg_jobs_free(jobs);