From d4e4b7ff68d176f4aec10637dd7475c57362b4a3 Mon Sep 17 00:00:00 2001 From: rami3l Date: Sat, 10 Aug 2024 20:16:04 +0800 Subject: [PATCH] refactor(common)!: remove `verbose` flag in several places --- src/cli/common.rs | 17 ++++------------- src/cli/log.rs | 2 +- src/cli/proxy_mode.rs | 2 +- src/cli/rustup_mode.rs | 4 ++-- src/cli/self_update.rs | 9 +++------ src/cli/setup_mode.rs | 2 +- 6 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/cli/common.rs b/src/cli/common.rs index 5d3a99a812f..d0af375f451 100644 --- a/src/cli/common.rs +++ b/src/cli/common.rs @@ -127,15 +127,13 @@ pub(crate) fn read_line(process: &Process) -> Result { pub(super) struct Notifier { tracker: Mutex, ram_notice_shown: RefCell, - verbose: bool, } impl Notifier { - pub(super) fn new(verbose: bool, quiet: bool, process: &Process) -> Self { + pub(super) fn new(quiet: bool, process: &Process) -> Self { Self { tracker: Mutex::new(DownloadTracker::new_with_display_progress(!quiet, process)), ram_notice_shown: RefCell::new(false), - verbose, } } @@ -158,9 +156,7 @@ impl Notifier { for n in format!("{n}").lines() { match level { NotificationLevel::Debug => { - if self.verbose { - debug!("{}", n); - } + debug!("{}", n); } NotificationLevel::Info => { info!("{}", n); @@ -180,13 +176,8 @@ impl Notifier { } #[tracing::instrument(level = "trace")] -pub(crate) fn set_globals( - current_dir: PathBuf, - verbose: bool, - quiet: bool, - process: &Process, -) -> Result> { - let notifier = Notifier::new(verbose, quiet, process); +pub(crate) fn set_globals(current_dir: PathBuf, quiet: bool, process: &Process) -> Result> { + let notifier = Notifier::new(quiet, process); Cfg::from_env(current_dir, Arc::new(move |n| notifier.handle(n)), process) } diff --git a/src/cli/log.rs b/src/cli/log.rs index a0d169ce766..5db2bb0b53e 100644 --- a/src/cli/log.rs +++ b/src/cli/log.rs @@ -69,7 +69,7 @@ where (logger.compact().with_filter(env_filter).boxed(), handle) } else { // Receive log lines from Rustup only. - let (env_filter, handle) = reload::Layer::new(EnvFilter::new("rustup=DEBUG")); + let (env_filter, handle) = reload::Layer::new(EnvFilter::new("rustup=INFO")); ( logger .event_format(EventFormatter) diff --git a/src/cli/proxy_mode.rs b/src/cli/proxy_mode.rs index de55f9a99ca..650767fb445 100644 --- a/src/cli/proxy_mode.rs +++ b/src/cli/proxy_mode.rs @@ -31,7 +31,7 @@ pub async fn main(arg0: &str, current_dir: PathBuf, process: &Process) -> Result .skip(1 + toolchain.is_some() as usize) .collect(); - let cfg = set_globals(current_dir, false, true, process)?; + let cfg = set_globals(current_dir, true, process)?; let cmd = cfg.resolve_local_toolchain(toolchain)?.command(arg0)?; run_command_for_dir(cmd, arg0, &cmd_args) } diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 89fd348f23f..28ed7b29e16 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -545,7 +545,7 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result { write!(process.stdout().lock(), "{err}")?; info!("This is the version for the rustup toolchain manager, not the rustc compiler."); - let mut cfg = common::set_globals(current_dir, false, true, process)?; + let mut cfg = common::set_globals(current_dir, true, process)?; match cfg.active_rustc_version() { Ok(Some(version)) => info!("The currently active `rustc` version is `{version}`"), Ok(None) => info!("No `rustc` is currently active"), @@ -570,7 +570,7 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result Result> { pub(crate) async fn install( current_dir: PathBuf, no_prompt: bool, - verbose: bool, quiet: bool, mut opts: InstallOpts<'_>, process: &Process, @@ -549,7 +548,7 @@ pub(crate) async fn install( } let no_modify_path = opts.no_modify_path; - if let Err(e) = maybe_install_rust(current_dir, verbose, quiet, opts, process).await { + if let Err(e) = maybe_install_rust(current_dir, quiet, opts, process).await { report_error(&e, process); // On windows, where installation happens in a console @@ -804,7 +803,6 @@ pub(crate) fn install_proxies(process: &Process) -> Result<()> { async fn maybe_install_rust( current_dir: PathBuf, - verbose: bool, quiet: bool, opts: InstallOpts<'_>, process: &Process, @@ -828,7 +826,7 @@ async fn maybe_install_rust( fs::create_dir_all(home).context("unable to create ~/.rustup")?; } - let mut cfg = common::set_globals(current_dir, verbose, quiet, process)?; + let mut cfg = common::set_globals(current_dir, quiet, process)?; let (components, targets) = (opts.components, opts.targets); let toolchain = opts.install(&mut cfg)?; @@ -1230,8 +1228,7 @@ mod tests { home.apply(&mut vars); let tp = TestProcess::with_vars(vars); let mut cfg = - common::set_globals(tp.process.current_dir().unwrap(), false, false, &tp.process) - .unwrap(); + common::set_globals(tp.process.current_dir().unwrap(), false, &tp.process).unwrap(); let opts = InstallOpts { default_host_triple: None, diff --git a/src/cli/setup_mode.rs b/src/cli/setup_mode.rs index ed2fe95c9da..fabcb2f901b 100644 --- a/src/cli/setup_mode.rs +++ b/src/cli/setup_mode.rs @@ -131,5 +131,5 @@ pub async fn main( targets: &target.iter().map(|s| &**s).collect::>(), }; - self_update::install(current_dir, no_prompt, verbose, quiet, opts, process).await + self_update::install(current_dir, no_prompt, quiet, opts, process).await }