From 62bce2f52f651cb13c0779b9518ba7f525836181 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Thu, 4 Aug 2022 23:15:05 +1000 Subject: [PATCH 1/7] Improve doc for `Options::log_level` Signed-off-by: Jiahao XU --- src/main.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main.rs b/src/main.rs index a794c52c..a725e285 100644 --- a/src/main.rs +++ b/src/main.rs @@ -149,6 +149,12 @@ struct Options { /// Utility log level /// /// Set to `debug` when submitting a bug report. + /// Set to `info` to only print useful information. + /// Set to `Warn` to only print on hazardous situations. + /// Set to `Error` to only print serious errors. + /// + /// Set to `off` to disable logging completely, this will also + /// disable output from `cargo-install`. #[clap( help_heading = "Meta", long, From 6685d5a610b75f97cd51aa926ec6b09e92212c62 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Thu, 4 Aug 2022 23:16:45 +1000 Subject: [PATCH 2/7] Add new option `Options::quiet` Signed-off-by: Jiahao XU --- src/main.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.rs b/src/main.rs index a725e285..85f5cc4e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -162,6 +162,12 @@ struct Options { value_name = "LEVEL" )] log_level: LevelFilter, + + /// Equivalent to setting `log_level` to `off`. + /// + /// This would override the `log_level`. + #[clap(help_heading = "Meta", long)] + quiet: bool, } enum MainExit { @@ -235,6 +241,9 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> { // Load options let mut opts = Options::parse_from(args); + if opts.quiet { + opts.log_level = LevelFilter::Off; + } let crate_names = take(&mut opts.crate_names); if crate_names.len() > 1 { From 3d28549fd6b5f439a0679d53228b29277a9e32cb Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Thu, 4 Aug 2022 23:18:00 +1000 Subject: [PATCH 3/7] Apply clippy suggestions in `binstall::install` Signed-off-by: Jiahao XU --- src/binstall/install.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/binstall/install.rs b/src/binstall/install.rs index 365dd0de..e4db9eb8 100644 --- a/src/binstall/install.rs +++ b/src/binstall/install.rs @@ -30,8 +30,8 @@ pub async fn install( .await .map(|option| { option.map(|bins| MetaData { - name: name.into(), - version_req: version.into(), + name, + version_req: version, current_version, source: Source::cratesio_registry(), target, From b6a539735db922173459e27c216a5fa7d85d7677 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Thu, 4 Aug 2022 23:21:29 +1000 Subject: [PATCH 4/7] Pass `-q` to `cargo-install` if `log_level` is set to off Signed-off-by: Jiahao XU --- src/binstall.rs | 1 + src/binstall/install.rs | 16 ++++++++++++---- src/main.rs | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/binstall.rs b/src/binstall.rs index 12a532f7..43707c0c 100644 --- a/src/binstall.rs +++ b/src/binstall.rs @@ -17,4 +17,5 @@ pub struct Options { pub manifest_path: Option, pub cli_overrides: PkgOverride, pub desired_targets: DesiredTargets, + pub quiet: bool, } diff --git a/src/binstall/install.rs b/src/binstall/install.rs index e4db9eb8..670c81eb 100644 --- a/src/binstall/install.rs +++ b/src/binstall/install.rs @@ -47,7 +47,7 @@ pub async fn install( .ok_or_else(|| miette!("No viable targets found, try with `--targets`"))?; if !opts.dry_run { - install_from_source(package, target, jobserver_client) + install_from_source(package, target, jobserver_client, opts.quiet) .await .map(|_| None) } else { @@ -126,6 +126,7 @@ async fn install_from_source( package: Package, target: &str, lazy_jobserver_client: LazyJobserverClient, + quiet: bool, ) -> Result<()> { let jobserver_client = lazy_jobserver_client.get().await?; @@ -136,13 +137,20 @@ async fn install_from_source( let mut command = process::Command::new("cargo"); jobserver_client.configure(&mut command); - let mut child = Command::from(command) - .arg("install") + let mut cmd = Command::from(command); + + cmd.arg("install") .arg(package.name) .arg("--version") .arg(package.version) .arg("--target") - .arg(&*target) + .arg(&*target); + + if quiet { + cmd.arg("quiet"); + } + + let mut child = cmd .spawn() .into_diagnostic() .wrap_err("Spawning cargo install failed.")?; diff --git a/src/main.rs b/src/main.rs index 85f5cc4e..35379458 100644 --- a/src/main.rs +++ b/src/main.rs @@ -335,6 +335,7 @@ async fn entry(jobserver_client: LazyJobserverClient) -> Result<()> { manifest_path: opts.manifest_path.take(), cli_overrides, desired_targets, + quiet: opts.log_level == LevelFilter::Off, }); let tasks: Vec<_> = if !opts.dry_run && !opts.no_confirm { From 8d5f55537318906e09304a1cd4414bb3222b0aa2 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Fri, 5 Aug 2022 15:02:38 +1000 Subject: [PATCH 5/7] Add new option `-q` for compatibility with `cargo-install` Signed-off-by: Jiahao XU --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 35379458..6e4bace0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -166,7 +166,7 @@ struct Options { /// Equivalent to setting `log_level` to `off`. /// /// This would override the `log_level`. - #[clap(help_heading = "Meta", long)] + #[clap(help_heading = "Meta", short, long)] quiet: bool, } From 7a90d4d6c6e8759b3a31b560067506751ae31b77 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Fri, 5 Aug 2022 15:09:40 +1000 Subject: [PATCH 6/7] Improve help page for `Options::log_level` Signed-off-by: Jiahao XU --- src/main.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6e4bace0..dea6024e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use std::{ time::{Duration, Instant}, }; -use clap::{AppSettings, Parser}; +use clap::{builder::PossibleValue, AppSettings, Parser}; use compact_str::CompactString; use log::{debug, error, info, warn, LevelFilter}; use miette::{miette, Result, WrapErr}; @@ -149,9 +149,12 @@ struct Options { /// Utility log level /// /// Set to `debug` when submitting a bug report. + /// /// Set to `info` to only print useful information. - /// Set to `Warn` to only print on hazardous situations. - /// Set to `Error` to only print serious errors. + /// + /// Set to `warn` to only print on hazardous situations. + /// + /// Set to `error` to only print serious errors. /// /// Set to `off` to disable logging completely, this will also /// disable output from `cargo-install`. @@ -159,7 +162,14 @@ struct Options { help_heading = "Meta", long, default_value = "info", - value_name = "LEVEL" + value_name = "LEVEL", + possible_values = [ + PossibleValue::new("debug").help("Set to debug when submitting a bug report."), + PossibleValue::new("info").help("Set to info to only print useful information."), + PossibleValue::new("warn").help("Set to warn to only print on hazardous situations."), + PossibleValue::new("error").help("Set to error to only print serious errors."), + PossibleValue::new("off").help("Set to off to disable logging completely, this will also disable output from `cargo-install`."), + ] )] log_level: LevelFilter, From c352eb00d1f89d4df7826532d1b55b70870d423b Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Fri, 5 Aug 2022 15:24:39 +1000 Subject: [PATCH 7/7] Add missing doc for `trace` for `Options::log_level` Signed-off-by: Jiahao XU --- src/main.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index dea6024e..35a3d9bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -148,6 +148,9 @@ struct Options { /// Utility log level /// + /// Set to `trace` to print very low priority, often extremely + /// verbose information. + /// /// Set to `debug` when submitting a bug report. /// /// Set to `info` to only print useful information. @@ -164,11 +167,16 @@ struct Options { default_value = "info", value_name = "LEVEL", possible_values = [ + PossibleValue::new("trace").help( + "Set to `trace` to print very low priority, often extremely verbose information." + ), PossibleValue::new("debug").help("Set to debug when submitting a bug report."), PossibleValue::new("info").help("Set to info to only print useful information."), PossibleValue::new("warn").help("Set to warn to only print on hazardous situations."), PossibleValue::new("error").help("Set to error to only print serious errors."), - PossibleValue::new("off").help("Set to off to disable logging completely, this will also disable output from `cargo-install`."), + PossibleValue::new("off").help( + "Set to off to disable logging completely, this will also disable output from `cargo-install`." + ), ] )] log_level: LevelFilter,