Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add dry-run mode to pkg delete
Matthew Seaman committed 13 years ago
commit 3a140da61aae3a5e6e4725307c5a80f749e5420d
parent 83d4963
2 files changed +67 -34
modified pkg/delete.c
@@ -39,8 +39,8 @@
void
usage_delete(void)
{
-
	fprintf(stderr, "usage: pkg delete [-yqgxXfr] <pkg-name> <...>\n");
-
	fprintf(stderr, "       pkg delete [-yq] -a\n\n");
+
	fprintf(stderr, "usage: pkg delete [-fgnqRXxy] <pkg-name> ...\n");
+
	fprintf(stderr, "       pkg delete [-nqy] -a\n\n");
	fprintf(stderr, "For more information see 'pkg help delete'.\n");
}

@@ -56,35 +56,39 @@ exec_delete(int argc, char **argv)
	int flags = PKG_LOAD_BASIC;
	int force = 0;
	bool yes = false;
+
	bool dry_run = false;
	int retcode = EX_SOFTWARE;
	int recursive = 0;

-
	while ((ch = getopt(argc, argv, "aqgxXfyR")) != -1) {
+
	while ((ch = getopt(argc, argv, "afgnqRXxy")) != -1) {
		switch (ch) {
		case 'a':
			match = MATCH_ALL;
			break;
+
		case 'f':
+
			force = 1;
+
			break;
		case 'g':
			match = MATCH_GLOB;
			break;
-
		case 'x':
-
			match = MATCH_REGEX;
+
		case 'n':
+
			dry_run = true;
+
			break;
+
		case 'q':
+
			quiet = true;
+
			break;
+
		case 'R':
+
			recursive = 1;
			break;
		case 'X':
			match = MATCH_EREGEX;
			break;
-
		case 'f':
-
			force = 1;
-
			break;
-
		case 'q':
-
			quiet = true;
+
		case 'x':
+
			match = MATCH_REGEX;
			break;
		case 'y':
			yes = true;
			break;
-
		case 'R':
-
			recursive = 1;
-
			break;
		default:
			usage_delete();
			return (EX_USAGE);
@@ -135,14 +139,17 @@ exec_delete(int argc, char **argv)
	}

	pkg = NULL;
-
	if (!quiet) {
-
		print_jobs_summary(jobs, PKG_JOBS_DEINSTALL, "The following packages will be deinstalled:\n\n");
+
	if (!quiet || dry_run) {
+
		print_jobs_summary(jobs, PKG_JOBS_DEINSTALL,
+
		    "The following packages will be deinstalled:\n\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 && !dry_run)
+
			yes = query_yesno(
+
		            "\nProceed with deinstalling packages [y/N]: ");
+
		if (dry_run)
+
			yes = false;
	}
	if (yes) {
		if ((retcode = pkg_jobs_apply(jobs, force)) != EPKG_OK)
modified pkg/pkg-delete.8
@@ -20,37 +20,63 @@
.Os
.Sh NAME
.Nm "pkg delete"
-
.Nd deletes a package from the database and the system
+
.Nd deletes packages from the database and the system
.Sh SYNOPSIS
.Nm
-
.Op Fl ay
+
.Op Fl fgnqRXxy
+
.Ar <pkg-name> ...
.Nm
-
.Op Fl yqfRgxX
-
.Ar <pkg-name> <...>
+
.Op Fl nqy
+
.Fl a
.Sh DESCRIPTION
.Nm
-
is used for deleting previously installed packages and removes them from the
-
database.
+
is used for deleting installed packages from the system.
+
.Nm
+
creates a work-list of all the installed packages matching the package
+
names on the command line.
+
The list is presented to the user.
+
If the user confirms that they do want to remove those packages, or
+
if the
+
.Cm ASSUME_ALWAYS_YES
+
consifuration option is set,
+
.Nm
+
proceeds to remove the listed packages.
+
.Pp
+
If the set of packages to be deleted would leave installed packages
+
with unfulfilled dependencies,
+
.Nm
+
will emit an error message and quit without deleting anything unless
+
forced to proceed by the
+
.Fl f
+
option.
.Sh OPTIONS
The following options are supported by
.Nm :
.Bl -tag -width F1
-
.It Fl f
-
Forces packages to be removed.
.It Fl a
-
Deletes all installed packages from the system and the database.
-
.It Fl y
-
Assume yes when asked for confirmation before package deletion.
+
Deletes all installed packages from the system and empties the database.
+
.It Fl f
+
Forces packages to be removed despite leaving unresolved dependencies.
.It Fl g
Treat the package names as shell glob patterns.
+
.It Fl n
+
Dry run mode.
+
The list of packages to delete is always printed, but no packages are
+
actually deleted.
+
.It Fl q
+
Force quiet output, except where
+
.Fl n
+
is also used, when
+
.Nm
+
will show the list of packages to be deleted.
.It Fl R
-
Recursively delete all packages that depend on the deleted package as well.
-
.It Fl x
-
Treat the package names as regular expressions.
+
Delete all packages that require the listed packages as well.
.It Fl X
Treat the package names as extended regular expressions.
-
.It Fl q
-
Force quiet output
+
.It Fl x
+
Treat the package names as regular expressions.
+
.It Fl y
+
Assume yes when asked for confirmation before package deletion.
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of