Skip to content

Commit 4712662

Browse files
committed
Make Navigate a method of Configuration
This will make sure it can be chained with other ParseFromYaml
1 parent f785e1c commit 4712662

File tree

5 files changed

+14
-22
lines changed

5 files changed

+14
-22
lines changed

configs/navigate.go

+2-16
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,20 @@ import (
55
"strings"
66

77
paths "github.com/arduino/go-paths-helper"
8-
homedir "github.com/mitchellh/go-homedir"
98
)
109

11-
func Navigate(root, pwd string) Configuration {
10+
func (c *Configuration) Navigate(root, pwd string) {
1211
relativePath, err := filepath.Rel(root, pwd)
1312
if err != nil {
1413
panic(err)
1514
}
1615

17-
home, err := homedir.Dir()
18-
if err != nil {
19-
panic(err) // Should never happen
20-
}
21-
22-
// Default configuration
23-
config := Configuration{
24-
SketchbookDir: paths.New(home, "Arduino"),
25-
DataDir: paths.New(home, ".arduino15"),
26-
}
27-
2816
// From the root to the current folder, search for arduino-cli.yaml files
2917
parts := strings.Split(relativePath, string(filepath.Separator))
3018
for i := range parts {
3119
path := paths.New(root)
3220
path = path.Join(parts[:i+1]...)
3321
path = path.Join("arduino-cli.yaml")
34-
_ = config.LoadFromYAML(path)
22+
_ = c.LoadFromYAML(path)
3523
}
36-
37-
return config
3824
}

configs/navigate_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ func TestNavigate(t *testing.T) {
2323
pwd := filepath.Join("testdata", "navigate", tt, "first", "second")
2424
golden := filepath.Join("testdata", "navigate", tt, "golden.yaml")
2525

26-
got := configs.Navigate(root, pwd)
27-
data, _ := got.SerializeToYAML()
26+
config, _ := configs.NewConfiguration()
27+
28+
config.Navigate(root, pwd)
29+
data, _ := config.SerializeToYAML()
2830

2931
diff(t, data, golden)
3032
})
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
proxy_type: ""
1+
proxy_type: auto
22
sketchbook_path: /tmp
33
arduino_data: $HOME/.arduino15
44
board_manager:
55
additional_urls:
6+
- https://downloads.arduino.cc/packages/package_index.json
67
- https://downloads.arduino.cc/package_index_mraa.json
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
proxy_type: ""
1+
proxy_type: auto
22
sketchbook_path: $HOME/Arduino
33
arduino_data: $HOME/.arduino15
44
board_manager:
55
additional_urls:
6+
- https://downloads.arduino.cc/packages/package_index.json
67
- https://downloads.arduino.cc/package_index_mraa.json
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
proxy_type: ""
1+
proxy_type: auto
22
sketchbook_path: $HOME/Arduino
33
arduino_data: $HOME/.arduino15
4-
board_manager: null
4+
board_manager:
5+
additional_urls:
6+
- https://downloads.arduino.cc/packages/package_index.json

0 commit comments

Comments
 (0)