Skip to content

Commit

Permalink
refactor(common)!: remove verbose flag in several places
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Aug 10, 2024
1 parent c94ef35 commit d4e4b7f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 24 deletions.
17 changes: 4 additions & 13 deletions src/cli/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,13 @@ pub(crate) fn read_line(process: &Process) -> Result<String> {
pub(super) struct Notifier {
tracker: Mutex<DownloadTracker>,
ram_notice_shown: RefCell<bool>,
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,
}
}

Expand All @@ -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);
Expand All @@ -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<Cfg<'_>> {
let notifier = Notifier::new(verbose, quiet, process);
pub(crate) fn set_globals(current_dir: PathBuf, quiet: bool, process: &Process) -> Result<Cfg<'_>> {
let notifier = Notifier::new(quiet, process);
Cfg::from_env(current_dir, Arc::new(move |n| notifier.handle(n)), process)
}

Expand Down
2 changes: 1 addition & 1 deletion src/cli/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/cli/proxy_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result<utils::Exit
Err(err) if err.kind() == DisplayVersion => {
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"),
Expand All @@ -570,7 +570,7 @@ pub async fn main(current_dir: PathBuf, process: &Process) -> Result<utils::Exit
}
};

let cfg = &mut common::set_globals(current_dir, matches.verbose, matches.quiet, process)?;
let cfg = &mut common::set_globals(current_dir, matches.quiet, process)?;

if let Some(t) = &matches.plus_toolchain {
cfg.set_toolchain_override(t);
Expand Down
9 changes: 3 additions & 6 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,6 @@ fn canonical_cargo_home(process: &Process) -> Result<Cow<'static, str>> {
pub(crate) async fn install(
current_dir: PathBuf,
no_prompt: bool,
verbose: bool,
quiet: bool,
mut opts: InstallOpts<'_>,
process: &Process,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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)?;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/setup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,5 @@ pub async fn main(
targets: &target.iter().map(|s| &**s).collect::<Vec<_>>(),
};

self_update::install(current_dir, no_prompt, verbose, quiet, opts, process).await
self_update::install(current_dir, no_prompt, quiet, opts, process).await
}

0 comments on commit d4e4b7f

Please sign in to comment.