@@ -27,9 +27,9 @@ import (
27
27
28
28
"golang.org/x/crypto/ssh/terminal"
29
29
30
- "github.com/mattn/go-colorable"
30
+ colorable "github.com/mattn/go-colorable"
31
31
32
- "github.com/arduino/go-paths-helper"
32
+ paths "github.com/arduino/go-paths-helper"
33
33
34
34
"github.com/arduino/arduino-cli/commands"
35
35
"github.com/arduino/arduino-cli/commands/board"
@@ -118,11 +118,15 @@ func preRun(cmd *cobra.Command, args []string) {
118
118
// initConfigs initializes the configuration from the specified file.
119
119
func initConfigs () {
120
120
// 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." )
124
127
os .Exit (commands .ErrGeneric )
125
128
}
129
+
126
130
// Start with default configuration
127
131
if conf , err := configs .NewConfiguration (); err != nil {
128
132
logrus .WithError (err ).Error ("Error creating default configuration" )
@@ -138,18 +142,14 @@ func initConfigs() {
138
142
logrus .WithError (err ).Warn ("Did not manage to find current path" )
139
143
}
140
144
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 )
146
148
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 )
148
150
}
149
151
}
150
152
151
- logrus .Info ("Initiating configuration" )
152
-
153
153
if commands .Config .IsBundledInDesktopIDE () {
154
154
logrus .Info ("CLI is bundled into the IDE" )
155
155
err := commands .Config .LoadFromDesktopIDEPreferences ()
@@ -159,6 +159,21 @@ func initConfigs() {
159
159
} else {
160
160
logrus .Info ("CLI is not bundled into the IDE" )
161
161
}
162
+
163
+ // Read configuration from parent folders (project config)
164
+ commands .Config .Navigate ("/" , pwd )
165
+
166
+ // Read configuration from environment vars
162
167
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
+
163
178
logrus .Info ("Configuration set" )
164
179
}
0 commit comments