Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add dry-run mode to pkg install
Matthew Seaman committed 13 years ago
commit 83d49638160248c1427c4ab51f8cbbbf1f50cb2f
parent 23779c2
2 files changed +72 -53
modified pkg/install.c
@@ -44,7 +44,8 @@
void
usage_install(void)
{
-
	fprintf(stderr, "usage: pkg install [-r reponame] [-yqfgxXRL] <pkg-name> <...>\n\n");
+
	fprintf(stderr,
+
	    "usage: pkg install [-fgLnqRXxy] [-r reponame] <pkg-name> ...\n\n");
	fprintf(stderr, "For more information see 'pkg help install'.\n");
}

@@ -64,36 +65,40 @@ exec_install(int argc, char **argv)

	match_t match = MATCH_EXACT;
	bool force = false;
+
	bool dry_run = false;

-
	while ((ch = getopt(argc, argv, "yfgxXr:qLR")) != -1) {
+
	while ((ch = getopt(argc, argv, "fgLnqRr:Xxy")) != -1) {
		switch (ch) {
-
		case 'y':
-
			yes = true;
+
		case 'f':
+
			force = true;
			break;
		case 'g':
			match = MATCH_GLOB;
			break;
-
		case 'x':
-
			match = MATCH_REGEX;
-
			break;
-
		case 'X':
-
			match = MATCH_EREGEX;
-
			break;
-
		case 'r':
-
			reponame = optarg;
+
		case 'L':
+
			auto_update = false;
			break;
-
		case 'f':
-
			force = true;
+
		case 'n':
+
			dry_run = true;
			break;
		case 'q':
			quiet = true;
			break;
-
		case 'L':
-
			auto_update = false;
-
			break;
		case 'R':
			recursive = true;
			break;
+
		case 'r':
+
			reponame = optarg;
+
			break;
+
		case 'X':
+
			match = MATCH_EREGEX;
+
			break;
+
		case 'x':
+
			match = MATCH_REGEX;
+
			break;
+
		case 'y':
+
			yes = true;
+
			break;
		default:
			usage_install();
			return (EX_USAGE);
@@ -124,10 +129,12 @@ exec_install(int argc, char **argv)
		goto cleanup;
	}

-
	if ((it = pkgdb_query_installs(db, match, argc, argv, reponame, force, recursive)) == NULL)
+
	if ((it = pkgdb_query_installs(db, match, argc, argv, reponame,
+
	    force, recursive)) == NULL)
		goto cleanup;

-
	while (pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC|PKG_LOAD_DEPS) == EPKG_OK) {
+
	while (pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC|PKG_LOAD_DEPS) ==
+
	    EPKG_OK) {
		pkg_jobs_add(jobs, pkg);
		pkg = NULL;
	}
@@ -138,13 +145,17 @@ exec_install(int argc, char **argv)

	/* print a summary before applying the jobs */
	pkg = NULL;
-
	if (!quiet) {
-
		print_jobs_summary(jobs, PKG_JOBS_INSTALL, "The following packages will be installed:\n\n");
+
	if (!quiet || dry_run) {
+
		print_jobs_summary(jobs, PKG_JOBS_INSTALL,
+
		    "The following packages will be installed:\n\n");

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

	if (yes)
modified pkg/pkg-install.8
@@ -23,9 +23,9 @@
.Nd installs packages from remote package repositories
.Sh SYNOPSIS
.Nm
+
.Op Fl fgLnqRXxy
.Op Fl r Ar reponame
-
.Op Fl yqfgxXRL
-
.Ar <pkg-origin> <...>
+
.Ar <pkg-origin> ...
.Sh DESCRIPTION
.Nm
is used for installation of packages from a remote package
@@ -71,18 +71,22 @@ for finding the autoremoval status of a package, and
.Xr pkg-set 8
for modifying it.
.Pp
+
Currently
.Nm
-
can install packages from multiple repositories.
-
Repository catalogues will be downloaded from all listed repositories.
-
The order in which repositories are listed in
+
will only use one repository to install packages from.
+
When
+
.Ev PACKAGESITE
+
is set in the environment, or the equivalent
+
.Cm PACKAGESITE
+
setting is present in
.Fa pkg.conf
-
is significant.
-
If a package is found to exist in more than one repository, package
-
fetching will be attempted from each repository listed as containing
-
the package in the order specified in
-
.Fa pkg.conf ,
-
until either the package has been successfully downloaded or all
-
the repositories have been tried.
+
only that site will be used.
+
.Pp
+
Alternatively, when in multi-repo mode, the
+
.Fl r
+
option may be used to select one of the package repositories listed
+
in the configuration file.
+
Otherwise the default repository will be used.
.Pp
Multiple package repository support is only activated when neither the
environment variable
@@ -90,9 +94,6 @@ environment variable
nor the equivalent
.Cm PACKAGESITE
configuration setting are defined.
-
When
-
.Ev PACKAGESITE
-
is defined only the referenced repository will be used.
.Pp
Package repository catalogues will be automatically updated whenever
.Xr pkg-update 8
@@ -106,31 +107,38 @@ package installation with
The following options are supported by
.Nm :
.Bl -tag -width F1
-
.It Fl r Ar reponame
-
In multi-repo mode, override the
-
.Fa pkg.conf
-
ordering and only attempt to download packages from the named
-
repository.
-
.It Fl y
-
Assume yes when asked for confirmation before package installation.
-
.It Fl g
-
Treat the package names as shell glob patterns.
-
.It Fl x
-
Treat the package names as regular expressions.
-
.It Fl X
-
Treat the package names as extended regular expressions.
.It Fl f
Force the reinstallation of the package if already installed.
-
.It Fl q
-
Force quiet output.
+
.It Fl g
+
Treat the package names as shell glob patterns.
.It Fl L
Don't auto update repository catalogues with
.Xr pkg-update 8 .
Use the locally cached copies only.
+
.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, except when
+
.Fl n
+
is used, where
+
.Nm
+
will always show packages to be installed, upgraded or deleted.
.It Fl R
When used with
.Fl f ,
reinstalls any packages that require the given package.
+
.It Fl r Ar reponame
+
In multi-repo mode, override the
+
.Fa pkg.conf
+
ordering and only attempt to download packages from the named
+
repository.
+
.It Fl X
+
Treat the package names as extended regular expressions.
+
.It Fl x
+
Treat the package names as regular expressions.
+
.It Fl y
+
Assume yes when asked for confirmation before package installation.
.El
.Sh ENVIRONMENT
The following environment variables affect the execution of