Skip to content

Commit 079109f

Browse files
committed
move vars to global
1 parent 10aa952 commit 079109f

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

cli/cli.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import (
2525

2626
"github.com/arduino/arduino-fwuploader/cli/certificates"
2727
"github.com/arduino/arduino-fwuploader/cli/common"
28+
"github.com/arduino/arduino-fwuploader/cli/feedback"
2829
"github.com/arduino/arduino-fwuploader/cli/firmware"
30+
"github.com/arduino/arduino-fwuploader/cli/globals"
2931
"github.com/arduino/arduino-fwuploader/cli/version"
30-
31-
"github.com/arduino/arduino-fwuploader/cli/feedback"
3232
v "github.com/arduino/arduino-fwuploader/version"
3333
"github.com/mattn/go-colorable"
3434
"github.com/rifflock/lfshook"
@@ -38,10 +38,8 @@ import (
3838

3939
var (
4040
outputFormat string
41-
verbose bool
4241
logFile string
4342
logFormat string
44-
logLevel string
4543
additionalFirmwareURLs []string
4644
additionalPackageURLs []string
4745
)
@@ -64,8 +62,8 @@ func NewCommand() *cobra.Command {
6462
rootCmd.PersistentFlags().StringVar(&outputFormat, "format", "text", "The output format, can be {text|json}.")
6563
rootCmd.PersistentFlags().StringVar(&logFile, "log-file", "", "Path to the file where logs will be written")
6664
rootCmd.PersistentFlags().StringVar(&logFormat, "log-format", "", "The output format for the logs, can be {text|json}.")
67-
rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "info", "Messages with this level and above will be logged. Valid levels are: trace, debug, info, warn, error, fatal, panic")
68-
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Print the logs on the standard output.")
65+
rootCmd.PersistentFlags().StringVar(&globals.LogLevel, "log-level", "info", "Messages with this level and above will be logged. Valid levels are: trace, debug, info, warn, error, fatal, panic")
66+
rootCmd.PersistentFlags().BoolVarP(&globals.Verbose, "verbose", "v", false, "Print the logs on the standard output.")
6967
rootCmd.PersistentFlags().StringArrayVarP(&additionalFirmwareURLs, "additional-fw-index", "F", nil, "Additional firmwares index URLs (useful for testing purposes)")
7068
rootCmd.PersistentFlags().StringArrayVarP(&additionalPackageURLs, "additional-packages-index", "P", nil, "Additional packages index URLs (useful for testing purposes)")
7169
return rootCmd
@@ -97,7 +95,7 @@ func preRun(cmd *cobra.Command, args []string) {
9795
feedback.SetFormat(format)
9896

9997
// Prepare logging
100-
if verbose {
98+
if globals.Verbose {
10199
// if we print on stdout, do it in full colors
102100
logrus.SetOutput(colorable.NewColorableStdout())
103101
logrus.SetFormatter(&logrus.TextFormatter{
@@ -128,8 +126,8 @@ func preRun(cmd *cobra.Command, args []string) {
128126
}
129127

130128
// Configure logging filter
131-
if lvl, found := toLogLevel(logLevel); !found {
132-
feedback.Fatal(fmt.Sprintf("Invalid option for --log-level: %s", logLevel), feedback.ErrBadArgument)
129+
if lvl, found := toLogLevel(globals.LogLevel); !found {
130+
feedback.Fatal(fmt.Sprintf("Invalid option for --log-level: %s", globals.LogLevel), feedback.ErrBadArgument)
133131
} else {
134132
logrus.SetLevel(lvl)
135133
}

cli/globals/globals.go

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ var (
2929
ModuleFirmwareIndexGZURL = "https://downloads.arduino.cc/arduino-fwuploader/boards/module_firmware_index.json.gz"
3030
PluginFirmwareIndexGZURL = "https://downloads.arduino.cc/arduino-fwuploader/boards/plugin_firmware_index.json.gz"
3131
FwUploaderPath = paths.TempDir().Join("fwuploader")
32+
Verbose bool
33+
LogLevel string
3234
)
3335

3436
//go:embed keys/*

0 commit comments

Comments
 (0)