mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-20 20:48:43 +00:00
Merge pull request #281 from cargo-bins/fix-quiet
Improve doc of cmdline option `log_level`, add `--quiet` and pass it to `cargo-install`
This commit is contained in:
commit
b46e54b53a
3 changed files with 51 additions and 8 deletions
|
@ -17,4 +17,5 @@ pub struct Options {
|
|||
pub manifest_path: Option<PathBuf>,
|
||||
pub cli_overrides: PkgOverride,
|
||||
pub desired_targets: DesiredTargets,
|
||||
pub quiet: bool,
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
@ -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<Meta>,
|
||||
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.")?;
|
||||
|
|
38
src/main.rs
38
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};
|
||||
|
@ -148,14 +148,44 @@ 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.
|
||||
///
|
||||
/// 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,
|
||||
default_value = "info",
|
||||
value_name = "LEVEL"
|
||||
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`."
|
||||
),
|
||||
]
|
||||
)]
|
||||
log_level: LevelFilter,
|
||||
|
||||
/// Equivalent to setting `log_level` to `off`.
|
||||
///
|
||||
/// This would override the `log_level`.
|
||||
#[clap(help_heading = "Meta", short, long)]
|
||||
quiet: bool,
|
||||
}
|
||||
|
||||
enum MainExit {
|
||||
|
@ -229,6 +259,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 {
|
||||
|
@ -320,6 +353,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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue