From cfd1d22e26f064a957842a6069b70e45f79cbdbf Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Tue, 20 Jun 2023 08:55:04 +0100 Subject: [PATCH] Improve colorchoice enum --- clap_builder/src/util/color.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/clap_builder/src/util/color.rs b/clap_builder/src/util/color.rs index 7a0e837e..d13a6df9 100644 --- a/clap_builder/src/util/color.rs +++ b/clap_builder/src/util/color.rs @@ -64,6 +64,15 @@ pub enum ColorChoice { Never, } +impl ColorChoice { + /// Report all `possible_values` + pub fn possible_values() -> impl Iterator { + Self::value_variants() + .iter() + .filter_map(ValueEnum::to_possible_value) + } +} + impl Default for ColorChoice { fn default() -> Self { Self::Auto @@ -99,11 +108,9 @@ impl ValueEnum for ColorChoice { 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"), + Self::Auto => PossibleValue::new("auto"), + Self::Always => PossibleValue::new("always"), + Self::Never => PossibleValue::new("never"), }) } }