fix: honor NO_COLOR specification#1067
Conversation
|
Thanks for the PR. I'm not sure this is the right approach though. This adds another parser (based on the env-var). This parser would, to my understanding, also set "no color" in the case the value is "0", which is clearly against what no-color.org shows in their example. I think the implementation could look something like: fn no_color_value(s: &str) -> Result<bool, String> {
Ok(!matches!(s.to_ascii_lowercase().as_str(), "false" | "0"))
}
#[derive(Parser)]
struct Args {
#[arg(
long,
env = "NO_COLOR",
action = ArgAction::Set,
num_args = 0..=1,
require_equals = true,
default_missing_value = "true",
default_value_t = false,
value_parser = no_color_value,
)]
no_color: bool,
} |
|
Thanks for reviewing! That's the https://no-color.org/ example: char *no_color = getenv("NO_COLOR");
bool color = true;
if (no_color != NULL && no_color[0] != '\0')
color = false;This checks for a null-terminated empty string, which is distinct from the string "0" (a string containing the character zero). This is consistent with the specification's description::
Everything else makes sense. I'll update the PR. |
|
On second thought, I think that having |
Fixes #1065