@@ -45,6 +45,7 @@ import (
4545 "github.com/arduino/arduino-cli/configuration"
4646 "github.com/arduino/arduino-cli/i18n"
4747 "github.com/arduino/arduino-cli/inventory"
48+ "github.com/fatih/color"
4849 "github.com/mattn/go-colorable"
4950 "github.com/rifflock/lfshook"
5051 "github.com/sirupsen/logrus"
@@ -104,6 +105,7 @@ func createCliCommandTree(cmd *cobra.Command) {
104105 cmd .PersistentFlags ().StringVar (& outputFormat , "format" , "text" , fmt .Sprintf (tr ("The output format, can be {%s|%s}." ), "text" , "json" ))
105106 cmd .PersistentFlags ().StringVar (& configFile , "config-file" , "" , tr ("The custom config file (if not specified the default will be used)." ))
106107 cmd .PersistentFlags ().StringSlice ("additional-urls" , []string {}, tr ("Comma-separated list of additional URLs for the Boards Manager." ))
108+ cmd .PersistentFlags ().Bool ("no-color" , false , "Disable colored output." )
107109 configuration .BindFlags (cmd , configuration .Settings )
108110}
109111
@@ -142,6 +144,13 @@ func preRun(cmd *cobra.Command, args []string) {
142144 os .Exit (errorcodes .ErrBadArgument )
143145 }
144146
147+ // https://no-color.org/
148+ color .NoColor = configuration .Settings .GetBool ("output.no_color" ) || os .Getenv ("NO_COLOR" ) != ""
149+
150+ // Set default feedback output to colorable
151+ feedback .SetOut (colorable .NewColorableStdout ())
152+ feedback .SetErr (colorable .NewColorableStderr ())
153+
145154 //
146155 // Prepare logging
147156 //
@@ -151,7 +160,8 @@ func preRun(cmd *cobra.Command, args []string) {
151160 // if we print on stdout, do it in full colors
152161 logrus .SetOutput (colorable .NewColorableStdout ())
153162 logrus .SetFormatter (& logrus.TextFormatter {
154- ForceColors : true ,
163+ ForceColors : true ,
164+ DisableColors : color .NoColor ,
155165 })
156166 } else {
157167 logrus .SetOutput (ioutil .Discard )
0 commit comments