Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ValueEnum for ColorChoice #4445

Merged
merged 1 commit into from Nov 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions 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 {
Expand Down Expand Up @@ -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"),
})
}
}