@@ -33,6 +33,7 @@ import (
3333 "github.com/arduino/arduino-cli/cli/generatedocs"
3434 "github.com/arduino/arduino-cli/cli/globals"
3535 "github.com/arduino/arduino-cli/cli/lib"
36+ "github.com/arduino/arduino-cli/cli/output"
3637 "github.com/arduino/arduino-cli/cli/sketch"
3738 "github.com/arduino/arduino-cli/cli/upload"
3839 "github.com/arduino/arduino-cli/cli/version"
5253 PersistentPreRun : preRun ,
5354 }
5455
55- verbose bool
56- logFile string
57- logFormat string
56+ verbose bool
57+ logFile string
58+ logFormat string
59+ outputFormat string
5860)
5961
6062const (
@@ -83,7 +85,7 @@ func createCliCommandTree(cmd *cobra.Command) {
8385 cmd .PersistentFlags ().StringVar (& globals .LogLevel , "log-level" , defaultLogLevel , "Messages with this level and above will be logged (default: warn)." )
8486 cmd .PersistentFlags ().StringVar (& logFile , "log-file" , "" , "Path to the file where logs will be written." )
8587 cmd .PersistentFlags ().StringVar (& logFormat , "log-format" , "text" , "The output format for the logs, can be [text|json]." )
86- cmd .PersistentFlags ().StringVar (& globals . OutputFormat , "format" , "text" , "The output format, can be [text|json]." )
88+ cmd .PersistentFlags ().StringVar (& outputFormat , "format" , "text" , "The output format, can be [text|json]." )
8789 cmd .PersistentFlags ().StringVar (& globals .YAMLConfigFile , "config-file" , "" , "The custom config file (if not specified the default will be used)." )
8890 cmd .PersistentFlags ().StringSliceVar (& globals .AdditionalUrls , "additional-urls" , []string {}, "Additional URLs for the board manager." )
8991}
@@ -115,7 +117,9 @@ func parseFormatString(arg string) (feedback.OutputFormat, bool) {
115117
116118func preRun (cmd * cobra.Command , args []string ) {
117119 // normalize the format strings
118- globals .OutputFormat = strings .ToLower (globals .OutputFormat )
120+ outputFormat = strings .ToLower (outputFormat )
121+ // configure the output package
122+ output .OutputFormat = outputFormat
119123 logFormat = strings .ToLower (logFormat )
120124
121125 // should we log to file?
@@ -159,9 +163,9 @@ func preRun(cmd *cobra.Command, args []string) {
159163 }
160164
161165 // check the right output format was passed
162- format , found := parseFormatString (globals . OutputFormat )
166+ format , found := parseFormatString (outputFormat )
163167 if ! found {
164- feedback .Error ("Invalid output format: " + globals . OutputFormat )
168+ feedback .Error ("Invalid output format: " + outputFormat )
165169 os .Exit (errorcodes .ErrBadCall )
166170 }
167171
@@ -174,7 +178,7 @@ func preRun(cmd *cobra.Command, args []string) {
174178 logrus .Info ("Starting root command preparation (`arduino`)" )
175179
176180 logrus .Info ("Formatter set" )
177- if globals . OutputFormat != "text" {
181+ if outputFormat != "text" {
178182 cmd .SetHelpFunc (func (cmd * cobra.Command , args []string ) {
179183 logrus .Warn ("Calling help on JSON format" )
180184 feedback .Error ("Invalid Call : should show Help, but it is available only in TEXT mode." )
0 commit comments