Skip to content

Commit

Permalink
Auto merge of #10152 - steven-joruk:quiet-config, r=ehuss
Browse files Browse the repository at this point in the history
Support `term.quiet` configuration

Fixes #10128

This follows the existing support for `--verbose` and `term.verbose`.

I've renamed the related tests to be a bit clearer now there are more cases, and the existing quiet tests now prove that they hide the cargo log.

I'm unsure whether I'm supposed to regenerate the documentation as part of this?
  • Loading branch information
bors committed Dec 14, 2021
2 parents c689f55 + bfe27c5 commit a359ce1
Show file tree
Hide file tree
Showing 96 changed files with 333 additions and 80 deletions.
28 changes: 14 additions & 14 deletions src/cargo/util/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,20 +909,19 @@ impl Config {

let color = color.or_else(|| term.color.as_deref());

let verbosity = match (verbose, term.verbose, quiet) {
(true, _, false) | (_, Some(true), false) => Verbosity::Verbose,

// Command line takes precedence over configuration, so ignore the
// configuration..
(false, _, true) => Verbosity::Quiet,

// Can't pass both at the same time on the command line regardless
// of configuration.
(true, _, true) => {
bail!("cannot set both --verbose and --quiet");
}

(false, _, false) => Verbosity::Normal,
// The command line takes precedence over configuration.
let verbosity = match (verbose, quiet) {
(true, true) => bail!("cannot set both --verbose and --quiet"),
(true, false) => Verbosity::Verbose,
(false, true) => Verbosity::Quiet,
(false, false) => match (term.verbose, term.quiet) {
(Some(true), Some(true)) => {
bail!("cannot set both `term.verbose` and `term.quiet`")
}
(Some(true), Some(false)) => Verbosity::Verbose,
(Some(false), Some(true)) => Verbosity::Quiet,
_ => Verbosity::Normal,
},
};

let cli_target_dir = target_dir.as_ref().map(|dir| Filesystem::new(dir.clone()));
Expand Down Expand Up @@ -2127,6 +2126,7 @@ pub struct CargoBuildConfig {
#[derive(Deserialize, Default)]
struct TermConfig {
verbose: Option<bool>,
quiet: Option<bool>,
color: Option<String>,
#[serde(default)]
#[serde(deserialize_with = "progress_or_string")]
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-bench.txt
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-check.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-clean.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-fetch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-fix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-generate-lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-init.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-install.txt
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-locate-project.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-login.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-owner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-package.txt
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-pkgid.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-publish.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-run.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-rustc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-rustdoc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-search.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-tree.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-uninstall.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-update.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-vendor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-verify-project.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo-yank.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
4 changes: 3 additions & 1 deletion src/doc/man/generated_txt/cargo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ OPTIONS
value <https://doc.rust-lang.org/cargo/reference/config.html>.

-q, --quiet
Do not print cargo log messages.
Do not print cargo log messages. May also be specified with the
term.quiet config value
<https://doc.rust-lang.org/cargo/reference/config.html>.

--color when
Control when colored output is used. Valid values:
Expand Down
2 changes: 2 additions & 0 deletions src/doc/man/includes/options-display.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ May also be specified with the `term.verbose`

{{#option "`-q`" "`--quiet`"}}
Do not print cargo log messages.
May also be specified with the `term.quiet`
[config value](../reference/config.html).
{{/option}}

{{#option "`--color` _when_"}}
Expand Down
4 changes: 3 additions & 1 deletion src/doc/src/commands/cargo-bench.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ May also be specified with the <code>term.verbose</code>

<dt class="option-term" id="option-cargo-bench--q"><a class="option-anchor" href="#option-cargo-bench--q"></a><code>-q</code></dt>
<dt class="option-term" id="option-cargo-bench---quiet"><a class="option-anchor" href="#option-cargo-bench---quiet"></a><code>--quiet</code></dt>
<dd class="option-desc">Do not print cargo log messages.</dd>
<dd class="option-desc">Do not print cargo log messages.
May also be specified with the <code>term.quiet</code>
<a href="../reference/config.html">config value</a>.</dd>


<dt class="option-term" id="option-cargo-bench---color"><a class="option-anchor" href="#option-cargo-bench---color"></a><code>--color</code> <em>when</em></dt>
Expand Down
Loading

0 comments on commit a359ce1

Please sign in to comment.