1use clap::builder::PossibleValue;
2use clap::ValueEnum;
3
4#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub enum Color {
6 Always,
7 Auto,
8 Never,
9}
10
11impl Color {
12 #[must_use]
13 pub fn as_str(&self) -> &'static str {
14 match self {
15 Self::Always => "always",
16 Self::Auto => "auto",
17 Self::Never => "never",
18 }
19 }
20}
21
22impl ValueEnum for Color {
23 fn from_str(input: &str, ignore_case: bool) -> Result<Self, String> {
24 let input = if ignore_case {
25 input.to_lowercase()
26 } else {
27 input.to_string()
28 };
29 match &input[..] {
30 "auto" => Ok(Self::Auto),
31 "always" => Ok(Self::Always),
32 "never" => Ok(Self::Never),
33 _ => Err("unrecognized option".to_string()),
34 }
35 }
36
37 fn value_variants<'a>() -> &'a [Self] {
38 &[Self::Always, Self::Auto, Self::Never]
39 }
40
41 fn to_possible_value(&self) -> Option<PossibleValue> {
42 let possible_value = PossibleValue::new(self.as_str());
43 Some(possible_value)
44 }
45}