Skip to content

Commit 1ad8fca

Browse files
committed
[breaking] make packages and platform case insensitive pt 4
using the `core.GetPlatform()` approach
1 parent 63769ae commit 1ad8fca

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

cli/arguments/reference.go

+19
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ package arguments
1818
import (
1919
"fmt"
2020
"strings"
21+
22+
"github.com/arduino/arduino-cli/cli/instance"
23+
"github.com/arduino/arduino-cli/commands/core"
24+
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2125
)
2226

2327
// Reference represents a reference item (core or library) passed to the CLI
@@ -80,5 +84,20 @@ func ParseReference(arg string) (*Reference, error) {
8084
}
8185
ret.Architecture = toks[1]
8286

87+
// We try to optimize the search and help the user
88+
platforms, _ := core.GetPlatforms(&rpc.PlatformListRequest{
89+
Instance: instance.CreateAndInit(),
90+
UpdatableOnly: false,
91+
All: true,
92+
})
93+
for _, platform := range platforms {
94+
if strings.EqualFold(platform.GetId(), ret.PackageName+":"+ret.Architecture) {
95+
toks = strings.Split(platform.GetId(), ":")
96+
ret.PackageName = toks[0]
97+
ret.Architecture = toks[1]
98+
break // is it ok to stop at the first result?
99+
}
100+
}
101+
83102
return ret, nil
84103
}

docs/UPGRADING.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ always parsed by the function.
1212
### `ParseReference() function change in `arduino-cli` package
1313

1414
The `parseArch` parameter was removed since it was unused and was always true. This means that the architecture gets
15-
always parsed by the function.
15+
always parsed by the function. Furthermore the function now should also correctly interpret `packager:arch` spelled with
16+
the wrong casing.
1617

1718
## 0.20.0
1819

0 commit comments

Comments
 (0)