Skip to content

Commit 8b5179d

Browse files
authored
[skip changelog] Fix core commands skipping gRPC interface (arduino#1169)
1 parent a9b0c9d commit 8b5179d

File tree

7 files changed

+66
-33
lines changed

7 files changed

+66
-33
lines changed

cli/core/list.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import (
1919
"os"
2020
"sort"
2121

22-
"github.com/arduino/arduino-cli/arduino/cores"
2322
"github.com/arduino/arduino-cli/cli/errorcodes"
2423
"github.com/arduino/arduino-cli/cli/feedback"
2524
"github.com/arduino/arduino-cli/cli/instance"
2625
"github.com/arduino/arduino-cli/commands/core"
26+
rpc "github.com/arduino/arduino-cli/rpc/commands"
2727
"github.com/arduino/arduino-cli/table"
2828
"github.com/sirupsen/logrus"
2929
"github.com/spf13/cobra"
@@ -55,7 +55,10 @@ func runListCommand(cmd *cobra.Command, args []string) {
5555

5656
logrus.Info("Executing `arduino core list`")
5757

58-
platforms, err := core.GetPlatforms(inst.Id, listFlags.updatableOnly)
58+
platforms, err := core.GetPlatforms(&rpc.PlatformListReq{
59+
Instance: inst,
60+
UpdatableOnly: listFlags.updatableOnly,
61+
})
5962
if err != nil {
6063
feedback.Errorf("Error listing platforms: %v", err)
6164
os.Exit(errorcodes.ErrGeneric)
@@ -67,7 +70,7 @@ func runListCommand(cmd *cobra.Command, args []string) {
6770
// output from this command requires special formatting, let's create a dedicated
6871
// feedback.Result implementation
6972
type installedResult struct {
70-
platforms []*cores.PlatformRelease
73+
platforms []*rpc.Platform
7174
}
7275

7376
func (ir installedResult) Data() interface{} {
@@ -82,10 +85,10 @@ func (ir installedResult) String() string {
8285
t := table.New()
8386
t.SetHeader("ID", "Installed", "Latest", "Name")
8487
sort.Slice(ir.platforms, func(i, j int) bool {
85-
return ir.platforms[i].Platform.String() < ir.platforms[j].Platform.String()
88+
return ir.platforms[i].ID < ir.platforms[j].ID
8689
})
8790
for _, p := range ir.platforms {
88-
t.AddRow(p.Platform.String(), p.Version.String(), p.Platform.GetLatestRelease().Version.String(), p.Platform.Name)
91+
t.AddRow(p.ID, p.Installed, p.Latest, p.Name)
8992
}
9093

9194
return t.Render()

cli/core/search.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
6969
arguments := strings.ToLower(strings.Join(args, " "))
7070
logrus.Infof("Executing `arduino core search` with args: '%s'", arguments)
7171

72-
resp, err := core.PlatformSearch(inst.GetId(), arguments, allVersions)
72+
resp, err := core.PlatformSearch(&rpc.PlatformSearchReq{
73+
Instance: inst,
74+
SearchArgs: arguments,
75+
AllVersions: allVersions,
76+
})
7377
if err != nil {
7478
feedback.Errorf("Error searching for platforms: %v", err)
7579
os.Exit(errorcodes.ErrGeneric)

cli/core/upgrade.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
5757

5858
// if no platform was passed, upgrade allthethings
5959
if len(args) == 0 {
60-
targets, err := core.GetPlatforms(inst.Id, true)
60+
targets, err := core.GetPlatforms(&rpc.PlatformListReq{
61+
Instance: inst,
62+
UpdatableOnly: true,
63+
})
6164
if err != nil {
6265
feedback.Errorf("Error retrieving core list: %v", err)
6366
os.Exit(errorcodes.ErrGeneric)
@@ -69,7 +72,7 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
6972
}
7073

7174
for _, t := range targets {
72-
args = append(args, t.Platform.String())
75+
args = append(args, t.ID)
7376
}
7477
}
7578

commands/core/list.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
package core
1717

1818
import (
19-
"github.com/arduino/arduino-cli/arduino/cores"
2019
"github.com/arduino/arduino-cli/commands"
20+
rpc "github.com/arduino/arduino-cli/rpc/commands"
2121
"github.com/pkg/errors"
2222
)
2323

2424
// GetPlatforms returns a list of installed platforms, optionally filtered by
2525
// those requiring an update.
26-
func GetPlatforms(instanceID int32, updatableOnly bool) ([]*cores.PlatformRelease, error) {
26+
func GetPlatforms(req *rpc.PlatformListReq) ([]*rpc.Platform, error) {
27+
instanceID := req.Instance.Id
2728
i := commands.GetInstance(instanceID)
2829
if i == nil {
2930
return nil, errors.Errorf("unable to find an instance with ID: %d", instanceID)
@@ -34,17 +35,20 @@ func GetPlatforms(instanceID int32, updatableOnly bool) ([]*cores.PlatformReleas
3435
return nil, errors.New("invalid instance")
3536
}
3637

37-
res := []*cores.PlatformRelease{}
38+
res := []*rpc.Platform{}
3839
for _, targetPackage := range packageManager.Packages {
3940
for _, platform := range targetPackage.Platforms {
40-
if platformRelease := packageManager.GetInstalledPlatformRelease(platform); platformRelease != nil {
41-
if updatableOnly {
41+
platformRelease := packageManager.GetInstalledPlatformRelease(platform)
42+
if platformRelease != nil {
43+
if req.UpdatableOnly {
4244
if latest := platform.GetLatestRelease(); latest == nil || latest == platformRelease {
4345
continue
4446
}
4547
}
4648

47-
res = append(res, platformRelease)
49+
rpcPlatform := commands.PlatformReleaseToRPC(platformRelease)
50+
rpcPlatform.Installed = platformRelease.Version.String()
51+
res = append(res, rpcPlatform)
4852
}
4953
}
5054
}

commands/core/search.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ func exactMatch(line, searchArgs string) bool {
3434
}
3535

3636
// PlatformSearch FIXMEDOC
37-
func PlatformSearch(instanceID int32, searchArgs string, allVersions bool) (*rpc.PlatformSearchResp, error) {
38-
pm := commands.GetPackageManager(instanceID)
37+
func PlatformSearch(req *rpc.PlatformSearchReq) (*rpc.PlatformSearchResp, error) {
38+
searchArgs := req.SearchArgs
39+
allVersions := req.AllVersions
40+
pm := commands.GetPackageManager(req.Instance.Id)
3941
if pm == nil {
4042
return nil, errors.New("invalid instance")
4143
}

commands/core/search_test.go

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/arduino/arduino-cli/cli/instance"
2323
"github.com/arduino/arduino-cli/configuration"
2424
"github.com/arduino/arduino-cli/rpc/commands"
25+
rpc "github.com/arduino/arduino-cli/rpc/commands"
2526
"github.com/arduino/go-paths-helper"
2627
"github.com/stretchr/testify/assert"
2728
"github.com/stretchr/testify/require"
@@ -52,7 +53,11 @@ func TestPlatformSearch(t *testing.T) {
5253
require.Nil(t, err)
5354
require.NotNil(t, inst)
5455

55-
res, err := PlatformSearch(inst.GetId(), "retrokit", true)
56+
res, err := PlatformSearch(&rpc.PlatformSearchReq{
57+
Instance: inst,
58+
SearchArgs: "retrokit",
59+
AllVersions: true,
60+
})
5661
require.Nil(t, err)
5762
require.NotNil(t, res)
5863

@@ -78,7 +83,11 @@ func TestPlatformSearch(t *testing.T) {
7883
Boards: []*commands.Board{{Name: "RK002"}},
7984
})
8085

81-
res, err = PlatformSearch(inst.GetId(), "retrokit", false)
86+
res, err = PlatformSearch(&rpc.PlatformSearchReq{
87+
Instance: inst,
88+
SearchArgs: "retrokit",
89+
AllVersions: false,
90+
})
8291
require.Nil(t, err)
8392
require.NotNil(t, res)
8493
require.Len(t, res.SearchOutput, 1)
@@ -94,7 +103,11 @@ func TestPlatformSearch(t *testing.T) {
94103
})
95104

96105
// Search the Package Maintainer
97-
res, err = PlatformSearch(inst.GetId(), "Retrokits (www.retrokits.com)", true)
106+
res, err = PlatformSearch(&rpc.PlatformSearchReq{
107+
Instance: inst,
108+
SearchArgs: "Retrokits (www.retrokits.com)",
109+
AllVersions: true,
110+
})
98111
require.Nil(t, err)
99112
require.NotNil(t, res)
100113
require.Len(t, res.SearchOutput, 2)
@@ -120,7 +133,11 @@ func TestPlatformSearch(t *testing.T) {
120133
})
121134

122135
// Search using the Package name
123-
res, err = PlatformSearch(inst.GetId(), "Retrokits-RK002", true)
136+
res, err = PlatformSearch(&rpc.PlatformSearchReq{
137+
Instance: inst,
138+
SearchArgs: "Retrokits-RK002",
139+
AllVersions: true,
140+
})
124141
require.Nil(t, err)
125142
require.NotNil(t, res)
126143
require.Len(t, res.SearchOutput, 2)
@@ -146,7 +163,11 @@ func TestPlatformSearch(t *testing.T) {
146163
})
147164

148165
// Search using the Platform name
149-
res, err = PlatformSearch(inst.GetId(), "rk002", true)
166+
res, err = PlatformSearch(&rpc.PlatformSearchReq{
167+
Instance: inst,
168+
SearchArgs: "rk002",
169+
AllVersions: true,
170+
})
150171
require.Nil(t, err)
151172
require.NotNil(t, res)
152173
require.Len(t, res.SearchOutput, 2)
@@ -172,7 +193,11 @@ func TestPlatformSearch(t *testing.T) {
172193
})
173194

174195
// Search using a board name
175-
res, err = PlatformSearch(inst.GetId(), "Yún", true)
196+
res, err = PlatformSearch(&rpc.PlatformSearchReq{
197+
Instance: inst,
198+
SearchArgs: "Yún",
199+
AllVersions: true,
200+
})
176201
require.Nil(t, err)
177202
require.NotNil(t, res)
178203
require.Len(t, res.SearchOutput, 1)

commands/daemon/daemon.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -259,24 +259,16 @@ func (s *ArduinoCoreServerImpl) PlatformUpgrade(req *rpc.PlatformUpgradeReq, str
259259

260260
// PlatformSearch FIXMEDOC
261261
func (s *ArduinoCoreServerImpl) PlatformSearch(ctx context.Context, req *rpc.PlatformSearchReq) (*rpc.PlatformSearchResp, error) {
262-
return core.PlatformSearch(req.GetInstance().GetId(), req.GetSearchArgs(), req.GetAllVersions())
262+
return core.PlatformSearch(req)
263263
}
264264

265265
// PlatformList FIXMEDOC
266266
func (s *ArduinoCoreServerImpl) PlatformList(ctx context.Context, req *rpc.PlatformListReq) (*rpc.PlatformListResp, error) {
267-
platforms, err := core.GetPlatforms(req.Instance.Id, req.UpdatableOnly)
267+
platforms, err := core.GetPlatforms(req)
268268
if err != nil {
269269
return nil, err
270270
}
271-
272-
installed := []*rpc.Platform{}
273-
for _, p := range platforms {
274-
rpcPlatform := commands.PlatformReleaseToRPC(p)
275-
rpcPlatform.Installed = p.Version.String()
276-
installed = append(installed, rpcPlatform)
277-
}
278-
279-
return &rpc.PlatformListResp{InstalledPlatform: installed}, nil
271+
return &rpc.PlatformListResp{InstalledPlatform: platforms}, nil
280272
}
281273

282274
// Upload FIXMEDOC

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy