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 {
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 {
res := []*cores.Board{}
for _, targetPackage := range pm.packages.Packages {
......
......@@ -31,6 +31,7 @@ package core
import (
"os"
"regexp"
"strings"
"github.com/bcmi-labs/arduino-cli/commands"
......@@ -62,24 +63,29 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
formatter.Print("Searching for platforms matching '" + search + "'")
formatter.Print("")
match := func(line string) bool {
return strings.Contains(strings.ToLower(line), search)
}
res := output.PlatformReleases{}
for _, targetPackage := range pm.GetPackages().Packages {
for _, platform := range targetPackage.Platforms {
platformRelease := platform.GetLatestRelease()
if platformRelease == nil {
continue
}
if match(platform.Name) || match(platform.Architecture) {
res = append(res, platformRelease)
continue
}
for _, boards := range platformRelease.BoardsManifest {
if match(boards.Name) {
if isUsb, _ := regexp.MatchString("[0-9a-f]{4}:[0-9a-f]{4}", search); isUsb {
vid, pid := search[:4], search[5:]
res = pm.FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid)
} else {
match := func(line string) bool {
return strings.Contains(strings.ToLower(line), search)
}
for _, targetPackage := range pm.GetPackages().Packages {
for _, platform := range targetPackage.Platforms {
platformRelease := platform.GetLatestRelease()
if platformRelease == nil {
continue
}
if match(platform.Name) || match(platform.Architecture) {
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