Skip to content

Commit 11c7cea

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

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

cli/arguments/reference.go

Lines changed: 19 additions & 0 deletions
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
}

cli/arguments/reference_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"testing"
2020

2121
"github.com/arduino/arduino-cli/cli/arguments"
22+
"github.com/arduino/arduino-cli/configuration"
2223
"github.com/stretchr/testify/assert"
2324
"github.com/stretchr/testify/require"
2425
)
@@ -45,6 +46,10 @@ var badCores = []struct {
4546
{"", nil},
4647
}
4748

49+
func init() {
50+
configuration.Settings = configuration.Init("")
51+
}
52+
4853
func TestArgsStringify(t *testing.T) {
4954
for _, core := range goodCores {
5055
require.Equal(t, core.in, core.expected.String())

docs/UPGRADING.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ Here you can find a list of migration guides to handle breaking changes between
44

55
## Unreleased
66

7-
### `ParseReferences() function change in `arduino-cli` package
7+
### `ParseReferences() function change in`arduino-cli` package
88

99
The `parseArch` parameter was removed since it was unused and was always true. This means that the architecture gets
1010
always parsed by the function.
1111

12-
### `ParseReference() function change in `arduino-cli` package
12+
### `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)