From cf2f775cf7d9188c05f52f205f029afdc810feca Mon Sep 17 00:00:00 2001 From: Paul Mabileau Date: Sat, 16 Mar 2024 17:24:51 +0100 Subject: [PATCH 1/5] Feat(install/cli): Add new gated --dry-run option Signed-off-by: Paul Mabileau --- src/bin/cargo/commands/install.rs | 10 +++ .../cargo_install/help/stdout.term.svg | 78 ++++++++++--------- 2 files changed, 51 insertions(+), 37 deletions(-) diff --git a/src/bin/cargo/commands/install.rs b/src/bin/cargo/commands/install.rs index e188d6a0d67..8a6ba681522 100644 --- a/src/bin/cargo/commands/install.rs +++ b/src/bin/cargo/commands/install.rs @@ -74,6 +74,13 @@ pub fn cli() -> Command { "list", "List all installed packages and their versions", )) + .arg( + flag( + "dry-run", + "Display what would be installed without actually performing anything (unstable)", + ) + .short('n'), + ) .arg_ignore_rust_version() .arg_message_format() .arg_silent_suggestion() @@ -201,6 +208,9 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult { if args.flag("list") { ops::install_list(root, gctx)?; } else { + if args.flag("dry-run") { + gctx.cli_unstable().fail_if_stable_opt("--dry-run", 11123)?; + } ops::install( gctx, root, diff --git a/tests/testsuite/cargo_install/help/stdout.term.svg b/tests/testsuite/cargo_install/help/stdout.term.svg index 5fac4877432..ccd06b44bae 100644 --- a/tests/testsuite/cargo_install/help/stdout.term.svg +++ b/tests/testsuite/cargo_install/help/stdout.term.svg @@ -1,4 +1,4 @@ - +
-n
+
--dry-run
+
(unstable) Cut the install operation short and display what it would have +usually done. The normal version check and crate downloads still occur exactly +like without the option flag, but the compilation and the actual installation +do not. Only the operation that would have been performed is displayed for each +requested package, one of:

+
    +
  • fresh install if the package is not installed yet,
  • +
  • upgrade if it is already installed but a newer version exists,
  • +
  • downgrade if it is already installed but an older version has been +explicitely requested,
  • +
  • nothing if it is already installed and up-to-date,
  • +
  • re-install if it is already installed and up-to-date but --force was set.
  • +
+ +
--bin name
Install only the specified binary.
diff --git a/src/etc/man/cargo-install.1 b/src/etc/man/cargo-install.1 index 44de0a8053a..cd066b54649 100644 --- a/src/etc/man/cargo-install.1 +++ b/src/etc/man/cargo-install.1 @@ -170,6 +170,37 @@ protect against multiple concurrent invocations of Cargo installing at the same time. .RE .sp +\fB\-n\fR, +\fB\-\-dry\-run\fR +.RS 4 +(unstable) Cut the install operation short and display what it \fIwould\fR have +usually done. The normal version check and crate downloads still occur exactly +like without the option flag, but the compilation and the actual installation +do not. Only the operation that would have been performed is displayed for each +requested package, one of: +.sp +.RS 4 +\h'-04'\(bu\h'+02'fresh install if the package is not installed yet, +.RE +.sp +.RS 4 +\h'-04'\(bu\h'+02'upgrade if it is already installed but a newer version exists, +.RE +.sp +.RS 4 +\h'-04'\(bu\h'+02'downgrade if it is already installed but an older version has been +explicitely requested, +.RE +.sp +.RS 4 +\h'-04'\(bu\h'+02'nothing if it is already installed and up\-to\-date, +.RE +.sp +.RS 4 +\h'-04'\(bu\h'+02're\-install if it is already installed and up\-to\-date but \fB\-\-force\fR was set. +.RE +.RE +.sp \fB\-\-bin\fR \fIname\fR\[u2026] .RS 4 Install only the specified binary.