Skip to content

Commit a03e360

Browse files
committed
Added methods to cycle on all installed platforms or boards
1 parent 1806457 commit a03e360

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

arduino/cores/packagemanager/package_manager.go

+32-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import (
2626

2727
"github.com/arduino/arduino-cli/arduino/cores"
2828
"github.com/arduino/arduino-cli/arduino/cores/packageindex"
29-
"github.com/arduino/go-paths-helper"
29+
paths "github.com/arduino/go-paths-helper"
3030
properties "github.com/arduino/go-properties-orderedmap"
3131
"github.com/sirupsen/logrus"
32-
"go.bug.st/relaxed-semver"
32+
semver "go.bug.st/relaxed-semver"
3333
)
3434

3535
// PackageManager defines the superior oracle which understands all about
@@ -354,6 +354,36 @@ func (pm *PackageManager) GetAllInstalledToolsReleases() []*cores.ToolRelease {
354354
return tools
355355
}
356356

357+
// InstalledPlatformReleases returns all installed PlatformReleases. This function is
358+
// useful to range all PlatformReleases in for loops.
359+
func (pm *PackageManager) InstalledPlatformReleases() []*cores.PlatformRelease {
360+
platforms := []*cores.PlatformRelease{}
361+
for _, targetPackage := range pm.packages.Packages {
362+
for _, platform := range targetPackage.Platforms {
363+
for _, release := range platform.GetAllInstalled() {
364+
platforms = append(platforms, release)
365+
}
366+
}
367+
}
368+
return platforms
369+
}
370+
371+
// InstalledBoards returns all installed Boards. This function is useful to range
372+
// all Boards in for loops.
373+
func (pm *PackageManager) InstalledBoards() []*cores.Board {
374+
boards := []*cores.Board{}
375+
for _, targetPackage := range pm.packages.Packages {
376+
for _, platform := range targetPackage.Platforms {
377+
for _, release := range platform.GetAllInstalled() {
378+
for _, board := range release.Boards {
379+
boards = append(boards, board)
380+
}
381+
}
382+
}
383+
}
384+
return boards
385+
}
386+
357387
func (pm *PackageManager) FindToolsRequiredForBoard(board *cores.Board) ([]*cores.ToolRelease, error) {
358388
pm.Log.Infof("Searching tools required for board %s", board)
359389

0 commit comments

Comments
 (0)