Skip to content

Commit

Permalink
feat(cmd)!: make !isatty(STDOUT_FILENO) subsume --quiet
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Nov 30, 2024
1 parent 35418be commit 6813dda
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub struct Pacaptr {

/// Suppress log output.
#[arg(global = true, long, conflicts_with = "dry_run")]
quiet: bool,
quiet: Option<bool>,

/// Package name or (sometimes) regex.
#[arg(global = true, name = "KEYWORDS")]
Expand Down
13 changes: 10 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,29 @@ pub struct Config {
pub no_cache: bool,

/// Suppress log output.
#[serde(default)]
pub quiet: bool,
pub quiet: Option<bool>,

/// The default package manager to be invoked.
pub default_pm: Option<String>,
}

impl Config {
/// Returns the value of the `quiet` flag if it is present,
/// otherwise returns whether the current `stdout` is **not** a TTY.
#[must_use]
pub fn quiet(&self) -> bool {
self.quiet
.unwrap_or_else(|| !console::Term::stdout().is_term())
}

/// Performs a left-biased join of two `Config`s.
pub fn join(&self, other: Self) -> Self {
Self {
dry_run: self.dry_run || other.dry_run,
needed: self.needed || other.dry_run,
no_confirm: self.no_confirm || other.no_confirm,
no_cache: self.no_cache || other.no_cache,
quiet: self.quiet || other.quiet,
quiet: self.quiet.or(other.quiet),
default_pm: self.default_pm.clone().or(other.default_pm),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ pub trait PmHelper: Pm {

/// Returns the default [`PmMode`] for this [`Pm`].
fn default_mode(&self) -> PmMode {
let quiet = self.cfg().quiet;
let quiet = self.cfg().quiet();
PmMode::CheckErr { quiet }
}

Expand Down

0 comments on commit 6813dda

Please sign in to comment.