Skip to content

Commit 74f9f6a

Browse files
committed
Search for config file in local directory
1 parent 4a73a8e commit 74f9f6a

File tree

6 files changed

+24
-8
lines changed

6 files changed

+24
-8
lines changed

configs/navigate.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
11
package configs
22

33
import (
4+
"fmt"
5+
46
paths "github.com/arduino/go-paths-helper"
57
homedir "github.com/mitchellh/go-homedir"
68
)
79

810
func Navigate(root, pwd string) Configuration {
11+
fmt.Println("Navigate", root, pwd)
912
home, err := homedir.Dir()
1013
if err != nil {
1114
panic(err) // Should never happen
1215
}
1316

14-
return Configuration{
17+
// Default configuration
18+
config := Configuration{
1519
SketchbookDir: paths.New(home, "Arduino"),
1620
DataDir: paths.New(home, ".arduino15"),
1721
}
22+
23+
// Search for arduino-cli.yaml in current folder
24+
_ = config.LoadFromYAML(paths.New(pwd, "arduino-cli.yaml"))
25+
26+
return config
1827
}

configs/navigate_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
func TestNavigate(t *testing.T) {
1515
tests := []string{
1616
"noconfig",
17+
"local",
1718
}
1819
for _, tt := range tests {
1920
t.Run(tt, func(t *testing.T) {

configs/testdata/navigate/local/first/second/.gitkeep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
board_manager:
2+
additional_urls:
3+
- https://downloads.arduino.cc/package_index_mraa.json
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
proxy_type: ""
2+
sketchbook_path: $HOME/Arduino
3+
arduino_data: $HOME/.arduino15
4+
board_manager:
5+
additional_urls:
6+
- https://downloads.arduino.cc/package_index_mraa.json

configs/yaml_serializer.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"net/url"
2424

2525
paths "github.com/arduino/go-paths-helper"
26-
"github.com/sirupsen/logrus"
2726
yaml "gopkg.in/yaml.v2"
2827
)
2928

@@ -48,16 +47,13 @@ type yamlProxyConfig struct {
4847

4948
// LoadFromYAML loads the configs from a yaml file.
5049
func (config *Configuration) LoadFromYAML(path *paths.Path) error {
51-
logrus.Info("Unserializing configurations from ", path)
5250
content, err := path.ReadFile()
5351
if err != nil {
54-
logrus.WithError(err).Warn("Error reading config, using default configuration")
5552
return err
5653
}
5754
var ret yamlConfig
5855
err = yaml.Unmarshal(content, &ret)
5956
if err != nil {
60-
logrus.WithError(err).Warn("Error parsing config, using default configuration")
6157
return err
6258
}
6359

@@ -84,12 +80,12 @@ func (config *Configuration) LoadFromYAML(path *paths.Path) error {
8480
for _, rawurl := range ret.BoardsManager.AdditionalURLS {
8581
url, err := url.Parse(rawurl)
8682
if err != nil {
87-
logrus.WithError(err).Warn("Error parsing config")
8883
continue
8984
}
9085
config.BoardManagerAdditionalUrls = append(config.BoardManagerAdditionalUrls, url)
9186
}
9287
}
88+
9389
return nil
9490
}
9591

@@ -113,9 +109,9 @@ func (config *Configuration) SerializeToYAML() ([]byte, error) {
113109
Password: config.ProxyPassword,
114110
}
115111
}
116-
if len(config.BoardManagerAdditionalUrls) > 1 {
112+
if len(config.BoardManagerAdditionalUrls) > 0 {
117113
c.BoardsManager = &yamlBoardsManagerConfig{AdditionalURLS: []string{}}
118-
for _, URL := range config.BoardManagerAdditionalUrls[1:] {
114+
for _, URL := range config.BoardManagerAdditionalUrls {
119115
c.BoardsManager.AdditionalURLS = append(c.BoardsManager.AdditionalURLS, URL.String())
120116
}
121117
}

0 commit comments

Comments
 (0)