Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add a dry-run option to pkg upgrade.
Matthew Seaman committed 13 years ago
commit 70891ed53385f619e223efa2dc0037d6673bc58e
parent 5fde840
2 files changed +42 -20
modified pkg/pkg-upgrade.8
@@ -23,14 +23,20 @@
.Nd performs upgrades of package software distributions
.Sh SYNOPSIS
.Nm
-
.Op Fl yfqL
+
.Op Fl fLnqy
+
.Op Fl r reponame
.Sh DESCRIPTION
.Nm
is used for upgrading of package software distributions.
.Pp
-
Currently only one package repository can be
-
used during package upgrades as defined by the environment variable
-
.Ev PACKAGESITE .
+
Currently only one package repository can be used during package
+
upgrades.
+
This is either as defined by the environment variable
+
.Ev PACKAGESITE ,
+
or when in multi-repos mode, either the default repository or the
+
argument to the
+
.Fl r
+
option.
.Pp
Soon enough
.Nm
@@ -45,16 +51,26 @@ flag.
The following options are supported by
.Nm :
.Bl -tag -width F1
-
.It Fl y
-
Assume yes when asked for confirmation before package installation.
.It Fl f
Force reinstalling/upgrading the whole set of packages
-
.It Fl q
-
Force quiet output
.It Fl L
Don't auto update the remote database with
.Xr pkg-update 8 .
Use the local cache only.
+
.It Fl n
+
Dry-run mode: show what packages have updates available, but do not perform
+
any upgrades.
+
Repository catalogues will be updated as usual unless the
+
.Fl L
+
option is also given.
+
.It Fl q
+
Force quiet output, except when
+
.Fl n
+
is used, where
+
.Nm
+
will always print out the list of packages with available updates.
+
.It Fl y
+
Assume yes when asked for confirmation before package installation.
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of
modified pkg/upgrade.c
@@ -37,7 +37,7 @@
void
usage_upgrade(void)
{
-
	fprintf(stderr, "usage: pkg upgrade [-r reponame] [-yfqL]\n\n");
+
	fprintf(stderr, "usage: pkg upgrade [-fLnqy] [-r reponame]\n\n");
	fprintf(stderr, "For more information see 'pkg help upgrade'.\n");
}

@@ -53,6 +53,7 @@ exec_upgrade(int argc, char **argv)
	int ch;
	bool yes = false;
	bool all = false;
+
	bool dry_run = false;
	bool auto_update = true;

	if (geteuid() != 0) {
@@ -60,22 +61,25 @@ exec_upgrade(int argc, char **argv)
		return (EX_NOPERM);
	}

-
	while ((ch = getopt(argc, argv, "yr:fqL")) != -1) {
+
	while ((ch = getopt(argc, argv, "fLnqr:y")) != -1) {
		switch (ch) {
-
		case 'y':
-
			yes = true;
+
		case 'f':
+
			all = true;
			break;
-
		case 'r':
-
			reponame = optarg;
+
		case 'L':
+
			auto_update = false;
+
			break;
+
		case 'n':
+
			dry_run = true;
			break;
		case 'q':
			quiet = true;
			break;
-
		case 'f':
-
			all = true;
+
		case 'r':
+
			reponame = optarg;
			break;
-
		case 'L':
-
			auto_update = false;
+
		case 'y':
+
			yes = true;
			break;
		default:
			usage_upgrade();
@@ -121,13 +125,15 @@ exec_upgrade(int argc, char **argv)
	}

	pkg = NULL;
-
	if (!quiet) {
+
	if (!quiet || dry_run) {
		print_jobs_summary(jobs, PKG_JOBS_INSTALL, "The following packages will be upgraded:\n\n");

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

	if (yes)