From 2ff3d437240eb663ffc4ff3c7956f1faa62b02a2 Mon Sep 17 00:00:00 2001 From: Thayne McCombs Date: Thu, 3 Nov 2022 01:35:40 -0600 Subject: [PATCH] feat(derive): Implement ValueEnum for ColorChoice --- src/util/color.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/util/color.rs b/src/util/color.rs index 15c9901a079..c13d20d3ea8 100644 --- a/src/util/color.rs +++ b/src/util/color.rs @@ -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 { + 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"), + }) + } +}