Skip to content

Commit

Permalink
Improve colorchoice enum
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Jun 20, 2023
1 parent 482012a commit cfd1d22
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions clap_builder/src/util/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ pub enum ColorChoice {
Never,
}

impl ColorChoice {
/// Report all `possible_values`
pub fn possible_values() -> impl Iterator<Item = PossibleValue> {
Self::value_variants()
.iter()
.filter_map(ValueEnum::to_possible_value)
}
}

impl Default for ColorChoice {
fn default() -> Self {
Self::Auto
Expand Down Expand Up @@ -99,11 +108,9 @@ impl ValueEnum for ColorChoice {

fn to_possible_value(&self) -> Option<PossibleValue> {
Some(match self {
Self::Auto => {
PossibleValue::new("auto").help("Use colored output if writing to a terminal/TTY")
}
Self::Always => PossibleValue::new("always").help("Always use colored output"),
Self::Never => PossibleValue::new("never").help("Never use colored output"),
Self::Auto => PossibleValue::new("auto"),
Self::Always => PossibleValue::new("always"),
Self::Never => PossibleValue::new("never"),
})
}
}

0 comments on commit cfd1d22

Please sign in to comment.