Commit e6998831 authored by Cristian Maglie's avatar Cristian Maglie

Now 'core search' match also USB ID

parent 3fe34f53
...@@ -79,6 +79,25 @@ func (pm *PackageManager) GetPackages() *cores.Packages { ...@@ -79,6 +79,25 @@ func (pm *PackageManager) GetPackages() *cores.Packages {
return pm.packages return pm.packages
} }
func (pm *PackageManager) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid string) []*cores.PlatformRelease {
res := []*cores.PlatformRelease{}
for _, targetPackage := range pm.packages.Packages {
for _, targetPlatform := range targetPackage.Platforms {
platformRelease := targetPlatform.GetLatestRelease()
if platformRelease == nil {
continue
}
for _, boardManifest := range platformRelease.BoardsManifest {
if boardManifest.HasUsbID(vid, pid) {
res = append(res, platformRelease)
break
}
}
}
}
return res
}
func (pm *PackageManager) FindBoardsWithVidPid(vid, pid string) []*cores.Board { func (pm *PackageManager) FindBoardsWithVidPid(vid, pid string) []*cores.Board {
res := []*cores.Board{} res := []*cores.Board{}
for _, targetPackage := range pm.packages.Packages { for _, targetPackage := range pm.packages.Packages {
......
...@@ -31,6 +31,7 @@ package core ...@@ -31,6 +31,7 @@ package core
import ( import (
"os" "os"
"regexp"
"strings" "strings"
"github.com/bcmi-labs/arduino-cli/commands" "github.com/bcmi-labs/arduino-cli/commands"
...@@ -62,24 +63,29 @@ func runSearchCommand(cmd *cobra.Command, args []string) { ...@@ -62,24 +63,29 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
formatter.Print("Searching for platforms matching '" + search + "'") formatter.Print("Searching for platforms matching '" + search + "'")
formatter.Print("") formatter.Print("")
match := func(line string) bool {
return strings.Contains(strings.ToLower(line), search)
}
res := output.PlatformReleases{} res := output.PlatformReleases{}
for _, targetPackage := range pm.GetPackages().Packages { if isUsb, _ := regexp.MatchString("[0-9a-f]{4}:[0-9a-f]{4}", search); isUsb {
for _, platform := range targetPackage.Platforms { vid, pid := search[:4], search[5:]
platformRelease := platform.GetLatestRelease() res = pm.FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid)
if platformRelease == nil { } else {
continue match := func(line string) bool {
} return strings.Contains(strings.ToLower(line), search)
if match(platform.Name) || match(platform.Architecture) { }
res = append(res, platformRelease) for _, targetPackage := range pm.GetPackages().Packages {
continue for _, platform := range targetPackage.Platforms {
} platformRelease := platform.GetLatestRelease()
for _, boards := range platformRelease.BoardsManifest { if platformRelease == nil {
if match(boards.Name) { continue
}
if match(platform.Name) || match(platform.Architecture) {
res = append(res, platformRelease) res = append(res, platformRelease)
break continue
}
for _, board := range platformRelease.BoardsManifest {
if match(board.Name) || board.HasUsbID(search) {
res = append(res, platformRelease)
break
}
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment