Skip to content

Commit e5da0d6

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 1877431 commit e5da0d6

File tree

7 files changed

+49
-18
lines changed

7 files changed

+49
-18
lines changed

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
}

commands/daemon/daemon.go

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

285285
// PlatformList FIXMEDOC
286286
func (s *ArduinoCoreServerImpl) PlatformList(ctx context.Context, req *rpc.PlatformListRequest) (*rpc.PlatformListResponse, error) {
287-
platforms, err := core.GetPlatforms(req)
288-
if err != nil {
289-
return nil, convertErrorToRPCStatus(err)
290-
}
291-
return &rpc.PlatformListResponse{InstalledPlatforms: platforms}, nil
287+
platforms, err := core.PlatformList(req)
288+
return platforms, convertErrorToRPCStatus(err)
292289
}
293290

294291
// Upload FIXMEDOC

docs/UPGRADING.md

+34
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,40 @@ has been removed as well.
118118

119119
That method was outdated and must not be used.
120120

121+
### golang API: method `github.com/arduino/arduino-cli/commands/core/GetPlatforms` renamed
122+
123+
The following method in `github.com/arduino/arduino-cli/commands/core`:
124+
125+
```go
126+
func GetPlatforms(req *rpc.PlatformListRequest) ([]*rpc.Platform, error) { ... }
127+
```
128+
129+
has been changed to:
130+
131+
```go
132+
func PlatformList(req *rpc.PlatformListRequest) (*rpc.PlatformListResponse, error) { ... }
133+
```
134+
135+
now it better follows the gRPC API interface. Old code like the following:
136+
137+
```go
138+
platforms, _ := core.GetPlatforms(&rpc.PlatformListRequest{Instance: inst})
139+
for _, i := range platforms {
140+
...
141+
}
142+
```
143+
144+
must be changed as follows:
145+
146+
```go
147+
// Use PlatformList function instead of GetPlatforms
148+
platforms, _ := core.PlatformList(&rpc.PlatformListRequest{Instance: inst})
149+
// Access installed platforms through the .InstalledPlatforms field
150+
for _, i := range platforms.InstalledPlatforms {
151+
...
152+
}
153+
```
154+
121155
## 0.31.0
122156

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

internal/cli/arguments/completion.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ func GetInstalledProgrammers() []string {
124124
func GetUninstallableCores() []string {
125125
inst := instance.CreateAndInit()
126126

127-
platforms, _ := core.GetPlatforms(&rpc.PlatformListRequest{
127+
platforms, _ := core.PlatformList(&rpc.PlatformListRequest{
128128
Instance: inst,
129129
UpdatableOnly: false,
130130
All: false,
131131
})
132132
var res []string
133133
// transform the data structure for the completion
134-
for _, i := range platforms {
134+
for _, i := range platforms.InstalledPlatforms {
135135
res = append(res, i.Id+"\t"+i.Name)
136136
}
137137
return res

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,

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

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)