diff --git a/src/bin/cargo/commands/clean.rs b/src/bin/cargo/commands/clean.rs index ec2879749ef..a9dfab8d5ef 100644 --- a/src/bin/cargo/commands/clean.rs +++ b/src/bin/cargo/commands/clean.rs @@ -7,6 +7,7 @@ use cargo::ops::CleanContext; use cargo::ops::{self, CleanOptions}; use cargo::util::print_available_packages; use clap_complete::ArgValueCandidates; +use indexmap::IndexSet; use std::time::Duration; pub fn cli() -> Command { @@ -18,6 +19,10 @@ pub fn cli() -> Command { "Package to clean artifacts for", ArgValueCandidates::new(get_pkg_name_candidates), ) + .arg( + flag("workspace", "Clean artifacts of the workspace members") + .help_heading(heading::PACKAGE_SELECTION), + ) .arg_release("Whether or not to clean release artifacts") .arg_profile("Clean artifacts of the specified profile") .arg_target_triple("Target triple to clean output for") @@ -146,10 +151,14 @@ pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult { if args.is_present_with_zero_values("package") { print_available_packages(&ws)?; } + let mut spec = IndexSet::from_iter(values(args, "package")); + if args.flag("workspace") { + spec.extend(ws.members().map(|package| package.name().to_string())) + }; let opts = CleanOptions { gctx, - spec: values(args, "package"), + spec, targets: args.targets()?, requested_profile: args.get_profile_name("dev", ProfileChecking::Custom)?, profile_specified: args.contains_id("profile") || args.flag("release"), diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index a70972fae1b..767726562f2 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -9,6 +9,7 @@ use crate::util::interning::InternedString; use crate::util::{GlobalContext, Progress, ProgressStyle}; use anyhow::bail; use cargo_util::paths; +use indexmap::IndexSet; use std::collections::{HashMap, HashSet}; use std::fs; use std::path::{Path, PathBuf}; @@ -17,7 +18,7 @@ use std::rc::Rc; pub struct CleanOptions<'gctx> { pub gctx: &'gctx GlobalContext, /// A list of packages to clean. If empty, everything is cleaned. - pub spec: Vec, + pub spec: IndexSet, /// The target arch triple to clean, or None for the host arch pub targets: Vec, /// Whether to clean the release directory @@ -108,7 +109,7 @@ fn clean_specs( ws: &Workspace<'_>, profiles: &Profiles, targets: &[String], - spec: &[String], + spec: &IndexSet, dry_run: bool, ) -> CargoResult<()> { // Clean specific packages. diff --git a/src/doc/man/cargo-clean.md b/src/doc/man/cargo-clean.md index bc8fdc2ba5d..d5c5b6c7cfd 100644 --- a/src/doc/man/cargo-clean.md +++ b/src/doc/man/cargo-clean.md @@ -26,10 +26,16 @@ When no packages are selected, all packages and all dependencies in the workspace are cleaned. {{#options}} + {{#option "`-p` _spec_..." "`--package` _spec_..." }} Clean only the specified packages. This flag may be specified multiple times. See {{man "cargo-pkgid" 1}} for the SPEC format. {{/option}} + +{{#option "`--workspace`" }} +Clean artifacts of the workspace members. +{{/option}} + {{/options}} ### Clean Options diff --git a/src/doc/man/generated_txt/cargo-clean.txt b/src/doc/man/generated_txt/cargo-clean.txt index a81fb9095fc..b90b983129e 100644 --- a/src/doc/man/generated_txt/cargo-clean.txt +++ b/src/doc/man/generated_txt/cargo-clean.txt @@ -21,6 +21,9 @@ OPTIONS Clean only the specified packages. This flag may be specified multiple times. See cargo-pkgid(1) for the SPEC format. + --workspace + Clean artifacts of the workspace members. + Clean Options --dry-run Displays a summary of what would be deleted without deleting diff --git a/src/doc/src/commands/cargo-clean.md b/src/doc/src/commands/cargo-clean.md index e1e91e8c389..274b82a7347 100644 --- a/src/doc/src/commands/cargo-clean.md +++ b/src/doc/src/commands/cargo-clean.md @@ -22,12 +22,19 @@ When no packages are selected, all packages and all dependencies in the workspace are cleaned.
+
-p spec
--package spec

Clean only the specified packages. This flag may be specified multiple times. See cargo-pkgid(1) for the SPEC format.

+ +
--workspace
+

Clean artifacts of the workspace members.

+
+ +
### Clean Options diff --git a/src/etc/man/cargo-clean.1 b/src/etc/man/cargo-clean.1 index 60edaebe37b..f380f1582d3 100644 --- a/src/etc/man/cargo-clean.1 +++ b/src/etc/man/cargo-clean.1 @@ -23,6 +23,11 @@ workspace are cleaned. Clean only the specified packages. This flag may be specified multiple times. See \fBcargo\-pkgid\fR(1) for the SPEC format. .RE +.sp +\fB\-\-workspace\fR +.RS 4 +Clean artifacts of the workspace members. +.RE .SS "Clean Options" .sp \fB\-\-dry\-run\fR diff --git a/tests/testsuite/cargo_clean/help/stdout.term.svg b/tests/testsuite/cargo_clean/help/stdout.term.svg index e51b7707b43..65a13758063 100644 --- a/tests/testsuite/cargo_clean/help/stdout.term.svg +++ b/tests/testsuite/cargo_clean/help/stdout.term.svg @@ -1,7 +1,7 @@ - +