Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add dry-run (-n) to pkg autoremove
Baptiste Daroussin committed 13 years ago
commit 025eb2514130c0154c834107bd172e1474f811fa
parent ab207d7
2 files changed +17 -7
modified pkg/autoremove.c
@@ -38,7 +38,7 @@
void
usage_autoremove(void)
{
-
	fprintf(stderr, "usage: pkg autoremove [-yq]\n\n");
+
	fprintf(stderr, "usage: pkg autoremove [-ynq]\n\n");
	fprintf(stderr, "For more information see 'pkg help autoremove'.\n");
}

@@ -55,8 +55,9 @@ exec_autoremove(int argc, char **argv)
	char size[7];
	int ch;
	bool yes = false;
+
	bool dry_run = false;

-
	while ((ch = getopt(argc, argv, "yq")) != -1) {
+
	while ((ch = getopt(argc, argv, "ynq")) != -1) {
		switch (ch) {
		case 'q':
			quiet = true;
@@ -64,6 +65,9 @@ exec_autoremove(int argc, char **argv)
		case 'y':
			yes = true;
			break;
+
		case 'n':
+
			dry_run = true;
+
			break;
		default:
			break;
		}
@@ -87,7 +91,7 @@ exec_autoremove(int argc, char **argv)
	}

	/* Always force packages to be removed */
-
	if (pkg_jobs_new(&jobs, PKG_JOBS_DEINSTALL, db, true, false)
+
	if (pkg_jobs_new(&jobs, PKG_JOBS_DEINSTALL, db, true, dry_run)
	    != EPKG_OK) {
		pkgdb_close(db);
		return (EX_IOERR);
@@ -120,7 +124,7 @@ exec_autoremove(int argc, char **argv)
	}

	pkg = NULL;
-
	if (!quiet) {
+
	if (!quiet || dry_run) {
		printf("Packages to be autoremoved: \n");
		while (pkg_jobs(jobs, &pkg) == EPKG_OK) {
			const char *name, *version;
@@ -135,8 +139,10 @@ exec_autoremove(int argc, char **argv)

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

	if (yes) {
modified pkg/pkg-autoremove.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd September 12, 2012
+
.Dd September 27, 2012
.Dt PKG-AUTOREMOVE 8
.Os
.Sh NAME
@@ -23,7 +23,7 @@
.Nd removes orphan packages
.Sh SYNOPSIS
.Nm
-
.Op Fl yq
+
.Op Fl ynq
.Sh DESCRIPTION
.Nm
is used for removing orphan packages, which were installed
@@ -34,6 +34,10 @@ The following options are supported by
.Bl -tag -width F1
.It Fl y
Assume yes when asked for confirmation before package autoremoval.
+
.It Fl n
+
Dry-run mode.
+
The list of changes to packages is always printed, but
+
no changes are actually made.
.It Fl q
Force quiet output
.El