Skip to content

Commit 8af5ecd

Browse files
committed
Fixed config from env vars
1 parent 2964f32 commit 8af5ecd

File tree

4 files changed

+18
-23
lines changed

4 files changed

+18
-23
lines changed

configs/env_vars_serializer.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ package configs
3131

3232
import (
3333
"os"
34-
35-
"github.com/bcmi-labs/arduino-cli/pathutils"
3634
)
3735

3836
// LoadFromEnv read configurations from the environment variables
@@ -41,10 +39,9 @@ func LoadFromEnv() {
4139
ProxyType = p
4240
}
4341
if dir, has := os.LookupEnv("ARDUINO_SKETCHBOOK_DIR"); has {
44-
SketchbookFolder = pathutils.NewConstPath("Sketchbook", dir, true)
45-
ArduinoHomeFolder = SketchbookFolder
42+
SketchbookFolder.SetPath(dir)
4643
}
4744
if dir, has := os.LookupEnv("ARDUINO_DATA_DIR"); has {
48-
ArduinoDataFolder = pathutils.NewConstPath("Arduino Data", dir, true)
45+
ArduinoDataFolder.SetPath(dir)
4946
}
5047
}

configs/preferences_txt_serializer.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ import (
3636
"path/filepath"
3737
"strings"
3838

39-
"github.com/bcmi-labs/arduino-cli/pathutils"
40-
4139
"github.com/arduino/go-properties-map"
4240
"github.com/sirupsen/logrus"
4341
"github.com/spf13/viper"
@@ -99,8 +97,7 @@ func LoadFromDesktopIDEPreferences() error {
9997
return err
10098
}
10199
if dir, has := props["sketchbook.path"]; has {
102-
SketchbookFolder = pathutils.NewConstPath("Sketchbook", dir, true)
103-
ArduinoHomeFolder = SketchbookFolder
100+
SketchbookFolder.SetPath(dir)
104101
}
105102
if URLs, has := props["boardsmanager.additional.urls"]; has {
106103
for _, URL := range strings.Split(URLs, ",") {

configs/yaml_serializer.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
"fmt"
3434
"io/ioutil"
3535

36-
"github.com/bcmi-labs/arduino-cli/pathutils"
3736
"github.com/sirupsen/logrus"
3837
yaml "gopkg.in/yaml.v2"
3938
)
@@ -70,10 +69,10 @@ func LoadFromYAML(path string) error {
7069
}
7170

7271
if ret.ArduinoDataFolder != "" {
73-
ArduinoDataFolder = pathutils.NewConstPath("Arduino Data", ret.ArduinoDataFolder, true)
72+
ArduinoDataFolder.SetPath(ret.ArduinoDataFolder)
7473
}
7574
if ret.SketchbookPath != "" {
76-
SketchbookFolder = pathutils.NewConstPath("Sketchbook", ret.SketchbookPath, true)
75+
SketchbookFolder.SetPath(ret.SketchbookPath)
7776
}
7877
if ret.ProxyType != "" {
7978
ProxyType = ret.ProxyType

pathutils/pathutils.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,9 @@ import (
3939
type Path interface {
4040
// Get tries to determine the path or return an error if fails
4141
Get() (string, error)
42-
}
4342

44-
// NewConstPath creates a constant Path that always returns the specified
45-
// path, errors will always be nil
46-
func NewConstPath(label string, path string, createIfMissing bool) Path {
47-
return &basicPath{
48-
Label: label,
49-
ProviderFunction: func() (string, error) {
50-
return path, nil
51-
},
52-
CreateIfMissing: createIfMissing,
53-
}
43+
// SetPath change the path to the specified constant
44+
SetPath(string)
5445
}
5546

5647
// NewPath return a Path object that use the providerFunction to determine
@@ -106,6 +97,13 @@ func (p *basicPath) Get() (string, error) {
10697
return p.cachedPath, nil
10798
}
10899

100+
func (p *basicPath) SetPath(path string) {
101+
p.cachedPath = ""
102+
p.ProviderFunction = func() (string, error) {
103+
return path, nil
104+
}
105+
}
106+
109107
type basicSubPath struct {
110108
Label string
111109
Path Path
@@ -137,3 +135,7 @@ func (p *basicSubPath) Get() (string, error) {
137135
p.cachedPath = path
138136
return p.cachedPath, nil
139137
}
138+
139+
func (p *basicSubPath) SetPath(path string) {
140+
panic("Could not SetPath in subPath object")
141+
}

0 commit comments

Comments
 (0)