Skip to content

Commit d288805

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

File tree

8 files changed

+32
-33
lines changed

8 files changed

+32
-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: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ 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::{
16-
common::{self, PackageUpdate},
17+
common::{self, update_console_filter, PackageUpdate},
1718
errors::CLIError,
1819
help::*,
1920
self_update::{self, check_rustup_update, SelfUpdateMode},
@@ -68,11 +69,11 @@ 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+
/// Set log level to 'DEBUG' if 'RUSTUP_LOG' is unset
73+
#[arg(short, long, conflicts_with = "quiet")]
7374
verbose: bool,
7475

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

@@ -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,8 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result<utils::Exit
570575
}
571576
};
572577

578+
update_console_filter(process, &console_filter, matches.quiet, matches.verbose);
579+
573580
let cfg = &mut common::set_globals(current_dir, matches.quiet, process)?;
574581

575582
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
@@ -793,7 +793,12 @@ impl Config {
793793
}
794794

795795
let tp = process::TestProcess::new(&*self.workdir.borrow(), &arg_strings, vars, "");
796-
let process_res = rustup_mode::main(tp.process.current_dir().unwrap(), &tp.process).await;
796+
let process_res = rustup_mode::main(
797+
tp.process.current_dir().unwrap(),
798+
&tp.process,
799+
tp.console_filter.clone(),
800+
)
801+
.await;
797802
// convert Err's into an ec
798803
let ec = match process_res {
799804
Ok(process_res) => process_res,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ 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 Set log level to 'DEBUG' if 'RUSTUP_LOG' is unset
34+
-q, --quiet Disable progress output, set log level to 'WARN' if 'RUSTUP_LOG' is unset
3535
-h, --help Print help
3636
-V, --version Print version
3737

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ 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 Set log level to 'DEBUG' if 'RUSTUP_LOG' is unset
34+
-q, --quiet Disable progress output, set log level to 'WARN' if 'RUSTUP_LOG' is unset
3535
-h, --help Print help
3636
-V, --version Print version
3737

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+
Set log level to 'DEBUG' if 'RUSTUP_LOG' is unset
3636
3737
-q, --quiet
38-
Disable progress output
38+
Disable progress output, set log 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)