@@ -32,7 +32,6 @@ package root
32
32
import (
33
33
"io/ioutil"
34
34
"os"
35
- "strings"
36
35
37
36
"github.com/bcmi-labs/arduino-cli/commands"
38
37
"github.com/bcmi-labs/arduino-cli/commands/board"
@@ -51,7 +50,6 @@ import (
51
50
"github.com/bcmi-labs/arduino-cli/configs"
52
51
"github.com/sirupsen/logrus"
53
52
"github.com/spf13/cobra"
54
- "github.com/spf13/viper"
55
53
)
56
54
57
55
const (
@@ -89,12 +87,8 @@ const (
89
87
}`
90
88
)
91
89
92
- var isTesting = false
93
-
94
90
// Init prepares the command.
95
- func Init (_isTesting bool ) {
96
- // Forward the testing status
97
- isTesting = _isTesting
91
+ func Init () {
98
92
99
93
Command .PersistentFlags ().BoolVar (& commands .GlobalFlags .Debug , "debug" , false , "Enables debug output (super verbose, used to debug the CLI)." )
100
94
Command .PersistentFlags ().StringVar (& commands .GlobalFlags .Format , "format" , "text" , "The output format, can be [text|json]." )
@@ -149,11 +143,6 @@ func preRun(cmd *cobra.Command, args []string) {
149
143
os .Exit (commands .ErrBadCall )
150
144
})
151
145
}
152
-
153
- if ! isTesting {
154
- logrus .Info ("Initializing viper configuration" )
155
- cobra .OnInitialize (initViper )
156
- }
157
146
}
158
147
159
148
// initConfigs initializes the configuration from the specified file.
@@ -175,72 +164,3 @@ func initConfigs() {
175
164
configs .LoadFromEnv ()
176
165
logrus .Info ("Configuration set" )
177
166
}
178
-
179
- func initViper () {
180
- logrus .Info ("Initiating viper config" )
181
-
182
- defHome , err := configs .ArduinoHomeFolder .Get ()
183
- if err != nil {
184
- commands .ErrLogrus .WithError (err ).Warn ("Cannot get default Arduino Home" )
185
- }
186
- defArduinoData , err := configs .ArduinoDataFolder .Get ()
187
- if err != nil {
188
- logrus .WithError (err ).Warn ("Cannot get default Arduino folder" )
189
- }
190
-
191
- viper .SetConfigName (".cli-config" )
192
- viper .AddConfigPath ("." )
193
- viper .SetConfigType ("yaml" )
194
-
195
- logrus .Info ("Reading configuration for viper" )
196
- err = viper .ReadInConfig ()
197
- if err != nil {
198
- formatter .PrintError (err , "Cannot read configuration file in any of the default folders." )
199
- os .Exit (commands .ErrNoConfigFile )
200
- }
201
-
202
- logrus .Info ("Setting defaults" )
203
- viper .SetDefault ("paths.sketchbook" , defHome )
204
- viper .SetDefault ("paths.arduino_data" , defArduinoData )
205
- viper .SetDefault ("proxy.type" , "auto" )
206
- viper .SetDefault ("proxy.hostname" , "" )
207
- viper .SetDefault ("proxy.username" , "" )
208
- viper .SetDefault ("proxy.password" , "" )
209
-
210
- viper .AutomaticEnv ()
211
-
212
- logrus .Info ("Setting proxy" )
213
- if viper .GetString ("proxy.type" ) == "manual" {
214
- hostname := viper .GetString ("proxy.hostname" )
215
- if hostname == "" {
216
- commands .ErrLogrus .Error ("With manual proxy configuration, hostname is required." )
217
- formatter .PrintErrorMessage ("With manual proxy configuration, hostname is required." )
218
- os .Exit (commands .ErrCoreConfig )
219
- }
220
-
221
- if strings .HasPrefix (hostname , "http" ) {
222
- os .Setenv ("HTTP_PROXY" , hostname )
223
- }
224
- if strings .HasPrefix (hostname , "https" ) {
225
- os .Setenv ("HTTPS_PROXY" , hostname )
226
- }
227
-
228
- username := viper .GetString ("proxy.username" )
229
- if username != "" { // Put username and pass somewhere.
230
-
231
- }
232
- }
233
- logrus .Info ("Done viper configuration loading" )
234
- }
235
-
236
- // TestInit creates an initialization for tests.
237
- // FIXME: is this any useful?
238
- func TestInit () {
239
- initConfigs ()
240
-
241
- cobra .OnInitialize (func () {
242
- viper .SetConfigFile ("./test-config.yml" )
243
- })
244
-
245
- isTesting = true
246
- }
0 commit comments