@@ -21,6 +21,7 @@ import (
21
21
"fmt"
22
22
"io/ioutil"
23
23
"os"
24
+ "path"
24
25
"path/filepath"
25
26
"strings"
26
27
@@ -117,15 +118,43 @@ func parseFormatString(arg string) (feedback.OutputFormat, bool) {
117
118
return f , found
118
119
}
119
120
121
+ // This function is here to replicate the old logic looking for a config
122
+ // file in the parent tree of the CWD, aka "project config".
123
+ // Please
124
+ func searchConfigTree (cwd string ) string {
125
+ // go back up to root and search for the config file
126
+ for {
127
+ if _ , err := os .Stat (path .Join (cwd , "arduino-cli.yaml" )); os .IsNotExist (err ) {
128
+ // no config file found
129
+ next := path .Join (cwd , ".." )
130
+ if filepath .Clean (next ) == filepath .Clean (cwd ) {
131
+ return ""
132
+ }
133
+ cwd = next
134
+ } else {
135
+ return cwd
136
+ }
137
+ }
138
+ }
139
+
120
140
func preRun (cmd * cobra.Command , args []string ) {
121
141
//
122
142
// Prepare the configuration system
123
143
//
124
144
configPath := ""
145
+
146
+ // get cwd, if something is wrong don't do anything and let
147
+ // configuration init proceed
148
+ if cwd , err := os .Getwd (); err == nil {
149
+ configPath = searchConfigTree (cwd )
150
+ }
151
+
152
+ // override the config path if --config-file was passed
125
153
if configFile != "" {
126
- // override the config path if --config-file was passed
127
154
configPath = filepath .Dir (configFile )
128
155
}
156
+
157
+ // initialize the config system
129
158
configuration .Init (configPath )
130
159
configFile := viper .ConfigFileUsed ()
131
160
0 commit comments