@@ -42,13 +42,13 @@ import (
42
42
"github.com/arduino/arduino-cli/cli/upgrade"
43
43
"github.com/arduino/arduino-cli/cli/upload"
44
44
"github.com/arduino/arduino-cli/cli/version"
45
+ "github.com/arduino/arduino-cli/configuration"
45
46
"github.com/arduino/arduino-cli/i18n"
46
47
"github.com/arduino/arduino-cli/inventory"
47
48
"github.com/mattn/go-colorable"
48
49
"github.com/rifflock/lfshook"
49
50
"github.com/sirupsen/logrus"
50
51
"github.com/spf13/cobra"
51
- "github.com/spf13/viper"
52
52
)
53
53
54
54
var (
@@ -99,15 +99,12 @@ func createCliCommandTree(cmd *cobra.Command) {
99
99
100
100
cmd .PersistentFlags ().BoolVarP (& verbose , "verbose" , "v" , false , "Print the logs on the standard output." )
101
101
cmd .PersistentFlags ().String ("log-level" , "" , "Messages with this level and above will be logged. Valid levels are: trace, debug, info, warn, error, fatal, panic" )
102
- viper .BindPFlag ("logging.level" , cmd .PersistentFlags ().Lookup ("log-level" ))
103
102
cmd .PersistentFlags ().String ("log-file" , "" , "Path to the file where logs will be written." )
104
- viper .BindPFlag ("logging.file" , cmd .PersistentFlags ().Lookup ("log-file" ))
105
103
cmd .PersistentFlags ().String ("log-format" , "" , "The output format for the logs, can be {text|json}." )
106
- viper .BindPFlag ("logging.format" , cmd .PersistentFlags ().Lookup ("log-format" ))
107
104
cmd .PersistentFlags ().StringVar (& outputFormat , "format" , "text" , "The output format, can be {text|json}." )
108
105
cmd .PersistentFlags ().StringVar (& configFile , "config-file" , "" , "The custom config file (if not specified the default will be used)." )
109
106
cmd .PersistentFlags ().StringSlice ("additional-urls" , []string {}, "Comma-separated list of additional URLs for the Boards Manager." )
110
- viper . BindPFlag ( "board_manager.additional_urls" , cmd . PersistentFlags (). Lookup ( "additional-urls" ) )
107
+ configuration . BindFlags ( cmd , configuration . Settings )
111
108
}
112
109
113
110
// convert the string passed to the `--log-level` option to the corresponding
@@ -136,10 +133,10 @@ func parseFormatString(arg string) (feedback.OutputFormat, bool) {
136
133
}
137
134
138
135
func preRun (cmd * cobra.Command , args []string ) {
139
- configFile := viper .ConfigFileUsed ()
136
+ configFile := configuration . Settings .ConfigFileUsed ()
140
137
141
138
// initialize inventory
142
- inventory .Init (viper .GetString ("directories.Data" ))
139
+ inventory .Init (configuration . Settings .GetString ("directories.Data" ))
143
140
144
141
//
145
142
// Prepare logging
@@ -157,13 +154,13 @@ func preRun(cmd *cobra.Command, args []string) {
157
154
}
158
155
159
156
// set the Logger format
160
- logFormat := strings .ToLower (viper .GetString ("logging.format" ))
157
+ logFormat := strings .ToLower (configuration . Settings .GetString ("logging.format" ))
161
158
if logFormat == "json" {
162
159
logrus .SetFormatter (& logrus.JSONFormatter {})
163
160
}
164
161
165
162
// should we log to file?
166
- logFile := viper .GetString ("logging.file" )
163
+ logFile := configuration . Settings .GetString ("logging.file" )
167
164
if logFile != "" {
168
165
file , err := os .OpenFile (logFile , os .O_CREATE | os .O_WRONLY | os .O_APPEND , 0666 )
169
166
if err != nil {
@@ -180,8 +177,8 @@ func preRun(cmd *cobra.Command, args []string) {
180
177
}
181
178
182
179
// configure logging filter
183
- if lvl , found := toLogLevel (viper .GetString ("logging.level" )); ! found {
184
- feedback .Errorf ("Invalid option for --log-level: %s" , viper .GetString ("logging.level" ))
180
+ if lvl , found := toLogLevel (configuration . Settings .GetString ("logging.level" )); ! found {
181
+ feedback .Errorf ("Invalid option for --log-level: %s" , configuration . Settings .GetString ("logging.level" ))
185
182
os .Exit (errorcodes .ErrBadArgument )
186
183
} else {
187
184
logrus .SetLevel (lvl )
0 commit comments