Skip to content

Commit

Permalink
fixup! feat(cli)!: set log level to DEBUG on --verbose if `RUSTUP…
Browse files Browse the repository at this point in the history
…_LOG` is unset
  • Loading branch information
rami3l committed Aug 10, 2024
1 parent 48412d4 commit ce06464
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/bin/rustup-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ async fn run_rustup_inner(
utils::current_exe()?;

match process.name().as_deref() {
Some("rustup") => rustup_mode::main(current_dir, process, Some(console_filter)).await,
Some("rustup") => rustup_mode::main(current_dir, process, console_filter).await,
Some(n) if n.starts_with("rustup-setup") || n.starts_with("rustup-init") => {
// NB: The above check is only for the prefix of the file
// name. Browsers rename duplicates to
Expand Down
22 changes: 10 additions & 12 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ enum SetSubcmd {
pub async fn main(
current_dir: PathBuf,
process: &Process,
console_filter: Option<Handle<EnvFilter, Registry>>,
console_filter: Handle<EnvFilter, Registry>,
) -> Result<utils::ExitCode> {
self_update::cleanup_self_updater(process)?;

Expand Down Expand Up @@ -576,17 +576,15 @@ pub async fn main(
};

if process.var("RUSTUP_LOG").is_err() {
if let Some(console_filter) = &console_filter {
if matches.quiet {
console_filter
.modify(|it| *it = EnvFilter::new("rustup=WARN"))
.expect("error reloading `EnvFilter` for console_logger")
}
if matches.verbose {
console_filter
.modify(|it| *it = EnvFilter::new("rustup=DEBUG"))
.expect("error reloading `EnvFilter` for console_logger")
}
if matches.quiet {
console_filter
.modify(|it| *it = EnvFilter::new("rustup=WARN"))
.expect("error reloading `EnvFilter` for console_logger")
}
if matches.verbose {
console_filter
.modify(|it| *it = EnvFilter::new("rustup=DEBUG"))
.expect("error reloading `EnvFilter` for console_logger")
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ use anyhow::{Context, Result};
use tracing::subscriber::DefaultGuard;
#[cfg(feature = "test")]
use tracing_subscriber::util::SubscriberInitExt;
#[cfg(feature = "test")]
use tracing_subscriber::{reload::Handle, EnvFilter, Registry};

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

Expand Down Expand Up @@ -230,10 +233,11 @@ impl TestProcess {
impl From<TestContext> for TestProcess {
fn from(inner: TestContext) -> Self {
let inner = Process::TestProcess(inner);
let guard = crate::cli::log::tracing_subscriber(&inner).0.set_default();
let (tracing_subscriber, console_filter) = crate::cli::log::tracing_subscriber(&inner);
Self {
process: inner,
_guard: guard,
console_filter,
_guard: tracing_subscriber.set_default(),
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/test/mock/clitools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,12 @@ impl Config {
}

let tp = process::TestProcess::new(&*self.workdir.borrow(), &arg_strings, vars, "");
let process_res =
rustup_mode::main(tp.process.current_dir().unwrap(), &tp.process, None).await;
let process_res = rustup_mode::main(
tp.process.current_dir().unwrap(),
&tp.process,
tp.console_filter.clone(),
)
.await;
// convert Err's into an ec
let ec = match process_res {
Ok(process_res) => process_res,
Expand Down
19 changes: 1 addition & 18 deletions tests/suite/cli_rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,7 @@ async fn rustup_stable_quiet() {
"
),
for_host!(
r"info: syncing channel updates for 'stable-{0}'
info: latest update on 2015-01-02, rust version 1.1.0 (hash-stable-1.1.0)
info: downloading component 'cargo'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: removing previous version of component 'cargo'
info: removing previous version of component 'rust-docs'
info: removing previous version of component 'rust-std'
info: removing previous version of component 'rustc'
info: installing component 'cargo'
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: cleaning up downloads & tmp directories
"
),
"",
)
.await;
}
Expand Down

0 comments on commit ce06464

Please sign in to comment.