Skip to content

Commit

Permalink
Use unwrap_or_default() when getting default color and verbosity (#2397)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Sep 30, 2024
1 parent 70476be commit c08eb90
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 21 deletions.
5 changes: 1 addition & 4 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ impl Color {
}

pub(crate) fn auto() -> Self {
Self {
use_color: UseColor::Auto,
..Self::default()
}
Self::default()
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn run(args: impl Iterator<Item = impl Into<OsString> + Clone>) -> Result<()
let (color, verbosity) = config
.as_ref()
.map(|config| (config.color, config.verbosity))
.unwrap_or((Color::auto(), Verbosity::default()));
.unwrap_or_default();

let loader = Loader::new();

Expand Down
30 changes: 14 additions & 16 deletions src/verbosity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use Verbosity::*;

#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
pub(crate) enum Verbosity {
Quiet,
Taciturn,
Expand All @@ -11,35 +9,35 @@ pub(crate) enum Verbosity {
impl Verbosity {
pub(crate) fn from_flag_occurrences(flag_occurrences: u8) -> Self {
match flag_occurrences {
0 => Taciturn,
1 => Loquacious,
_ => Grandiloquent,
0 => Self::Taciturn,
1 => Self::Loquacious,
_ => Self::Grandiloquent,
}
}

pub(crate) fn quiet(self) -> bool {
matches!(self, Quiet)
self == Self::Quiet
}

pub(crate) fn loud(self) -> bool {
!self.quiet()
}

pub(crate) fn loquacious(self) -> bool {
match self {
Quiet | Taciturn => false,
Loquacious | Grandiloquent => true,
}
self >= Self::Loquacious
}

pub(crate) fn grandiloquent(self) -> bool {
match self {
Quiet | Taciturn | Loquacious => false,
Grandiloquent => true,
}
self >= Self::Grandiloquent
}

pub const fn default() -> Self {
Taciturn
Self::Taciturn
}
}

impl Default for Verbosity {
fn default() -> Self {
Self::default()
}
}

0 comments on commit c08eb90

Please sign in to comment.