Prompt
When implementing environment variable configuration:
- Follow standard environment variable conventions:
- Use uppercase with underscores (e.g.,
NO_COLOR,FORCE_COLOR) - Validate non-empty values for boolean flags
- Support standard environment variables where applicable (e.g.,
NO_COLOR,FORCE_COLOR,CLICOLOR_FORCE)
- Use uppercase with underscores (e.g.,
- Document environment variables clearly:
- Specify expected value formats and constraints
- Document the precedence order when multiple configuration methods exist
- Include examples of valid values
Example:
// Bad - No validation or documentation
if std::env::var_os("FORCE_COLOR").is_some() {
ColorChoice::Always
}
// Good - Validates non-empty value and documents behavior
/// Controls color output. When set to a non-empty value, forces color output
/// regardless of terminal capabilities.
/// Takes precedence over NO_COLOR and --color settings.
if let Some(force_color) = std::env::var_os("FORCE_COLOR") {
if !force_color.is_empty() {
ColorChoice::Always
}
}
- Establish clear precedence rules:
- Document which settings take precedence (e.g., CLI flags vs environment variables)
- Consider standard environment variables first
- Fall back to custom environment variables before defaults
- Provide validation and feedback:
- Validate environment variable values early
- Provide clear error messages for invalid values
- Consider warning on deprecated or conflicting configurations