mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 14:54:15 +00:00
feat(derive): Implement ValueEnum for ColorChoice
This commit is contained in:
parent
033438eb4b
commit
2ff3d43724
1 changed files with 19 additions and 0 deletions
|
@ -1,3 +1,6 @@
|
|||
use crate::builder::PossibleValue;
|
||||
use crate::derive::ValueEnum;
|
||||
|
||||
/// Represents the color preferences for program output
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
pub enum ColorChoice {
|
||||
|
@ -60,3 +63,19 @@ impl Default for ColorChoice {
|
|||
Self::Auto
|
||||
}
|
||||
}
|
||||
|
||||
impl ValueEnum for ColorChoice {
|
||||
fn value_variants<'a>() -> &'a [Self] {
|
||||
&[Self::Auto, Self::Always, Self::Never]
|
||||
}
|
||||
|
||||
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"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue