Skip to content

Commit 2cbbf6e

Browse files
committed
Auto merge of #12959 - ehuss:quiet-global, r=epage
Fix --quiet being used with nested subcommands. This fixes an issue where `--quiet` doesn't work with commands that have subcommands. This is because `config_configure` only looks at the global and top-level subcommand, and not deeper subcommands. The issue was that `--quiet` was not defined as a global flag. This was changed in #6358 in order to give a better help message for `cargo test --quiet`. I don't remember if clap just didn't support overriding at the time, or if we just didn't know how it worked. Anyways, it seems to work to override it now, so I think it should be fine to mark it as global. This should bring in `--quiet` more in-line with how `--verbose` works. This means that `--quiet` is now accepted with `cargo report`, `cargo help`, and `cargo config`. This also fixes `--quiet` with `cargo clean gc`. This should also help with supporting `--quiet` with the new `cargo owner` subcommands being added in #11879. As for this diff, the help text changes because the `--quiet` flag is changing position (except for the 3 commands mentioned above where it is now added). Fixes #12957
2 parents fa62a0e + 80ffb1d commit 2cbbf6e

File tree

74 files changed

+140
-83
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+140
-83
lines changed

crates/xtask-bump-check/src/xtask.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ pub fn cli() -> clap::Command {
4141
.action(ArgAction::Count)
4242
.global(true),
4343
)
44-
.arg_quiet()
44+
.arg(
45+
flag("quiet", "Do not print cargo log messages")
46+
.short('q')
47+
.global(true),
48+
)
4549
.arg(
4650
opt("color", "Coloring: auto, always, never")
4751
.value_name("WHEN")

src/bin/cargo/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ See '<cyan,bold>cargo help</> <cyan><<command>></>' for more information on a sp
589589
.action(ArgAction::Count)
590590
.global(true),
591591
)
592-
.arg_quiet()
592+
.arg(flag("quiet", "Do not print cargo log messages").short('q').global(true))
593593
.arg(
594594
opt("color", "Coloring: auto, always, never")
595595
.value_name("WHEN")

src/bin/cargo/commands/add.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Example uses:
8080
.arg_manifest_path_without_unsupported_path_tip()
8181
.arg_package("Package to modify")
8282
.arg_dry_run("Don't actually write the manifest")
83-
.arg_quiet()
83+
.arg_silent_suggestion()
8484
.next_help_heading("Source")
8585
.args([
8686
clap::Arg::new("path")

src/bin/cargo/commands/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn cli() -> Command {
2424
))
2525
.arg_ignore_rust_version()
2626
.arg_message_format()
27-
.arg_quiet()
27+
.arg_silent_suggestion()
2828
.arg_package_spec(
2929
"Package to run benchmarks for",
3030
"Benchmark all packages in the workspace",

src/bin/cargo/commands/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn cli() -> Command {
1010
.arg_ignore_rust_version()
1111
.arg_future_incompat_report()
1212
.arg_message_format()
13-
.arg_quiet()
13+
.arg_silent_suggestion()
1414
.arg_package_spec(
1515
"Package to build (see `cargo help pkgid`)",
1616
"Build all packages in the workspace",

src/bin/cargo/commands/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub fn cli() -> Command {
1010
.arg_ignore_rust_version()
1111
.arg_future_incompat_report()
1212
.arg_message_format()
13-
.arg_quiet()
13+
.arg_silent_suggestion()
1414
.arg_package_spec(
1515
"Package(s) to check",
1616
"Check all packages in the workspace",

src/bin/cargo/commands/clean.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn cli() -> Command {
1212
subcommand("clean")
1313
.about("Remove artifacts that cargo has generated in the past")
1414
.arg_doc("Whether or not to clean just the documentation directory")
15-
.arg_quiet()
15+
.arg_silent_suggestion()
1616
.arg_package_spec_simple("Package to clean artifacts for")
1717
.arg_release("Whether or not to clean release artifacts")
1818
.arg_profile("Clean artifacts of the specified profile")
@@ -25,8 +25,7 @@ pub fn cli() -> Command {
2525
subcommand("gc")
2626
.about("Clean global caches")
2727
.hide(true)
28-
// FIXME: arg_quiet doesn't work because `config_configure`
29-
// doesn't know about subcommands.
28+
.arg_silent_suggestion()
3029
.arg_dry_run("Display what would be deleted without deleting anything")
3130
// NOTE: Not all of these options may get stabilized. Some of them are
3231
// very low-level details, and may not be something typical users need.

src/bin/cargo/commands/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn cli() -> Command {
1818
.arg(flag("document-private-items", "Document private items"))
1919
.arg_ignore_rust_version()
2020
.arg_message_format()
21-
.arg_quiet()
21+
.arg_silent_suggestion()
2222
.arg_package_spec(
2323
"Package to document",
2424
"Document all packages in the workspace",

src/bin/cargo/commands/fetch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use cargo::ops::FetchOptions;
66
pub fn cli() -> Command {
77
subcommand("fetch")
88
.about("Fetch dependencies of a package from the network")
9-
.arg_quiet()
9+
.arg_silent_suggestion()
1010
.arg_target_triple("Fetch dependencies for the target triple")
1111
.arg_manifest_path()
1212
.after_help(color_print::cstr!(

src/bin/cargo/commands/fix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn cli() -> Command {
2828
))
2929
.arg_ignore_rust_version()
3030
.arg_message_format()
31-
.arg_quiet()
31+
.arg_silent_suggestion()
3232
.arg_package_spec(
3333
"Package(s) to fix",
3434
"Fix all packages in the workspace",

src/bin/cargo/commands/generate_lockfile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use cargo::ops;
55
pub fn cli() -> Command {
66
subcommand("generate-lockfile")
77
.about("Generate the lockfile for a package")
8-
.arg_quiet()
8+
.arg_silent_suggestion()
99
.arg_manifest_path()
1010
.after_help(color_print::cstr!(
1111
"Run `<cyan,bold>cargo help generate-lockfile</>` for more detailed information.\n"

src/bin/cargo/commands/init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn cli() -> Command {
1313
)
1414
.arg_new_opts()
1515
.arg_registry("Registry to use")
16-
.arg_quiet()
16+
.arg_silent_suggestion()
1717
.after_help(color_print::cstr!(
1818
"Run `<cyan,bold>cargo help init</>` for more detailed information.\n"
1919
))

src/bin/cargo/commands/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub fn cli() -> Command {
7676
))
7777
.arg_ignore_rust_version()
7878
.arg_message_format()
79-
.arg_quiet()
79+
.arg_silent_suggestion()
8080
.arg_targets_bins_examples(
8181
"Install only the specified binary",
8282
"Install all binaries",

src/bin/cargo/commands/locate_project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn cli() -> Command {
1414
)
1515
.value_name("FMT"),
1616
)
17-
.arg_quiet()
17+
.arg_silent_suggestion()
1818
.arg_manifest_path()
1919
.after_help(color_print::cstr!(
2020
"Run `<cyan,bold>cargo help locate-project</>` for more detailed information.\n"

src/bin/cargo/commands/login.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn cli() -> Command {
1414
.num_args(0..)
1515
.last(true),
1616
)
17-
.arg_quiet()
17+
.arg_silent_suggestion()
1818
.after_help(color_print::cstr!(
1919
"Run `<cyan,bold>cargo help login</>` for more detailed information.\n"
2020
))

src/bin/cargo/commands/logout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub fn cli() -> Command {
77
subcommand("logout")
88
.about("Remove an API token from the registry locally")
99
.arg_registry("Registry to use")
10-
.arg_quiet()
10+
.arg_silent_suggestion()
1111
.after_help(color_print::cstr!(
1212
"Run `<cyan,bold>cargo help logout</>` for more detailed information.\n"
1313
))

src/bin/cargo/commands/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn cli() -> Command {
2323
.value_name("VERSION")
2424
.value_parser(["1"]),
2525
)
26-
.arg_quiet()
26+
.arg_silent_suggestion()
2727
.arg_features()
2828
.arg_manifest_path()
2929
.after_help(color_print::cstr!(

src/bin/cargo/commands/new.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn cli() -> Command {
1313
)
1414
.arg_new_opts()
1515
.arg_registry("Registry to use")
16-
.arg_quiet()
16+
.arg_silent_suggestion()
1717
.after_help(color_print::cstr!(
1818
"Run `<cyan,bold>cargo help new</>` for more detailed information.\n"
1919
))

src/bin/cargo/commands/owner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn cli() -> Command {
2727
.arg_index("Registry index URL to modify owners for")
2828
.arg_registry("Registry to modify owners for")
2929
.arg(opt("token", "API token to use when authenticating").value_name("TOKEN"))
30-
.arg_quiet()
30+
.arg_silent_suggestion()
3131
.after_help(color_print::cstr!(
3232
"Run `<cyan,bold>cargo help owner</>` for more detailed information.\n"
3333
))

src/bin/cargo/commands/package.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn cli() -> Command {
2424
"allow-dirty",
2525
"Allow dirty working directories to be packaged",
2626
))
27-
.arg_quiet()
27+
.arg_silent_suggestion()
2828
.arg_package_spec_no_all(
2929
"Package(s) to assemble",
3030
"Assemble all packages in the workspace",

src/bin/cargo/commands/pkgid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub fn cli() -> Command {
77
subcommand("pkgid")
88
.about("Print a fully qualified package specification")
99
.arg(Arg::new("spec").value_name("SPEC").action(ArgAction::Set))
10-
.arg_quiet()
10+
.arg_silent_suggestion()
1111
.arg_package("Argument to get the package ID specifier for")
1212
.arg_manifest_path()
1313
.after_help(color_print::cstr!(

src/bin/cargo/commands/publish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn cli() -> Command {
1717
"allow-dirty",
1818
"Allow dirty working directories to be packaged",
1919
))
20-
.arg_quiet()
20+
.arg_silent_suggestion()
2121
.arg_package("Package to publish")
2222
.arg_features()
2323
.arg_parallel()

src/bin/cargo/commands/read_manifest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Print a JSON representation of a Cargo.toml manifest.
99
Deprecated, use `<cyan,bold>cargo metadata --no-deps</>` instead.\
1010
"
1111
))
12-
.arg_quiet()
12+
.arg_silent_suggestion()
1313
.arg_manifest_path()
1414
}
1515

src/bin/cargo/commands/remove.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn cli() -> clap::Command {
2626
.value_name("DEP_ID")
2727
.help("Dependencies to be removed")])
2828
.arg_dry_run("Don't actually write the manifest")
29-
.arg_quiet()
29+
.arg_silent_suggestion()
3030
.next_help_heading("Section")
3131
.args([
3232
clap::Arg::new("dev")

src/bin/cargo/commands/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn cli() -> Command {
2424
)
2525
.arg_ignore_rust_version()
2626
.arg_message_format()
27-
.arg_quiet()
27+
.arg_silent_suggestion()
2828
.arg_package("Package with the target to run")
2929
.arg_targets_bin_example(
3030
"Name of the bin target to run",

src/bin/cargo/commands/rustc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub fn cli() -> Command {
3030
.arg_future_incompat_report()
3131
.arg_ignore_rust_version()
3232
.arg_message_format()
33-
.arg_quiet()
33+
.arg_silent_suggestion()
3434
.arg_package("Package to build")
3535
.arg_targets_all(
3636
"Build only this package's library",

src/bin/cargo/commands/rustdoc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn cli() -> Command {
1818
))
1919
.arg_ignore_rust_version()
2020
.arg_message_format()
21-
.arg_quiet()
21+
.arg_silent_suggestion()
2222
.arg_package("Package to document")
2323
.arg_targets_all(
2424
"Build only this package's library",

src/bin/cargo/commands/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn cli() -> Command {
1717
)
1818
.arg_index("Registry index URL to search packages in")
1919
.arg_registry("Registry to search packages in")
20-
.arg_quiet()
20+
.arg_silent_suggestion()
2121
.after_help(color_print::cstr!(
2222
"Run `<cyan,bold>cargo help search</>` for more detailed information.\n"
2323
))

src/bin/cargo/commands/tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn cli() -> Command {
1717
.short('a')
1818
.hide(true),
1919
)
20-
.arg_quiet()
20+
.arg_silent_suggestion()
2121
.arg(flag("no-dev-dependencies", "Deprecated, use -e=no-dev instead").hide(true))
2222
.arg(
2323
multi_opt(

src/bin/cargo/commands/uninstall.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub fn cli() -> Command {
77
.about("Remove a Rust binary")
88
.arg(Arg::new("spec").value_name("SPEC").num_args(0..))
99
.arg(opt("root", "Directory to uninstall packages from").value_name("DIR"))
10-
.arg_quiet()
10+
.arg_silent_suggestion()
1111
.arg_package_spec_simple("Package to uninstall")
1212
.arg(
1313
multi_opt("bin", "NAME", "Only uninstall the binary NAME")

src/bin/cargo/commands/update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn cli() -> Command {
3535
.value_name("PRECISE")
3636
.requires("package-group"),
3737
)
38-
.arg_quiet()
38+
.arg_silent_suggestion()
3939
.arg(
4040
flag("workspace", "Only update the workspace packages")
4141
.short('w')

src/bin/cargo/commands/vendor.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ pub fn cli() -> Command {
3636
.arg(unsupported("relative-path"))
3737
.arg(unsupported("only-git-deps"))
3838
.arg(unsupported("disallow-duplicates"))
39-
.arg_quiet_without_unknown_silent_arg_tip()
4039
.arg_manifest_path()
4140
.after_help(color_print::cstr!(
4241
"Run `<cyan,bold>cargo help vendor</>` for more detailed information.\n"

src/bin/cargo/commands/verify_project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::process;
66
pub fn cli() -> Command {
77
subcommand("verify-project")
88
.about("Check correctness of crate manifest")
9-
.arg_quiet()
9+
.arg_silent_suggestion()
1010
.arg_manifest_path()
1111
.after_help(color_print::cstr!(
1212
"Run `<cyan,bold>cargo help verify-project</>` for more detailed information.\n"

src/bin/cargo/commands/version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::command_prelude::*;
44
pub fn cli() -> Command {
55
subcommand("version")
66
.about("Show version information")
7-
.arg_quiet()
7+
.arg_silent_suggestion()
88
.after_help(color_print::cstr!(
99
"Run `<cyan,bold>cargo help version</>` for more detailed information.\n"
1010
))

src/bin/cargo/commands/yank.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn cli() -> Command {
1919
.arg_index("Registry index URL to yank from")
2020
.arg_registry("Registry to yank from")
2121
.arg(opt("token", "API token to use when authenticating").value_name("TOKEN"))
22-
.arg_quiet()
22+
.arg_silent_suggestion()
2323
.after_help(color_print::cstr!(
2424
"Run `<cyan,bold>cargo help yank</>` for more detailed information.\n"
2525
))

src/cargo/util/command_prelude.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -363,20 +363,19 @@ pub trait CommandExt: Sized {
363363
))
364364
}
365365

366-
fn arg_quiet(self) -> Self {
367-
let unsupported_silent_arg = {
368-
let value_parser = UnknownArgumentValueParser::suggest_arg("--quiet");
366+
/// Adds a suggestion for the `--silent` or `-s` flags to use the
367+
/// `--quiet` flag instead. This is to help with people familiar with
368+
/// other tools that use `-s`.
369+
///
370+
/// Every command should call this, unless it has its own `-s` short flag.
371+
fn arg_silent_suggestion(self) -> Self {
372+
let value_parser = UnknownArgumentValueParser::suggest_arg("--quiet");
373+
self._arg(
369374
flag("silent", "")
370375
.short('s')
371376
.value_parser(value_parser)
372-
.hide(true)
373-
};
374-
self.arg_quiet_without_unknown_silent_arg_tip()
375-
._arg(unsupported_silent_arg)
376-
}
377-
378-
fn arg_quiet_without_unknown_silent_arg_tip(self) -> Self {
379-
self._arg(flag("quiet", "Do not print cargo log messages").short('q'))
377+
.hide(true),
378+
)
380379
}
381380

382381
fn arg_timings(self) -> Self {

tests/testsuite/cargo_add/help/stdout.log

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ Options:
4545
-n, --dry-run
4646
Don't actually write the manifest
4747

48-
-q, --quiet
49-
Do not print cargo log messages
50-
5148
-v, --verbose...
5249
Use verbose output (-vv very verbose/build.rs output)
5350

51+
-q, --quiet
52+
Do not print cargo log messages
53+
5454
--color <WHEN>
5555
Coloring: auto, always, never
5656

tests/testsuite/cargo_bench/help/stdout.log

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Options:
1111
--no-fail-fast Run all benchmarks regardless of failure
1212
--ignore-rust-version Ignore `rust-version` specification in packages
1313
--message-format <FMT> Error format
14-
-q, --quiet Do not print cargo log messages
1514
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
15+
-q, --quiet Do not print cargo log messages
1616
--color <WHEN> Coloring: auto, always, never
1717
--config <KEY=VALUE> Override a configuration value
1818
-Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for

tests/testsuite/cargo_build/help/stdout.log

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Options:
66
--ignore-rust-version Ignore `rust-version` specification in packages
77
--future-incompat-report Outputs a future incompatibility report at the end of the build
88
--message-format <FMT> Error format
9-
-q, --quiet Do not print cargo log messages
109
-v, --verbose... Use verbose output (-vv very verbose/build.rs output)
10+
-q, --quiet Do not print cargo log messages
1111
--color <WHEN> Coloring: auto, always, never
1212
--config <KEY=VALUE> Override a configuration value
1313
-Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for

0 commit comments

Comments
 (0)