@@ -19,6 +19,7 @@ import (
1919 "fmt"
2020 "strings"
2121
22+ "github.com/arduino/arduino-cli/arduino"
2223 "github.com/arduino/arduino-cli/cli/instance"
2324 "github.com/arduino/arduino-cli/commands/core"
2425 rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -94,20 +95,28 @@ func ParseReference(arg string) (*Reference, error) {
9495 UpdatableOnly : false ,
9596 All : true , // this is true because we want also the installable platforms
9697 })
97- var found = 0
98+ foundPlatforms := [] string {}
9899 for _ , platform := range platforms {
99- if strings .EqualFold (platform .GetId (), ret .PackageName + ":" + ret .Architecture ) {
100- logrus .Infof ("Found possible match for reference %s -> %s" , arg , platform .GetId ())
101- toks = strings .Split (platform .GetId (), ":" )
102- found ++
100+ platformID := platform .GetId ()
101+ platformUser := ret .PackageName + ":" + ret .Architecture
102+ // At first we check if the platform the user is searching for matches an available one,
103+ // this way we do not need to adapt the casing and we can return it directly
104+ if platformUser == platformID {
105+ return ret , nil
106+ }
107+ if strings .EqualFold (platformUser , platformID ) {
108+ logrus .Infof ("Found possible match for reference %s -> %s" , platformUser , platformID )
109+ toks = strings .Split (platformID , ":" )
110+ foundPlatforms = append (foundPlatforms , platformID )
103111 }
104112 }
105- // replace the returned Reference only if only one occurrence is found, otherwise leave it as is
106- if found == 1 {
113+ // replace the returned Reference only if only one occurrence is found,
114+ // otherwise return an error to the user because we don't know on which platform operate
115+ if len (foundPlatforms ) == 1 {
107116 ret .PackageName = toks [0 ]
108117 ret .Architecture = toks [1 ]
109118 } else {
110- logrus . Warnf ( "Found %d platform for reference: %s" , found , arg )
119+ return nil , & arduino. MultiplePlatformsError { Platforms : foundPlatforms , UserPlatform : arg }
111120 }
112121 return ret , nil
113122}
0 commit comments