Same with UseColor
This commit is contained in:
parent
b80fb1e879
commit
48cc69d851
10
src/color.rs
10
src/color.rs
@ -38,6 +38,7 @@ impl Color {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
pub(crate) fn always() -> Self {
|
pub(crate) fn always() -> Self {
|
||||||
Self {
|
Self {
|
||||||
use_color: UseColor::Always,
|
use_color: UseColor::Always,
|
||||||
@ -133,6 +134,15 @@ impl Color {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<UseColor> for Color {
|
||||||
|
fn from(value: UseColor) -> Self {
|
||||||
|
Self {
|
||||||
|
use_color: value,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for Color {
|
impl Default for Color {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -109,10 +109,7 @@ mod arg {
|
|||||||
pub(crate) const WORKING_DIRECTORY: &str = "WORKING-DIRECTORY";
|
pub(crate) const WORKING_DIRECTORY: &str = "WORKING-DIRECTORY";
|
||||||
pub(crate) const YES: &str = "YES";
|
pub(crate) const YES: &str = "YES";
|
||||||
|
|
||||||
pub(crate) const COLOR_ALWAYS: &str = "always";
|
|
||||||
pub(crate) const COLOR_AUTO: &str = "auto";
|
pub(crate) const COLOR_AUTO: &str = "auto";
|
||||||
pub(crate) const COLOR_NEVER: &str = "never";
|
|
||||||
pub(crate) const COLOR_VALUES: &[&str] = &[COLOR_AUTO, COLOR_ALWAYS, COLOR_NEVER];
|
|
||||||
|
|
||||||
pub(crate) const COMMAND_COLOR_BLACK: &str = "black";
|
pub(crate) const COMMAND_COLOR_BLACK: &str = "black";
|
||||||
pub(crate) const COMMAND_COLOR_BLUE: &str = "blue";
|
pub(crate) const COMMAND_COLOR_BLUE: &str = "blue";
|
||||||
@ -182,7 +179,7 @@ impl Config {
|
|||||||
.long("color")
|
.long("color")
|
||||||
.env("JUST_COLOR")
|
.env("JUST_COLOR")
|
||||||
.action(ArgAction::Set)
|
.action(ArgAction::Set)
|
||||||
.value_parser(PossibleValuesParser::new(arg::COLOR_VALUES))
|
.value_parser(clap::value_parser!(UseColor))
|
||||||
.default_value(arg::COLOR_AUTO)
|
.default_value(arg::COLOR_AUTO)
|
||||||
.help("Print colorful output"),
|
.help("Print colorful output"),
|
||||||
)
|
)
|
||||||
@ -529,23 +526,6 @@ impl Config {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn color_from_matches(matches: &ArgMatches) -> ConfigResult<Color> {
|
|
||||||
let value = matches
|
|
||||||
.get_one::<String>(arg::COLOR)
|
|
||||||
.ok_or_else(|| ConfigError::Internal {
|
|
||||||
message: "`--color` had no value".to_string(),
|
|
||||||
})?;
|
|
||||||
|
|
||||||
match value.as_str() {
|
|
||||||
arg::COLOR_AUTO => Ok(Color::auto()),
|
|
||||||
arg::COLOR_ALWAYS => Ok(Color::always()),
|
|
||||||
arg::COLOR_NEVER => Ok(Color::never()),
|
|
||||||
_ => Err(ConfigError::Internal {
|
|
||||||
message: format!("Invalid argument `{value}` to --color."),
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn command_color_from_matches(matches: &ArgMatches) -> ConfigResult<Option<ansi_term::Color>> {
|
fn command_color_from_matches(matches: &ArgMatches) -> ConfigResult<Option<ansi_term::Color>> {
|
||||||
if let Some(value) = matches.get_one::<String>(arg::COMMAND_COLOR) {
|
if let Some(value) = matches.get_one::<String>(arg::COMMAND_COLOR) {
|
||||||
match value.as_str() {
|
match value.as_str() {
|
||||||
@ -727,7 +707,7 @@ impl Config {
|
|||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
check: matches.get_flag(arg::CHECK),
|
check: matches.get_flag(arg::CHECK),
|
||||||
color: Self::color_from_matches(matches)?,
|
color: (*matches.get_one::<UseColor>(arg::COLOR).unwrap()).into(),
|
||||||
command_color: Self::command_color_from_matches(matches)?,
|
command_color: Self::command_color_from_matches(matches)?,
|
||||||
dotenv_filename: matches
|
dotenv_filename: matches
|
||||||
.get_one::<String>(arg::DOTENV_FILENAME)
|
.get_one::<String>(arg::DOTENV_FILENAME)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Copy, Clone, Debug, PartialEq, clap::ValueEnum)]
|
||||||
pub(crate) enum UseColor {
|
pub(crate) enum UseColor {
|
||||||
Auto,
|
Auto,
|
||||||
Always,
|
Always,
|
||||||
|
Loading…
Reference in New Issue
Block a user