All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] checkpatch: Change format of --color argument to --color[=WHEN]
@ 2017-06-05 22:27 John Brooks
  2017-06-05 23:10 ` Joe Perches
  0 siblings, 1 reply; 10+ messages in thread
From: John Brooks @ 2017-06-05 22:27 UTC (permalink / raw)
  To: Andy Whitcroft, Joe Perches; +Cc: linux-kernel

The boolean --color argument did not offer the ability to force colourized
output even if stdout is not a terminal. Change the format of the argument
to the familiar --color[=WHEN] construct as seen in common Linux utilities
such as ls and dmesg, which allows the user to specify whether to colourize
output always, never, or only when the output is a terminal ("auto").

Because the option is no longer boolean, --nocolor (or --no-color) is no
longer available. Users of the old negative option should use --color=never
instead.

Signed-off-by: John Brooks <john@fastquake.com>
---
 scripts/checkpatch.pl | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4b9569f..8099609 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -56,7 +56,7 @@ my $codespell = 0;
 my $codespellfile = "/usr/share/codespell/dictionary.txt";
 my $conststructsfile = "$D/const_structs.checkpatch";
 my $typedefsfile = "";
-my $color = 1;
+my $color = "auto";
 my $allow_c99_comments = 1;
 
 sub help {
@@ -115,7 +115,8 @@ Options:
                              (default:/usr/share/codespell/dictionary.txt)
   --codespellfile            Use this codespell dictionary
   --typedefsfile             Read additional types from this file
-  --color                    Use colors when output is STDOUT (default: on)
+  --color[=WHEN]             Use colors 'always', 'never', or only when output
+                             is a terminal ('auto'). Default is 'auto'.
   -h, --help, --version      display this help and exit
 
 When FILE is - read standard input.
@@ -211,7 +212,7 @@ GetOptions(
 	'codespell!'	=> \$codespell,
 	'codespellfile=s'	=> \$codespellfile,
 	'typedefsfile=s'	=> \$typedefsfile,
-	'color!'	=> \$color,
+	'color:s'	=> \$color,
 	'h|help'	=> \$help,
 	'version'	=> \$help
 ) or help(1);
@@ -237,6 +238,16 @@ if ($#ARGV < 0) {
 	push(@ARGV, '-');
 }
 
+if ($color eq "always") {
+	$color = 1;
+} elsif ($color eq "never") {
+	$color = 0;
+} elsif ($color eq "auto") {
+	$color = (-t STDOUT);
+} else {
+	die "Invalid color mode: $color\n";
+}
+
 sub hash_save_array_words {
 	my ($hashRef, $arrayRef) = @_;
 
@@ -1881,7 +1892,7 @@ sub report {
 		return 0;
 	}
 	my $output = '';
-	if (-t STDOUT && $color) {
+	if ($color) {
 		if ($level eq 'ERROR') {
 			$output .= RED;
 		} elsif ($level eq 'WARNING') {
@@ -1892,10 +1903,10 @@ sub report {
 	}
 	$output .= $prefix . $level . ':';
 	if ($show_types) {
-		$output .= BLUE if (-t STDOUT && $color);
+		$output .= BLUE if ($color);
 		$output .= "$type:";
 	}
-	$output .= RESET if (-t STDOUT && $color);
+	$output .= RESET if ($color);
 	$output .= ' ' . $msg . "\n";
 
 	if ($showfile) {
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-06-07 13:41 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-05 22:27 [PATCH] checkpatch: Change format of --color argument to --color[=WHEN] John Brooks
2017-06-05 23:10 ` Joe Perches
2017-06-05 23:28   ` John Brooks
2017-06-06  5:48   ` Adam Borowski
2017-06-06 17:07   ` [PATCH v2] " John Brooks
2017-06-06 19:21     ` Joe Perches
2017-06-06 19:56       ` John Brooks
2017-06-06 20:03         ` Joe Perches
2017-06-07  1:50           ` [PATCH V3] " Joe Perches
2017-06-07 13:41             ` John Brooks

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.