@@ -33,6 +33,7 @@ import (
33
33
"github.com/arduino/arduino-cli/cli/generatedocs"
34
34
"github.com/arduino/arduino-cli/cli/globals"
35
35
"github.com/arduino/arduino-cli/cli/lib"
36
+ "github.com/arduino/arduino-cli/cli/output"
36
37
"github.com/arduino/arduino-cli/cli/sketch"
37
38
"github.com/arduino/arduino-cli/cli/upload"
38
39
"github.com/arduino/arduino-cli/cli/version"
52
53
PersistentPreRun : preRun ,
53
54
}
54
55
55
- verbose bool
56
- logFile string
57
- logFormat string
56
+ verbose bool
57
+ logFile string
58
+ logFormat string
59
+ outputFormat string
58
60
)
59
61
60
62
const (
@@ -83,7 +85,7 @@ func createCliCommandTree(cmd *cobra.Command) {
83
85
cmd .PersistentFlags ().StringVar (& globals .LogLevel , "log-level" , defaultLogLevel , "Messages with this level and above will be logged." )
84
86
cmd .PersistentFlags ().StringVar (& logFile , "log-file" , "" , "Path to the file where logs will be written." )
85
87
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]." )
87
89
cmd .PersistentFlags ().StringVar (& globals .YAMLConfigFile , "config-file" , "" , "The custom config file (if not specified the default will be used)." )
88
90
cmd .PersistentFlags ().StringSliceVar (& globals .AdditionalUrls , "additional-urls" , []string {}, "Additional URLs for the board manager." )
89
91
}
@@ -115,7 +117,9 @@ func parseFormatString(arg string) (feedback.OutputFormat, bool) {
115
117
116
118
func preRun (cmd * cobra.Command , args []string ) {
117
119
// 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
119
123
logFormat = strings .ToLower (logFormat )
120
124
121
125
// should we log to file?
@@ -159,9 +163,9 @@ func preRun(cmd *cobra.Command, args []string) {
159
163
}
160
164
161
165
// check the right output format was passed
162
- format , found := parseFormatString (globals . OutputFormat )
166
+ format , found := parseFormatString (outputFormat )
163
167
if ! found {
164
- feedback .Error ("Invalid output format: " + globals . OutputFormat )
168
+ feedback .Error ("Invalid output format: " + outputFormat )
165
169
os .Exit (errorcodes .ErrBadCall )
166
170
}
167
171
@@ -174,7 +178,7 @@ func preRun(cmd *cobra.Command, args []string) {
174
178
logrus .Info ("Starting root command preparation (`arduino`)" )
175
179
176
180
logrus .Info ("Formatter set" )
177
- if globals . OutputFormat != "text" {
181
+ if outputFormat != "text" {
178
182
cmd .SetHelpFunc (func (cmd * cobra.Command , args []string ) {
179
183
logrus .Warn ("Calling help on JSON format" )
180
184
feedback .Error ("Invalid Call : should show Help, but it is available only in TEXT mode." )
0 commit comments