Skip to content

Commit 1eb60b5

Browse files
committed
feat(cli/rustup-mode)!: set log level to DEBUG on --verbose if RUSTUP_LOG is unset
1 parent fc0e7f1 commit 1eb60b5

File tree

8 files changed

+47
-33
lines changed

8 files changed

+47
-33
lines changed

src/bin/rustup-init.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ async fn run_rustup_inner(
9393
utils::current_exe()?;
9494

9595
match process.name().as_deref() {
96-
Some("rustup") => rustup_mode::main(current_dir, process).await,
96+
Some("rustup") => rustup_mode::main(current_dir, process, console_filter).await,
9797
Some(n) if n.starts_with("rustup-setup") || n.starts_with("rustup-init") => {
9898
// NB: The above check is only for the prefix of the file
9999
// name. Browsers rename duplicates to

src/cli/rustup_mode.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use clap::{builder::PossibleValue, Args, CommandFactory, Parser, Subcommand, Val
1010
use clap_complete::Shell;
1111
use itertools::Itertools;
1212
use tracing::{info, trace, warn};
13+
use tracing_subscriber::{reload::Handle, EnvFilter, Registry};
1314

1415
use crate::{
1516
cli::{
@@ -68,12 +69,12 @@ fn handle_epipe(res: Result<utils::ExitCode>) -> Result<utils::ExitCode> {
6869
after_help = RUSTUP_HELP,
6970
)]
7071
struct Rustup {
71-
/// Enable verbose output
72-
#[arg(short, long)]
72+
/// Enable verbose output, limit console logger level to 'DEBUG' if 'RUSTUP_LOG' is unset
73+
#[arg(short, long, overrides_with = "quiet")]
7374
verbose: bool,
7475

75-
/// Disable progress output
76-
#[arg(short, long, conflicts_with = "verbose")]
76+
/// Disable progress output, limit console logger level to 'WARN' if 'RUSTUP_LOG' is unset
77+
#[arg(short, long, overrides_with = "verbose")]
7778
quiet: bool,
7879

7980
/// Release channel (e.g. +stable) or custom toolchain to set override
@@ -532,7 +533,11 @@ enum SetSubcmd {
532533
}
533534

534535
#[tracing::instrument(level = "trace", fields(args = format!("{:?}", process.args_os().collect::<Vec<_>>())))]
535-
pub async fn main(current_dir: PathBuf, process: &Process) -> Result<utils::ExitCode> {
536+
pub async fn main(
537+
current_dir: PathBuf,
538+
process: &Process,
539+
console_filter: Handle<EnvFilter, Registry>,
540+
) -> Result<utils::ExitCode> {
536541
self_update::cleanup_self_updater(process)?;
537542

538543
use clap::error::ErrorKind::*;
@@ -570,6 +575,19 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result<utils::Exit
570575
}
571576
};
572577

578+
if process.var("RUSTUP_LOG").is_err() {
579+
if matches.quiet {
580+
console_filter
581+
.modify(|it| *it = EnvFilter::new("rustup=WARN"))
582+
.expect("error reloading `EnvFilter` for console_logger")
583+
}
584+
if matches.verbose {
585+
console_filter
586+
.modify(|it| *it = EnvFilter::new("rustup=DEBUG"))
587+
.expect("error reloading `EnvFilter` for console_logger")
588+
}
589+
}
590+
573591
let cfg = &mut common::set_globals(current_dir, matches.quiet, process)?;
574592

575593
if let Some(t) = &matches.plus_toolchain {

src/process.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ use anyhow::{Context, Result};
1717
use tracing::subscriber::DefaultGuard;
1818
#[cfg(feature = "test")]
1919
use tracing_subscriber::util::SubscriberInitExt;
20+
#[cfg(feature = "test")]
21+
use tracing_subscriber::{reload::Handle, EnvFilter, Registry};
2022

2123
pub mod filesource;
2224
pub mod terminalsource;
@@ -177,6 +179,7 @@ impl Default for OsProcess {
177179
#[cfg(feature = "test")]
178180
pub struct TestProcess {
179181
pub process: Process,
182+
pub console_filter: Handle<EnvFilter, Registry>,
180183
_guard: DefaultGuard, // guard is dropped at the end of the test
181184
}
182185

@@ -230,10 +233,11 @@ impl TestProcess {
230233
impl From<TestContext> for TestProcess {
231234
fn from(inner: TestContext) -> Self {
232235
let inner = Process::TestProcess(inner);
233-
let guard = crate::cli::log::tracing_subscriber(&inner).0.set_default();
236+
let (tracing_subscriber, console_filter) = crate::cli::log::tracing_subscriber(&inner);
234237
Self {
235238
process: inner,
236-
_guard: guard,
239+
console_filter,
240+
_guard: tracing_subscriber.set_default(),
237241
}
238242
}
239243
}

src/test/mock/clitools.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,12 @@ impl Config {
790790
}
791791

792792
let tp = process::TestProcess::new(&*self.workdir.borrow(), &arg_strings, vars, "");
793-
let process_res = rustup_mode::main(tp.process.current_dir().unwrap(), &tp.process).await;
793+
let process_res = rustup_mode::main(
794+
tp.process.current_dir().unwrap(),
795+
&tp.process,
796+
tp.console_filter.clone(),
797+
)
798+
.await;
794799
// convert Err's into an ec
795800
let ec = match process_res {
796801
Ok(process_res) => process_res,

tests/suite/cli-ui/rustup/rustup_help_cmd_stdout.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ Arguments:
3030
[+toolchain] Release channel (e.g. +stable) or custom toolchain to set override
3131
3232
Options:
33-
-v, --verbose Enable verbose output
34-
-q, --quiet Disable progress output
33+
-v, --verbose Enable verbose output, limit console logger level to 'DEBUG' if 'RUSTUP_LOG' is
34+
unset
35+
-q, --quiet Disable progress output, limit console logger level to 'WARN' if 'RUSTUP_LOG' is
36+
unset
3537
-h, --help Print help
3638
-V, --version Print version
3739

tests/suite/cli-ui/rustup/rustup_help_flag_stdout.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ Arguments:
3030
[+toolchain] Release channel (e.g. +stable) or custom toolchain to set override
3131
3232
Options:
33-
-v, --verbose Enable verbose output
34-
-q, --quiet Disable progress output
33+
-v, --verbose Enable verbose output, limit console logger level to 'DEBUG' if 'RUSTUP_LOG' is
34+
unset
35+
-q, --quiet Disable progress output, limit console logger level to 'WARN' if 'RUSTUP_LOG' is
36+
unset
3537
-h, --help Print help
3638
-V, --version Print version
3739

tests/suite/cli-ui/rustup/rustup_only_options_stdout.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ Arguments:
3232
3333
Options:
3434
-v, --verbose
35-
Enable verbose output
35+
Enable verbose output, limit console logger level to 'DEBUG' if 'RUSTUP_LOG' is unset
3636
3737
-q, --quiet
38-
Disable progress output
38+
Disable progress output, limit console logger level to 'WARN' if 'RUSTUP_LOG' is unset
3939
4040
-h, --help
4141
Print help

tests/suite/cli_rustup.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,7 @@ async fn rustup_stable_quiet() {
8484
8585
"
8686
),
87-
for_host!(
88-
r"info: syncing channel updates for 'stable-{0}'
89-
info: latest update on 2015-01-02, rust version 1.1.0 (hash-stable-1.1.0)
90-
info: downloading component 'cargo'
91-
info: downloading component 'rust-docs'
92-
info: downloading component 'rust-std'
93-
info: downloading component 'rustc'
94-
info: removing previous version of component 'cargo'
95-
info: removing previous version of component 'rust-docs'
96-
info: removing previous version of component 'rust-std'
97-
info: removing previous version of component 'rustc'
98-
info: installing component 'cargo'
99-
info: installing component 'rust-docs'
100-
info: installing component 'rust-std'
101-
info: installing component 'rustc'
102-
info: cleaning up downloads & tmp directories
103-
"
104-
),
87+
"",
10588
)
10689
.await;
10790
}

0 commit comments

Comments
 (0)