Skip to content

Commit 48412d4

Browse files
committed
feat(cli)!: set log level to DEBUG on --verbose if RUSTUP_LOG is unset
1 parent 827bcb7 commit 48412d4

8 files changed

+53
-21
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, Some(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: 25 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: Option<Handle<EnvFilter, Registry>>,
540+
) -> Result<utils::ExitCode> {
536541
self_update::cleanup_self_updater(process)?;
537542

538543
use clap::error::ErrorKind::*;
@@ -570,6 +575,21 @@ 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 let Some(console_filter) = &console_filter {
580+
if matches.quiet {
581+
console_filter
582+
.modify(|it| *it = EnvFilter::new("rustup=WARN"))
583+
.expect("error reloading `EnvFilter` for console_logger")
584+
}
585+
if matches.verbose {
586+
console_filter
587+
.modify(|it| *it = EnvFilter::new("rustup=DEBUG"))
588+
.expect("error reloading `EnvFilter` for console_logger")
589+
}
590+
}
591+
}
592+
573593
let cfg = &mut common::set_globals(current_dir, matches.quiet, process)?;
574594

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

src/cli/setup_mode.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ use crate::{
2525
before_help = format!("rustup-init {}", common::version()),
2626
)]
2727
struct RustupInit {
28-
/// Enable verbose output
29-
#[arg(short, long)]
28+
/// Enable verbose output, limit console logger level to 'DEBUG' if 'RUSTUP_LOG' is unset
29+
#[arg(short, long, overrides_with = "quiet")]
3030
verbose: bool,
3131

3232
/// Disable progress output, limit console logger level to 'WARN' if 'RUSTUP_LOG' is unset
33-
#[arg(short, long)]
33+
#[arg(short, long, overrides_with = "verbose")]
3434
quiet: bool,
3535

3636
/// Disable confirmation prompt
@@ -115,10 +115,17 @@ pub async fn main(
115115
warn!("{}", common::WARN_COMPLETE_PROFILE);
116116
}
117117

118-
if quiet && process.var("RUSTUP_LOG").is_err() {
119-
console_filter
120-
.modify(|it| *it = EnvFilter::new("rustup=WARN"))
121-
.expect("error reloading `EnvFilter` for console_logger");
118+
if process.var("RUSTUP_LOG").is_err() {
119+
if quiet {
120+
console_filter
121+
.modify(|it| *it = EnvFilter::new("rustup=WARN"))
122+
.expect("error reloading `EnvFilter` for console_logger");
123+
}
124+
if verbose {
125+
console_filter
126+
.modify(|it| *it = EnvFilter::new("rustup=DEBUG"))
127+
.expect("error reloading `EnvFilter` for console_logger");
128+
}
122129
}
123130

124131
let opts = InstallOpts {

src/test/mock/clitools.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,8 @@ 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 =
794+
rustup_mode::main(tp.process.current_dir().unwrap(), &tp.process, None).await;
794795
// convert Err's into an ec
795796
let ec = match process_res {
796797
Ok(process_res) => process_res,

tests/suite/cli-ui/rustup-init/rustup-init_help_flag_stdout.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Usage: rustup-init[EXE] [OPTIONS]
1010
1111
Options:
1212
-v, --verbose
13-
Enable verbose output
13+
Enable verbose output, limit console logger level to 'DEBUG' if 'RUSTUP_LOG' is unset
1414
-q, --quiet
1515
Disable progress output, limit console logger level to 'WARN' if 'RUSTUP_LOG' is unset
1616
-y

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

0 commit comments

Comments
 (0)