Skip to content

Commit 715cb0b

Browse files
committed
Sligltly simplified getDefaultConfigDir
1 parent 8b9ab21 commit 715cb0b

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

config.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ package main
1717

1818
import (
1919
_ "embed"
20-
"fmt"
2120
"os"
2221

2322
"github.com/arduino/go-paths-helper"
2423
log "github.com/sirupsen/logrus"
2524
)
2625

27-
// getDefaultArduinoCreateConfigDir returns the full path to the default arduino create agent data directory
28-
func getDefaultArduinoCreateConfigDir() (*paths.Path, error) {
26+
// getDefaultConfigDir returns the full path to the default Arduino Create Agent configuration directory.
27+
func getDefaultConfigDir() *paths.Path {
2928
// UserConfigDir returns the default root directory to use
3029
// for user-specific configuration data. Users should create
3130
// their own application-specific subdirectory within this
@@ -43,14 +42,14 @@ func getDefaultArduinoCreateConfigDir() (*paths.Path, error) {
4342
// is not defined), then it will return an error.
4443
configDir, err := os.UserConfigDir()
4544
if err != nil {
46-
return nil, err
45+
log.Panicf("Can't get user home dir: %s", err)
4746
}
4847

4948
agentConfigDir := paths.New(configDir, "ArduinoCreateAgent")
5049
if err := agentConfigDir.MkdirAll(); err != nil {
51-
return nil, fmt.Errorf("cannot create config dir: %s", err)
50+
log.Panicf("Can't create config dir: %s", err)
5251
}
53-
return agentConfigDir, nil
52+
return agentConfigDir
5453
}
5554

5655
//go:embed config.ini

main.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,7 @@ func main() {
136136
go loop()
137137

138138
// SetupSystray is the main thread
139-
configDir, err := getDefaultArduinoCreateConfigDir()
140-
if err != nil {
141-
log.Panicf("Can't open defaul configuration dir: %s", err)
142-
}
139+
configDir := getDefaultConfigDir()
143140
Systray = systray.Systray{
144141
Hibernate: *hibernate,
145142
Version: version + "-" + commit,
@@ -201,7 +198,7 @@ func loop() {
201198
src, _ := os.Executable()
202199
srcPath := paths.New(src) // The path of the agent's binary
203200
srcDir := srcPath.Parent() // The directory of the agent's binary
204-
agentDir, err := getDefaultArduinoCreateConfigDir()
201+
agentDir := getDefaultConfigDir()
205202

206203
// Instantiate Tools
207204
Tools = tools.Tools{
@@ -216,6 +213,7 @@ func loop() {
216213
Tools.Init(requiredToolsAPILevel)
217214

218215
// Let's handle the config
216+
configDir := getDefaultConfigDir()
219217
var configPath *paths.Path
220218

221219
// see if the env var is defined, if it is take the config from there, this will override the default path
@@ -225,7 +223,7 @@ func loop() {
225223
log.Panicf("config from env var %s does not exists", envConfig)
226224
}
227225
log.Infof("using config from env variable: %s", configPath)
228-
} else if defaultConfigPath := agentDir.Join("config.ini"); defaultConfigPath.Exist() {
226+
} else if defaultConfigPath := configDir.Join("config.ini"); defaultConfigPath.Exist() {
229227
// by default take the config from the ~/.arduino-create/config.ini file
230228
configPath = defaultConfigPath
231229
log.Infof("using config from default: %s", configPath)
@@ -243,7 +241,7 @@ func loop() {
243241
}
244242
}
245243
if configPath == nil {
246-
configPath = generateConfig(agentDir)
244+
configPath = generateConfig(configDir)
247245
}
248246

249247
// Parse the config.ini

0 commit comments

Comments
 (0)