@@ -19,6 +19,7 @@ import (
19
19
"fmt"
20
20
"strings"
21
21
22
+ "github.com/arduino/arduino-cli/arduino"
22
23
"github.com/arduino/arduino-cli/cli/instance"
23
24
"github.com/arduino/arduino-cli/commands/core"
24
25
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -94,20 +95,28 @@ func ParseReference(arg string) (*Reference, error) {
94
95
UpdatableOnly : false ,
95
96
All : true , // this is true because we want also the installable platforms
96
97
})
97
- var found = 0
98
+ foundPlatforms := [] string {}
98
99
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 )
103
111
}
104
112
}
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 {
107
116
ret .PackageName = toks [0 ]
108
117
ret .Architecture = toks [1 ]
109
118
} else {
110
- logrus . Warnf ( "Found %d platform for reference: %s" , found , arg )
119
+ return nil , & arduino. MultiplePlatformsError { Platforms : foundPlatforms , UserPlatform : arg }
111
120
}
112
121
return ret , nil
113
122
}
0 commit comments