@@ -41,18 +41,6 @@ func Init(configPath string) {
41
41
logrus .Infof ("Checking for config file in: %s" , configPath )
42
42
viper .AddConfigPath (configPath )
43
43
44
- // Set configuration defaults
45
- setDefaults (configPath , getDefaultSketchbookDir ())
46
-
47
- // Attempt to read config file
48
- if err := viper .ReadInConfig (); err != nil {
49
- if _ , ok := err .(viper.ConfigFileNotFoundError ); ok {
50
- logrus .Info ("Config file not found, using default values" )
51
- } else {
52
- feedback .Errorf ("Error reading config file: %v" , err )
53
- }
54
- }
55
-
56
44
// Bind env vars
57
45
viper .SetEnvPrefix ("ARDUINO" )
58
46
viper .SetEnvKeyReplacer (strings .NewReplacer ("." , "_" ))
@@ -62,6 +50,29 @@ func Init(configPath string) {
62
50
viper .BindEnv ("directories.Sketchbook" , "ARDUINO_SKETCHBOOK_DIR" )
63
51
viper .BindEnv ("directories.Downloads" , "ARDUINO_DOWNLOADS_DIR" )
64
52
viper .BindEnv ("directories.Data" , "ARDUINO_DATA_DIR" )
53
+
54
+ // Early access directories.Data and directories.Sketchbookin case
55
+ // those were set through env vars or cli flags
56
+ dataDir := viper .GetString ("directories.Data" )
57
+ if dataDir == "" {
58
+ dataDir = getDefaultArduinoDataDir ()
59
+ }
60
+ sketchbookDir := viper .GetString ("directories.Sketchbook" )
61
+ if sketchbookDir == "" {
62
+ sketchbookDir = getDefaultSketchbookDir ()
63
+ }
64
+
65
+ // Set default values for all the settings
66
+ setDefaults (dataDir , sketchbookDir )
67
+
68
+ // Attempt to read config file
69
+ if err := viper .ReadInConfig (); err != nil {
70
+ if _ , ok := err .(viper.ConfigFileNotFoundError ); ok {
71
+ logrus .Info ("Config file not found, using default values" )
72
+ } else {
73
+ feedback .Errorf ("Error reading config file: %v" , err )
74
+ }
75
+ }
65
76
}
66
77
67
78
// getDefaultArduinoDataDir returns the full path to the default arduino folder
0 commit comments