Skip to content

Commit 0daabe3

Browse files
committed
bugfix: Navigate method didn't work with Windows-style paths
Fix arduino#150
1 parent 49d459e commit 0daabe3

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

commands/root/root.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ func initConfigs() {
126126
}
127127

128128
// Read configuration from global config file
129+
logrus.Info("Checking for config file in: " + commands.Config.ConfigFile.String())
129130
if commands.Config.ConfigFile.Exist() {
130131
readConfigFrom(commands.Config.ConfigFile)
131132
}
@@ -147,7 +148,7 @@ func initConfigs() {
147148
readConfigFrom(path)
148149
}
149150
} else {
150-
commands.Config.Navigate("/", pwd.String())
151+
commands.Config.Navigate(pwd)
151152
}
152153

153154
// Read configuration from old configuration file if found, but output a warning.

configs/navigate.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,22 @@
1818
package configs
1919

2020
import (
21-
"path/filepath"
22-
"strings"
21+
"fmt"
2322

2423
paths "github.com/arduino/go-paths-helper"
24+
"github.com/sirupsen/logrus"
2525
)
2626

27-
func (c *Configuration) Navigate(root, pwd string) {
28-
relativePath, err := filepath.Rel(root, pwd)
29-
if err != nil {
30-
return
31-
}
27+
func (c *Configuration) Navigate(pwd *paths.Path) {
28+
parents := pwd.Clean().Parents()
29+
fmt.Println(parents)
3230

3331
// From the root to the current folder, search for arduino-cli.yaml files
34-
parts := strings.Split(relativePath, string(filepath.Separator))
35-
for i := range parts {
36-
path := paths.New(root)
37-
path = path.Join(parts[:i+1]...)
38-
path = path.Join("arduino-cli.yaml")
39-
_ = c.LoadFromYAML(path)
32+
for i := range parents {
33+
path := parents[len(parents)-i-1].Join("arduino-cli.yaml")
34+
logrus.Info("Checking for config in: " + path.String())
35+
if err := c.LoadFromYAML(path); err != nil {
36+
logrus.WithError(err).Infof("error loading")
37+
}
4038
}
4139
}

configs/navigate_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"testing"
2525

2626
"github.com/arduino/arduino-cli/configs"
27+
paths "github.com/arduino/go-paths-helper"
2728
homedir "github.com/mitchellh/go-homedir"
2829
"github.com/sergi/go-diff/diffmatchpatch"
2930
)
@@ -36,13 +37,12 @@ func TestNavigate(t *testing.T) {
3637
}
3738
for _, tt := range tests {
3839
t.Run(tt, func(t *testing.T) {
39-
root := filepath.Join("testdata", "navigate", tt)
40-
pwd := filepath.Join("testdata", "navigate", tt, "first", "second")
40+
pwd := paths.New("testdata", "navigate", tt, "first", "second")
4141
golden := filepath.Join("testdata", "navigate", tt, "golden.yaml")
4242

4343
config, _ := configs.NewConfiguration()
4444

45-
config.Navigate(root, pwd)
45+
config.Navigate(pwd)
4646
data, _ := config.SerializeToYAML()
4747

4848
diff(t, data, golden)

0 commit comments

Comments
 (0)