Skip to content

Commit 6145d74

Browse files
committed
Correct order of preferences loading. Added more logging.
1 parent 4705594 commit 6145d74

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

commands/root/root.go

+28-13
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import (
2727

2828
"golang.org/x/crypto/ssh/terminal"
2929

30-
"github.com/mattn/go-colorable"
30+
colorable "github.com/mattn/go-colorable"
3131

32-
"github.com/arduino/go-paths-helper"
32+
paths "github.com/arduino/go-paths-helper"
3333

3434
"github.com/arduino/arduino-cli/commands"
3535
"github.com/arduino/arduino-cli/commands/board"
@@ -118,11 +118,15 @@ func preRun(cmd *cobra.Command, args []string) {
118118
// initConfigs initializes the configuration from the specified file.
119119
func initConfigs() {
120120
// Return error if an old configuration file is found
121-
if paths.New(".cli-config.yml").Exist() {
122-
logrus.Error("Old configuration file detected. Ensure you are using the new `arduino-cli.yaml` configuration")
123-
formatter.PrintError(fmt.Errorf("old configuration file detected"), "Ensure you are using the new `arduino-cli.yaml` configuration")
121+
if old := paths.New(".cli-config.yml"); old.Exist() {
122+
logrus.Errorf("Old configuration file detected: %s.", old)
123+
logrus.Info("The name of this file has been changed to `arduino-cli.yaml`, please rename the file fix it.")
124+
formatter.PrintError(
125+
fmt.Errorf("old configuration file detected: %s", old),
126+
"The name of this file has been changed to `arduino-cli.yaml`, please rename the file fix it.")
124127
os.Exit(commands.ErrGeneric)
125128
}
129+
126130
// Start with default configuration
127131
if conf, err := configs.NewConfiguration(); err != nil {
128132
logrus.WithError(err).Error("Error creating default configuration")
@@ -138,18 +142,14 @@ func initConfigs() {
138142
logrus.WithError(err).Warn("Did not manage to find current path")
139143
}
140144

141-
commands.Config.Navigate("/", pwd)
142-
commands.Config.LoadFromYAML(commands.Config.ConfigFile)
143-
144-
if yamlConfigFile != "" {
145-
commands.Config.ConfigFile = paths.New(yamlConfigFile)
145+
// Read configuration from global config file
146+
if commands.Config.ConfigFile.Exist() {
147+
logrus.Infof("Reading configuration from %s", commands.Config.ConfigFile)
146148
if err := commands.Config.LoadFromYAML(commands.Config.ConfigFile); err != nil {
147-
logrus.WithError(err).Warn("Did not manage to get config file, using default configuration")
149+
logrus.WithError(err).Warnf("Could not read configuration from %s", commands.Config.ConfigFile)
148150
}
149151
}
150152

151-
logrus.Info("Initiating configuration")
152-
153153
if commands.Config.IsBundledInDesktopIDE() {
154154
logrus.Info("CLI is bundled into the IDE")
155155
err := commands.Config.LoadFromDesktopIDEPreferences()
@@ -159,6 +159,21 @@ func initConfigs() {
159159
} else {
160160
logrus.Info("CLI is not bundled into the IDE")
161161
}
162+
163+
// Read configuration from parent folders (project config)
164+
commands.Config.Navigate("/", pwd)
165+
166+
// Read configuration from environment vars
162167
commands.Config.LoadFromEnv()
168+
169+
// Read configuration from user specified file
170+
if yamlConfigFile != "" {
171+
commands.Config.ConfigFile = paths.New(yamlConfigFile)
172+
logrus.Infof("Reading configuration from %s", commands.Config.ConfigFile)
173+
if err := commands.Config.LoadFromYAML(commands.Config.ConfigFile); err != nil {
174+
logrus.WithError(err).Warnf("Could not read configuration from %s", commands.Config.ConfigFile)
175+
}
176+
}
177+
163178
logrus.Info("Configuration set")
164179
}

0 commit comments

Comments
 (0)