diff --git a/commands/board/list.go b/commands/board/list.go index 577aa478b6c..c89f06fe75d 100644 --- a/commands/board/list.go +++ b/commands/board/list.go @@ -90,6 +90,17 @@ func apiByVidPid(vid, pid string) ([]*rpc.BoardListItem, error) { return retVal, nil } +func identifyViaCloudAPI(port *commands.BoardPort) ([]*rpc.BoardListItem, error) { + // If the port is not USB do not try identification via cloud + id := port.IdentificationPrefs + if !id.ContainsKey("vid") || !id.ContainsKey("pid") { + return nil, ErrNotFound + } + + logrus.Debug("Querying builder API for board identification...") + return apiByVidPid(id.Get("vid"), id.Get("pid")) +} + // List FIXMEDOC func List(instanceID int32) ([]*rpc.DetectedPort, error) { m.Lock() @@ -119,13 +130,9 @@ func List(instanceID int32) ([]*rpc.DetectedPort, error) { } // if installed cores didn't recognize the board, try querying - // the builder API + // the builder API if the board is a USB device port if len(b) == 0 { - logrus.Debug("Querying builder API for board identification...") - items, err := apiByVidPid( - port.IdentificationPrefs.Get("vid"), - port.IdentificationPrefs.Get("pid"), - ) + items, err := identifyViaCloudAPI(port) if err == ErrNotFound { // the board couldn't be detected, print a warning logrus.Debug("Board not recognized") diff --git a/commands/board/list_test.go b/commands/board/list_test.go index 4014e791f4a..d8600681c22 100644 --- a/commands/board/list_test.go +++ b/commands/board/list_test.go @@ -21,6 +21,8 @@ import ( "net/http/httptest" "testing" + "github.com/arduino/arduino-cli/commands" + "github.com/arduino/go-properties-orderedmap" "github.com/stretchr/testify/require" ) @@ -91,3 +93,12 @@ func TestGetByVidPidMalformedResponse(t *testing.T) { require.Equal(t, "wrong format in server response", err.Error()) require.Len(t, res, 0) } + +func TestBoardDetectionViaAPIWithNonUSBPort(t *testing.T) { + port := &commands.BoardPort{ + IdentificationPrefs: properties.NewMap(), + } + items, err := identifyViaCloudAPI(port) + require.Equal(t, err, ErrNotFound) + require.Empty(t, items) +} diff --git a/go.mod b/go.mod index 8427598d575..b0ae9aa7f2e 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,6 @@ require ( go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45 golang.org/x/net v0.0.0-20190311183353-d8887717615a golang.org/x/text v0.3.0 - google.golang.org/appengine v1.4.0 // indirect google.golang.org/genproto v0.0.0-20190327125643-d831d65fe17d // indirect google.golang.org/grpc v1.21.1 gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect