@@ -42,13 +42,13 @@ import (
4242 "github.com/arduino/arduino-cli/cli/upgrade"
4343 "github.com/arduino/arduino-cli/cli/upload"
4444 "github.com/arduino/arduino-cli/cli/version"
45+ "github.com/arduino/arduino-cli/configuration"
4546 "github.com/arduino/arduino-cli/i18n"
4647 "github.com/arduino/arduino-cli/inventory"
4748 "github.com/mattn/go-colorable"
4849 "github.com/rifflock/lfshook"
4950 "github.com/sirupsen/logrus"
5051 "github.com/spf13/cobra"
51- "github.com/spf13/viper"
5252)
5353
5454var (
@@ -99,15 +99,12 @@ func createCliCommandTree(cmd *cobra.Command) {
9999
100100 cmd .PersistentFlags ().BoolVarP (& verbose , "verbose" , "v" , false , "Print the logs on the standard output." )
101101 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" ))
103102 cmd .PersistentFlags ().String ("log-file" , "" , "Path to the file where logs will be written." )
104- viper .BindPFlag ("logging.file" , cmd .PersistentFlags ().Lookup ("log-file" ))
105103 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" ))
107104 cmd .PersistentFlags ().StringVar (& outputFormat , "format" , "text" , "The output format, can be {text|json}." )
108105 cmd .PersistentFlags ().StringVar (& configFile , "config-file" , "" , "The custom config file (if not specified the default will be used)." )
109106 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 )
111108}
112109
113110// convert the string passed to the `--log-level` option to the corresponding
@@ -136,10 +133,10 @@ func parseFormatString(arg string) (feedback.OutputFormat, bool) {
136133}
137134
138135func preRun (cmd * cobra.Command , args []string ) {
139- configFile := viper .ConfigFileUsed ()
136+ configFile := configuration . Settings .ConfigFileUsed ()
140137
141138 // initialize inventory
142- inventory .Init (viper .GetString ("directories.Data" ))
139+ inventory .Init (configuration . Settings .GetString ("directories.Data" ))
143140
144141 //
145142 // Prepare logging
@@ -157,13 +154,13 @@ func preRun(cmd *cobra.Command, args []string) {
157154 }
158155
159156 // set the Logger format
160- logFormat := strings .ToLower (viper .GetString ("logging.format" ))
157+ logFormat := strings .ToLower (configuration . Settings .GetString ("logging.format" ))
161158 if logFormat == "json" {
162159 logrus .SetFormatter (& logrus.JSONFormatter {})
163160 }
164161
165162 // should we log to file?
166- logFile := viper .GetString ("logging.file" )
163+ logFile := configuration . Settings .GetString ("logging.file" )
167164 if logFile != "" {
168165 file , err := os .OpenFile (logFile , os .O_CREATE | os .O_WRONLY | os .O_APPEND , 0666 )
169166 if err != nil {
@@ -180,8 +177,8 @@ func preRun(cmd *cobra.Command, args []string) {
180177 }
181178
182179 // 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" ))
185182 os .Exit (errorcodes .ErrBadArgument )
186183 } else {
187184 logrus .SetLevel (lvl )
0 commit comments