From 7da8de0ae5ca9ca9858a4e908b6a2840cc83ab3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Ferrero?= Date: Sun, 29 Dec 2024 21:32:49 +0100 Subject: [PATCH] Simplify $opt{color} and patch $opt{nocolor} option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit · Line 236 duplicated. · Set $opt{color} the test default option. · Line $opt{nocolor} = 1 unless (-t STDOUT), duplicated at default values section · Remove some parenthesis --- mysqltuner.pl | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/mysqltuner.pl b/mysqltuner.pl index ba1f9b86..c13027ef 100755 --- a/mysqltuner.pl +++ b/mysqltuner.pl @@ -234,7 +234,6 @@ package main; $opt{cvefile} = 'vulnerabilities.csv'; #CVE File for vulnerability checks } $opt{noprettyicon}=0 if $opt{noprettyicon}!=1; -$opt{nocolor} = 1 if defined( $opt{outputfile} ); $opt{tbstat} = 0 if ( $opt{notbstat} == 1 ); # Don't print table information $opt{colstat} = 0 if ( $opt{nocolstat} == 1 ); # Don't print column information $opt{dbstat} = 0 if ( $opt{nodbstat} == 1 ); # Don't print database information @@ -269,22 +268,20 @@ package main; open( $fh, '>', $outputfile ) or die("Fail opening $outputfile") if defined($outputfile); -$opt{nocolor} = 1 if defined($outputfile); -$opt{nocolor} = 1 unless ( -t STDOUT ); - -$opt{nocolor} = 0 if ( $opt{color} == 1 ); # Setting up the colors for the print styles +$opt{nocolor} = 1 if defined($outputfile); +$opt{color} = 0 if $opt{nocolor} == 1; + my $me = `whoami`; $me =~ s/\n//g; - -my $good = ( $opt{nocolor} == 0 ) ? "[\e[0;32mOK\e[0m]" : "[OK]"; -my $bad = ( $opt{nocolor} == 0 ) ? "[\e[0;31m!!\e[0m]" : "[!!]"; -my $info = ( $opt{nocolor} == 0 ) ? "[\e[0;34m--\e[0m]" : "[--]"; -my $deb = ( $opt{nocolor} == 0 ) ? "[\e[0;31mDG\e[0m]" : "[DG]"; -my $cmd = ( $opt{nocolor} == 0 ) ? "\e[1;32m[CMD]($me)" : "[CMD]($me)"; -my $end = ( $opt{nocolor} == 0 ) ? "\e[0m" : ""; +my $good = $opt{color} ? "[\e[0;32mOK\e[0m]" : "[OK]"; +my $bad = $opt{color} ? "[\e[0;31m!!\e[0m]" : "[!!]"; +my $info = $opt{color} ? "[\e[0;34m--\e[0m]" : "[--]"; +my $deb = $opt{color} ? "[\e[0;31mDG\e[0m]" : "[DG]"; +my $cmd = $opt{color} ? "\e[1;32m[CMD]($me)" : "[CMD]($me)"; +my $end = $opt{color} ? "\e[0m" : ""; if ($opt{noprettyicon} == 0) { $good = "✔ "; @@ -333,11 +330,11 @@ sub debugprint { } sub redwrap { - return ( $opt{nocolor} == 0 ) ? "\e[0;31m" . $_[0] . "\e[0m" : $_[0]; + return $opt{color} ? "\e[0;31m" . $_[0] . "\e[0m" : $_[0]; } sub greenwrap { - return ( $opt{nocolor} == 0 ) ? "\e[0;32m" . $_[0] . "\e[0m" : $_[0]; + return $opt{color} ? "\e[0;32m" . $_[0] . "\e[0m" : $_[0]; } sub cmdprint {