feat(cli): Add NO_COLOR support (#779)

This commit is contained in:
Félix Saparelli 2024-02-11 18:13:41 +13:00 committed by GitHub
parent 8b39279423
commit 1846c96b86
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 1 deletions

View File

@ -1,4 +1,3 @@
-D clippy::all
-W clippy::nursery
-W clippy::pedantic
-A clippy::module-name-repetitions
@ -10,3 +9,4 @@
-A clippy::default-trait-access
-A clippy::enum-glob-use
-A clippy::option-if-let-else
-A clippy::blocks-in-conditions

View File

@ -680,6 +680,8 @@ pub struct Args {
pub notify: bool,
/// When to use terminal colours
///
/// Setting the environment variable `NO_COLOR` to any value is equivalent to `--color=never`.
#[arg(
long,
help_heading = OPTSET_OUTPUT,
@ -1104,6 +1106,11 @@ pub fn get_args() -> Args {
debug!("parsing arguments");
let mut args = Args::parse_from(args);
// https://no-color.org/
if args.color == ColourMode::Auto && std::env::var("NO_COLOR").is_ok() {
args.color = ColourMode::Never;
}
if args.ignore_nothing {
args.no_global_ignore = true;
args.no_vcs_ignore = true;

View File

@ -385,6 +385,8 @@ With this, Watchexec will emit a desktop notification when a command starts and
.TP
\fB\-\-color\fR=\fIMODE\fR [default: auto]
When to use terminal colours
Setting the environment variable `NO_COLOR` to any value is equivalent to `\-\-color=never`.
.TP
\fB\-\-timings\fR
Print how long the command took to run

View File

@ -536,6 +536,9 @@ may silently do nothing, or log a warning.
: When to use terminal colours
Setting the environment variable \`NO_COLOR\` to any value is equivalent
to \`\--color=never\`.
**\--timings**
: Print how long the command took to run