Skip to content

Commit 6d37d8d

Browse files
committed
Removed useless viper configuration module
- The implementation is clearly a draft - We handle the global configuration by ourself with the `config` module
1 parent 523720c commit 6d37d8d

File tree

4 files changed

+3
-85
lines changed

4 files changed

+3
-85
lines changed

commands/commands_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func executeWithArgs(t *testing.T, args ...string) (exitCode int, output []byte)
9090

9191
// Init only once.
9292
if !root.Command.HasFlags() {
93-
root.Init(true)
93+
root.Init()
9494
}
9595
root.Command.SetArgs(args)
9696

commands/root/root.go

+1-81
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ package root
3232
import (
3333
"io/ioutil"
3434
"os"
35-
"strings"
3635

3736
"github.com/bcmi-labs/arduino-cli/commands"
3837
"github.com/bcmi-labs/arduino-cli/commands/board"
@@ -51,7 +50,6 @@ import (
5150
"github.com/bcmi-labs/arduino-cli/configs"
5251
"github.com/sirupsen/logrus"
5352
"github.com/spf13/cobra"
54-
"github.com/spf13/viper"
5553
)
5654

5755
const (
@@ -89,12 +87,8 @@ const (
8987
}`
9088
)
9189

92-
var isTesting = false
93-
9490
// Init prepares the command.
95-
func Init(_isTesting bool) {
96-
// Forward the testing status
97-
isTesting = _isTesting
91+
func Init() {
9892

9993
Command.PersistentFlags().BoolVar(&commands.GlobalFlags.Debug, "debug", false, "Enables debug output (super verbose, used to debug the CLI).")
10094
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) {
149143
os.Exit(commands.ErrBadCall)
150144
})
151145
}
152-
153-
if !isTesting {
154-
logrus.Info("Initializing viper configuration")
155-
cobra.OnInitialize(initViper)
156-
}
157146
}
158147

159148
// initConfigs initializes the configuration from the specified file.
@@ -175,72 +164,3 @@ func initConfigs() {
175164
configs.LoadFromEnv()
176165
logrus.Info("Configuration set")
177166
}
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-
}

configs/preferences_txt_serializer.go

-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import (
3838

3939
"github.com/arduino/go-properties-map"
4040
"github.com/sirupsen/logrus"
41-
"github.com/spf13/viper"
4241
)
4342

4443
var arduinoIDEDirectory *string
@@ -114,7 +113,6 @@ func proxyConfigsFromIDEPrefs(props properties.Map) error {
114113
switch proxy["type"] {
115114
case "auto":
116115
// Automatic proxy
117-
viper.Set("proxy.type", "auto")
118116
break
119117
case "manual":
120118
// Manual proxy configuration

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import (
3838
)
3939

4040
func main() {
41-
root.Init(false)
41+
root.Init()
4242
if err := root.Command.Execute(); err != nil {
4343
formatter.PrintError(err, "Bad exit.")
4444
os.Exit(commands.ErrGeneric)

0 commit comments

Comments
 (0)