@@ -45,6 +45,7 @@ import (
45
45
"github.com/arduino/arduino-cli/configuration"
46
46
"github.com/arduino/arduino-cli/i18n"
47
47
"github.com/arduino/arduino-cli/inventory"
48
+ "github.com/fatih/color"
48
49
"github.com/mattn/go-colorable"
49
50
"github.com/rifflock/lfshook"
50
51
"github.com/sirupsen/logrus"
@@ -104,6 +105,7 @@ func createCliCommandTree(cmd *cobra.Command) {
104
105
cmd .PersistentFlags ().StringVar (& outputFormat , "format" , "text" , fmt .Sprintf (tr ("The output format, can be {%s|%s}." ), "text" , "json" ))
105
106
cmd .PersistentFlags ().StringVar (& configFile , "config-file" , "" , tr ("The custom config file (if not specified the default will be used)." ))
106
107
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." )
107
109
configuration .BindFlags (cmd , configuration .Settings )
108
110
}
109
111
@@ -142,6 +144,13 @@ func preRun(cmd *cobra.Command, args []string) {
142
144
os .Exit (errorcodes .ErrBadArgument )
143
145
}
144
146
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
+
145
154
//
146
155
// Prepare logging
147
156
//
@@ -151,7 +160,8 @@ func preRun(cmd *cobra.Command, args []string) {
151
160
// if we print on stdout, do it in full colors
152
161
logrus .SetOutput (colorable .NewColorableStdout ())
153
162
logrus .SetFormatter (& logrus.TextFormatter {
154
- ForceColors : true ,
163
+ ForceColors : true ,
164
+ DisableColors : color .NoColor ,
155
165
})
156
166
} else {
157
167
logrus .SetOutput (ioutil .Discard )
0 commit comments