@@ -50,12 +50,6 @@ import (
50
50
// ConfigFilePath represents the default location of the config file (same directory as executable).
51
51
var ConfigFilePath = detectConfigFilePath ()
52
52
53
- // bundledInIDE tells if the CLI is paired with the Java Arduino IDE.
54
- var bundledInIDE * bool
55
-
56
- // ArduinoIDEFolder represents the path of the IDE directory, set only if BundledInIDE = true.
57
- var ArduinoIDEFolder string
58
-
59
53
func detectConfigFilePath () string {
60
54
fileLocation , err := os .Executable ()
61
55
if err != nil {
@@ -180,14 +174,17 @@ func fixMissingFields(c *Configs) {
180
174
}
181
175
}
182
176
177
+ var arduinoIDEDirectory * string
178
+
183
179
// Bundled returns if the CLI is bundled with the Arduino IDE.
184
180
func Bundled () bool {
185
- if bundledInIDE != nil {
186
- return * bundledInIDE
181
+ if arduinoIDEDirectory != nil {
182
+ return * arduinoIDEDirectory != ""
187
183
}
188
- bundledInIDE = new (bool )
184
+ empty := ""
185
+ arduinoIDEDirectory = & empty
186
+
189
187
logrus .Info ("Checking if CLI is Bundled into the IDE" )
190
- * bundledInIDE = false
191
188
executable , err := os .Executable ()
192
189
if err != nil {
193
190
logrus .WithError (err ).Warn ("Cannot get executable path" )
@@ -198,19 +195,19 @@ func Bundled() bool {
198
195
logrus .WithError (err ).Warn ("Cannot get executable path (symlinks error)" )
199
196
return false
200
197
}
201
- ArduinoIDEFolder := filepath .Dir (filepath .Dir (executable ))
202
-
203
- logrus .Info ("Candidate IDE Folder:" , ArduinoIDEFolder )
198
+ ideDir := filepath .Dir (filepath .Dir (executable ))
199
+ logrus .Info ("Candidate IDE Directory:" , ideDir )
204
200
205
201
executables := []string {"arduino" , "arduino.sh" , "arduino.exe" }
206
202
for _ , exe := range executables {
207
- exePath := filepath .Join (ArduinoIDEFolder , exe )
203
+ exePath := filepath .Join (ideDir , exe )
208
204
_ , err := os .Stat (exePath )
209
205
if ! os .IsNotExist (err ) {
210
- logrus . WithError ( err ). Info ( "CLI is bundled" )
211
- * bundledInIDE = true
206
+ arduinoIDEDirectory = & ideDir
207
+ logrus . Info ( "CLI is bundled:" , * arduinoIDEDirectory )
212
208
break
213
209
}
214
210
}
215
- return false
211
+
212
+ return * arduinoIDEDirectory != ""
216
213
}
0 commit comments