@@ -20,7 +20,6 @@ import (
20
20
"strings"
21
21
22
22
"github.com/arduino/arduino-cli/arduino/globals"
23
- "github.com/arduino/arduino-cli/arduino/sketch"
24
23
"github.com/arduino/go-paths-helper"
25
24
properties "github.com/arduino/go-properties-orderedmap"
26
25
"github.com/pkg/errors"
@@ -176,20 +175,11 @@ func addExamples(lib *Library) error {
176
175
}
177
176
178
177
func addExamplesToPathList (examplesPath * paths.Path , list * paths.PathList ) error {
179
- files , err := examplesPath .ReadDir ( )
178
+ files , err := examplesPath .ReadDirRecursiveFiltered ( nil , filterExamplesDirs )
180
179
if err != nil {
181
180
return err
182
181
}
183
- for _ , file := range files {
184
- _ , err := sketch .New (file )
185
- if err == nil {
186
- list .Add (file )
187
- } else if file .IsDir () {
188
- if err := addExamplesToPathList (file , list ); err != nil {
189
- return err
190
- }
191
- }
192
- }
182
+ list .AddAll (files )
193
183
return nil
194
184
}
195
185
@@ -208,3 +198,8 @@ func containsHeaderFile(d *paths.Path) (bool, error) {
208
198
dirContent .FilterSuffix (headerExtensions ... )
209
199
return len (dirContent ) > 0 , nil
210
200
}
201
+
202
+ // filterExamplesDirs filters out any directory that does not contain a ".ino" or ".pde" file
203
+ func filterExamplesDirs (dir * paths.Path ) bool {
204
+ return dir .Join (dir .Base ()+ ".ino" ).Exist () || dir .Join (dir .Base ()+ ".pde" ).Exist ()
205
+ }
0 commit comments