@@ -27,7 +27,9 @@ import (
27
27
"github.com/spf13/viper"
28
28
)
29
29
30
- // Init initialize defaults and read the configuration file
30
+ // Init initialize defaults and read the configuration file.
31
+ // Please note the logging system hasn't been configured yet,
32
+ // so logging shouldn't be used here.
31
33
func Init (configPath string ) {
32
34
// Config file metadata
33
35
viper .SetConfigName ("arduino-cli" )
@@ -38,7 +40,6 @@ func Init(configPath string) {
38
40
}
39
41
40
42
// Add paths where to search for a config file
41
- logrus .Infof ("Checking for config file in: %s" , configPath )
42
43
viper .AddConfigPath (configPath )
43
44
44
45
// Bind env vars
@@ -67,9 +68,9 @@ func Init(configPath string) {
67
68
68
69
// Attempt to read config file
69
70
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 {
71
+ // ConfigFileNotFoundError is acceptable, anything else
72
+ // should be reported to the user
73
+ if _ , ok := err .(viper. ConfigFileNotFoundError ); ! ok {
73
74
feedback .Errorf ("Error reading config file: %v" , err )
74
75
}
75
76
}
@@ -79,7 +80,7 @@ func Init(configPath string) {
79
80
func getDefaultArduinoDataDir () string {
80
81
userHomeDir , err := os .UserHomeDir ()
81
82
if err != nil {
82
- logrus .Errorf ("Unable to get user home dir: %v" , err )
83
+ feedback .Errorf ("Unable to get user home dir: %v" , err )
83
84
return "."
84
85
}
85
86
@@ -91,7 +92,7 @@ func getDefaultArduinoDataDir() string {
91
92
case "windows" :
92
93
localAppDataPath , err := win32 .GetLocalAppDataFolder ()
93
94
if err != nil {
94
- logrus .Errorf ("Unable to get Local App Data Folder: %v" , err )
95
+ feedback .Errorf ("Unable to get Local App Data Folder: %v" , err )
95
96
return "."
96
97
}
97
98
return filepath .Join (localAppDataPath , "Arduino15" )
@@ -104,7 +105,7 @@ func getDefaultArduinoDataDir() string {
104
105
func getDefaultSketchbookDir () string {
105
106
userHomeDir , err := os .UserHomeDir ()
106
107
if err != nil {
107
- logrus .Errorf ("Unable to get user home dir: %v" , err )
108
+ feedback .Errorf ("Unable to get user home dir: %v" , err )
108
109
return "."
109
110
}
110
111
@@ -116,7 +117,7 @@ func getDefaultSketchbookDir() string {
116
117
case "windows" :
117
118
documentsPath , err := win32 .GetDocumentsFolder ()
118
119
if err != nil {
119
- logrus .Errorf ("Unable to get Documents Folder: %v" , err )
120
+ feedback .Errorf ("Unable to get Documents Folder: %v" , err )
120
121
return "."
121
122
}
122
123
return filepath .Join (documentsPath , "Arduino" )
@@ -138,18 +139,17 @@ func IsBundledInDesktopIDE() bool {
138
139
logrus .Info ("Checking if CLI is Bundled into the IDE" )
139
140
executable , err := os .Executable ()
140
141
if err != nil {
141
- logrus . WithError ( err ). Warn ( "Cannot get executable path" )
142
+ feedback . Errorf ( "Cannot get executable path: %v" , err )
142
143
return viper .GetBool ("IDE.Bundled" )
143
144
}
144
145
145
146
executablePath , err := filepath .EvalSymlinks (executable )
146
147
if err != nil {
147
- logrus . WithError ( err ). Warn ( "Cannot get executable path" )
148
+ feedback . Errorf ( "Cannot get executable path: %v" , err )
148
149
return viper .GetBool ("IDE.Bundled" )
149
150
}
150
151
151
152
ideDir := filepath .Dir (executablePath )
152
- logrus .Info ("Candidate IDE Directory: " , ideDir )
153
153
154
154
// We check an arbitrary number of folders that are part of the IDE
155
155
// install tree
@@ -166,7 +166,6 @@ func IsBundledInDesktopIDE() bool {
166
166
}
167
167
168
168
if test == "portable" {
169
- logrus .Info ("IDE is portable" )
170
169
viper .Set ("IDE.Portable" , true )
171
170
}
172
171
}
0 commit comments