Skip to content

Commit a5e5483

Browse files
Christian Weichelmasci
Christian Weichel
authored andcommitted
Core search/list now return boards in a platform (#268)
Signed-off-by: Christian Weichel <[email protected]>
1 parent f0369bc commit a5e5483

File tree

7 files changed

+229
-154
lines changed

7 files changed

+229
-154
lines changed

Diff for: cli/core/list.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func runListCommand(cmd *cobra.Command, args []string) {
6969
}
7070
}
7171

72-
func outputInstalledCores(cores []*rpc.InstalledPlatform) {
72+
func outputInstalledCores(cores []*rpc.Platform) {
7373
table := output.NewTable()
7474
table.AddRow("ID", "Installed", "Latest", "Name")
7575
sort.Slice(cores, func(i, j int) bool {

Diff for: cli/core/search.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
7171
}
7272
}
7373

74-
func outputSearchCores(cores []*rpc.SearchOutput) {
74+
func outputSearchCores(cores []*rpc.Platform) {
7575
table := output.NewTable()
7676
table.AddRow("ID", "Version", "Name")
7777
sort.Slice(cores, func(i, j int) bool {
7878
return cores[i].ID < cores[j].ID
7979
})
8080
for _, item := range cores {
81-
table.AddRow(item.GetID(), item.GetVersion(), item.GetName())
81+
table.AddRow(item.GetID(), item.GetLatest(), item.GetName())
8282
}
8383
fmt.Print(table.Render())
8484
}

Diff for: commands/core/core.go

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* This file is part of arduino-cli.
3+
*
4+
* Copyright 2019 ARDUINO SA (http://www.arduino.cc/)
5+
*
6+
* This software is released under the GNU General Public License version 3,
7+
* which covers the main part of arduino-cli.
8+
* The terms of this license can be found at:
9+
* https://www.gnu.org/licenses/gpl-3.0.en.html
10+
*
11+
* You can be released from the requirements of the above licenses by purchasing
12+
* a commercial license. Buying such a license is mandatory if you want to modify or
13+
* otherwise use the software for commercial activities involving the Arduino
14+
* software without disclosing the source code of your own applications. To purchase
15+
* a commercial license, send an email to [email protected].
16+
*/
17+
18+
package core
19+
20+
import (
21+
"github.com/arduino/arduino-cli/arduino/cores"
22+
rpc "github.com/arduino/arduino-cli/rpc/commands"
23+
)
24+
25+
// platformReleaseToRPC converts our internal structure to the RPC structure.
26+
// Note: this function does not touch the "Installed" field of rpc.Platform as it's not always clear that the
27+
// platformRelease we're currently converting is actually installed.
28+
func platformReleaseToRPC(platformRelease *cores.PlatformRelease) *rpc.Platform {
29+
boards := make([]*rpc.Board, len(platformRelease.Boards))
30+
i := 0
31+
for _, b := range platformRelease.Boards {
32+
boards[i] = &rpc.Board{
33+
Name: b.Name(),
34+
Fqbn: b.FQBN(),
35+
}
36+
i++
37+
}
38+
39+
result := &rpc.Platform{
40+
ID: platformRelease.Platform.String(),
41+
Name: platformRelease.Platform.Name,
42+
Maintainer: platformRelease.Platform.Package.Maintainer,
43+
Website: platformRelease.Platform.Package.WebsiteURL,
44+
Email: platformRelease.Platform.Package.Email,
45+
Boards: boards,
46+
}
47+
48+
latest := platformRelease.Platform.GetLatestRelease()
49+
if latest != nil {
50+
result.Latest = latest.Version.String()
51+
}
52+
53+
return result
54+
}

Diff for: commands/core/list.go

+4-9
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func PlatformList(ctx context.Context, req *rpc.PlatformListReq) (*rpc.PlatformL
3232
return nil, errors.New("invalid instance")
3333
}
3434

35-
installed := []*rpc.InstalledPlatform{}
35+
installed := []*rpc.Platform{}
3636
for _, targetPackage := range pm.GetPackages().Packages {
3737
for _, platform := range targetPackage.Platforms {
3838
if platformRelease := pm.GetInstalledPlatformRelease(platform); platformRelease != nil {
@@ -41,14 +41,9 @@ func PlatformList(ctx context.Context, req *rpc.PlatformListReq) (*rpc.PlatformL
4141
continue
4242
}
4343
}
44-
p := &rpc.InstalledPlatform{
45-
ID: platformRelease.String(),
46-
Installed: platformRelease.Version.String(),
47-
Name: platformRelease.Platform.Name,
48-
}
49-
if latest := platformRelease.Platform.GetLatestRelease(); latest != nil {
50-
p.Latest = latest.Version.String()
51-
}
44+
45+
p := platformReleaseToRPC(platformRelease)
46+
p.Installed = platformRelease.Version.String()
5247
installed = append(installed, p)
5348
}
5449
}

Diff for: commands/core/search.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,9 @@ func PlatformSearch(ctx context.Context, req *rpc.PlatformSearchReq) (*rpc.Platf
6565
}
6666
}
6767

68-
out := []*rpc.SearchOutput{}
69-
for _, platformRelease := range res {
70-
out = append(out, &rpc.SearchOutput{
71-
ID: platformRelease.Platform.String(),
72-
Name: platformRelease.Platform.Name,
73-
Version: platformRelease.Version.String(),
74-
})
68+
out := make([]*rpc.Platform, len(res))
69+
for i, platformRelease := range res {
70+
out[i] = platformReleaseToRPC(platformRelease)
7571
}
7672
return &rpc.PlatformSearchResp{SearchOutput: out}, nil
7773
}

0 commit comments

Comments
 (0)