Skip to content

Commit d079aa3

Browse files
committed
Created core.PlatformList implementaion follow gRPC naming
Previously it was named GetPlatforms with a different return type than the one defined in gRPC API .proto files.
1 parent 2900744 commit d079aa3

File tree

7 files changed

+49
-18
lines changed

7 files changed

+49
-18
lines changed

Diff for: commands/core/list.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2626
)
2727

28-
// GetPlatforms returns a list of installed platforms, optionally filtered by
28+
// PlatformList returns a list of installed platforms, optionally filtered by
2929
// those requiring an update.
30-
func GetPlatforms(req *rpc.PlatformListRequest) ([]*rpc.Platform, error) {
30+
func PlatformList(req *rpc.PlatformListRequest) (*rpc.PlatformListResponse, error) {
3131
pme, release := commands.GetPackageManagerExplorer(req)
3232
if pme == nil {
3333
return nil, &arduino.InvalidInstanceError{}
@@ -85,5 +85,5 @@ func GetPlatforms(req *rpc.PlatformListRequest) ([]*rpc.Platform, error) {
8585
}
8686
return false
8787
})
88-
return res, nil
88+
return &rpc.PlatformListResponse{InstalledPlatforms: res}, nil
8989
}

Diff for: commands/daemon/daemon.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,8 @@ func (s *ArduinoCoreServerImpl) PlatformSearch(ctx context.Context, req *rpc.Pla
277277

278278
// PlatformList FIXMEDOC
279279
func (s *ArduinoCoreServerImpl) PlatformList(ctx context.Context, req *rpc.PlatformListRequest) (*rpc.PlatformListResponse, error) {
280-
platforms, err := core.GetPlatforms(req)
281-
if err != nil {
282-
return nil, convertErrorToRPCStatus(err)
283-
}
284-
return &rpc.PlatformListResponse{InstalledPlatforms: platforms}, nil
280+
platforms, err := core.PlatformList(req)
281+
return platforms, convertErrorToRPCStatus(err)
285282
}
286283

287284
// Upload FIXMEDOC

Diff for: docs/UPGRADING.md

+34
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,40 @@ $ arduino-cli outdated --format json
5555

5656
That method was outdated and must not be used.
5757

58+
### golang API: method `github.com/arduino/arduino-cli/commands/core/GetPlatforms` renamed
59+
60+
The following method in `github.com/arduino/arduino-cli/commands/core`:
61+
62+
```go
63+
func GetPlatforms(req *rpc.PlatformListRequest) ([]*rpc.Platform, error) { ... }
64+
```
65+
66+
has been changed to:
67+
68+
```go
69+
func PlatformList(req *rpc.PlatformListRequest) (*rpc.PlatformListResponse, error) { ... }
70+
```
71+
72+
now it better follows the gRPC API interface. Old code like the following:
73+
74+
```go
75+
platforms, _ := core.GetPlatforms(&rpc.PlatformListRequest{Instance: inst})
76+
for _, i := range platforms {
77+
...
78+
}
79+
```
80+
81+
must be changed as follows:
82+
83+
```go
84+
// Use PlatformList function instead of GetPlatforms
85+
platforms, _ := core.PlatformList(&rpc.PlatformListRequest{Instance: inst})
86+
// Access installed platforms through the .InstalledPlatforms field
87+
for _, i := range platforms.InstalledPlatforms {
88+
...
89+
}
90+
```
91+
5892
## 0.31.0
5993

6094
### Added `post_install` script support for tools

Diff for: internal/cli/arguments/completion.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ func GetInstalledProgrammers() []string {
109109
func GetUninstallableCores() []string {
110110
inst := instance.CreateAndInit()
111111

112-
platforms, _ := core.GetPlatforms(&rpc.PlatformListRequest{
112+
platforms, _ := core.PlatformList(&rpc.PlatformListRequest{
113113
Instance: inst,
114114
UpdatableOnly: false,
115115
All: false,
116116
})
117117
var res []string
118118
// transform the data structure for the completion
119-
for _, i := range platforms {
119+
for _, i := range platforms.InstalledPlatforms {
120120
res = append(res, i.Id+"\t"+i.Name)
121121
}
122122
return res

Diff for: internal/cli/arguments/reference.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ func ParseReference(arg string) (*Reference, error) {
9292
ret.Architecture = toks[1]
9393

9494
// Now that we have the required informations in `ret` we can
95-
// try to use core.GetPlatforms to optimize what the user typed
95+
// try to use core.PlatformList to optimize what the user typed
9696
// (by replacing the PackageName and Architecture in ret with the content of core.GetPlatform())
97-
platforms, _ := core.GetPlatforms(&rpc.PlatformListRequest{
97+
platforms, _ := core.PlatformList(&rpc.PlatformListRequest{
9898
Instance: instance.CreateAndInit(),
9999
UpdatableOnly: false,
100100
All: true, // this is true because we want also the installable platforms
101101
})
102102
foundPlatforms := []string{}
103-
for _, platform := range platforms {
103+
for _, platform := range platforms.InstalledPlatforms {
104104
platformID := platform.GetId()
105105
platformUser := ret.PackageName + ":" + ret.Architecture
106106
// At first we check if the platform the user is searching for matches an available one,

Diff for: internal/cli/core/list.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ func List(inst *rpc.Instance, all bool, updatableOnly bool) {
6060

6161
// GetList returns a list of installed platforms.
6262
func GetList(inst *rpc.Instance, all bool, updatableOnly bool) []*rpc.Platform {
63-
platforms, err := core.GetPlatforms(&rpc.PlatformListRequest{
63+
platforms, err := core.PlatformList(&rpc.PlatformListRequest{
6464
Instance: inst,
6565
UpdatableOnly: updatableOnly,
6666
All: all,
6767
})
6868
if err != nil {
6969
feedback.Fatal(tr("Error listing platforms: %v", err), feedback.ErrGeneric)
7070
}
71-
return platforms
71+
return platforms.InstalledPlatforms
7272
}
7373

7474
// output from this command requires special formatting, let's create a dedicated

Diff for: internal/cli/core/upgrade.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,20 @@ func runUpgradeCommand(args []string, skipPostInstall bool) {
6060
func Upgrade(inst *rpc.Instance, args []string, skipPostInstall bool) {
6161
// if no platform was passed, upgrade allthethings
6262
if len(args) == 0 {
63-
targets, err := core.GetPlatforms(&rpc.PlatformListRequest{
63+
targets, err := core.PlatformList(&rpc.PlatformListRequest{
6464
Instance: inst,
6565
UpdatableOnly: true,
6666
})
6767
if err != nil {
6868
feedback.Fatal(tr("Error retrieving core list: %v", err), feedback.ErrGeneric)
6969
}
7070

71-
if len(targets) == 0 {
71+
if len(targets.InstalledPlatforms) == 0 {
7272
feedback.Print(tr("All the cores are already at the latest version"))
7373
return
7474
}
7575

76-
for _, t := range targets {
76+
for _, t := range targets.InstalledPlatforms {
7777
args = append(args, t.Id)
7878
}
7979
}

0 commit comments

Comments
 (0)