8000 [breaking] Updated gRPC Platform API by cmaglie · Pull Request #2357 · arduino/arduino-cli · GitHub
[go: up one dir, main page]

Skip to content

[breaking] Updated gRPC Platform API #2357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
28f1f71
Updated gRPC Pltform API, regenerated API
cmaglie Oct 6, 2023
86b171d
Adapted cores.Platform and PlatformRelease to the new gRPC API
cmaglie Oct 16, 2023
2031172
Fixed search_test.go
cmaglie Oct 16, 2023
28cc496
Removed gRPC PlatformList command
cmaglie Oct 16, 2023
24a1dd3
Other adaptation of platform structures
cmaglie Oct 16, 2023
9d2fd89
Adapt arguuments completion to use PlatformSearch instead of Platform…
cmaglie Oct 16, 2023
c80d0ff
Adapt 'core list' to use PlatformSearch instead of PlatformList
cmaglie Oct 16, 2023
175a6d2
Adapt 'core upgrade' command to use PlatformSearch instead of Platfor…
cmaglie Oct 16, 2023
3b41351
Adapted some integration tests
cmaglie Oct 16, 2023
3c7bc1a
Fix integreation test
cmaglie Oct 9, 2023
0a055a6
apply changes to search vidpid
alessio-perugini Oct 10, 2023
f11b45d
Better handling of 'core list' results
cmaglie Oct 10, 2023
abe05fa
Better handling of 'core search' results
cmaglie Oct 10, 2023
7f3a6cb
Better handling of 'core outdated' results
cmaglie Oct 10, 2023
aca91e6
add 'orderedmap' data structure
alessio-perugini Oct 10, 2023
b8ae4f3
Made orderedmap more generic
cmaglie Oct 11, 2023
8c98f74
fix regression on 'ParseReference'
alessio-perugini Oct 11, 2023
6a6897b
wip: fix 'core' integrationtests
alessio-perugini Oct 11, 2023
7ad2ca4
wip: fix 'core' sorting tests
alessio-perugini Oct 11, 2023
cccf397
fix regression which skipped mannually instaled core in core list
alessio-perugini Oct 12, 2023
8b8ce96
wip: add more 'core' integration tests
alessio-perugini Oct 12, 2023
3cee33b
regression: all flag takes precedence above updatable in core list
alessio-perugini Oct 12, 2023
064f57f
lint: ignore unexported-return (revive)
alessio-perugini Oct 12, 2023
ea0854e
license: regenerate and add missin headers
alessio-perugini Oct 12, 2023
64a2631
tests: fix 'board' integrations
alessio-perugini Oct 12, 2023
d010385
fix: regression not showing manually installed platform in 'core list'
alessio-perugini Oct 12, 2023
1d4b9e2
wip: add test to orderedmap
alessio-perugini Oct 12, 2023
87ea190
add more orderdmap tests
alessio-perugini Oct 13, 2023
655a5af
orderdmap: add json tests
alessio-perugini Oct 13, 2023
5fd313c
update DOCS
alessio-perugini Oct 13, 2023
d9dd825
apply CR suggestions
alessio-perugini Oct 16, 2023
494e923
fix proto numeration
alessio-perugini Oct 19, 2023
8528612
docs: update to release 0.36.0
alessio-perugini Oct 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Better handling of 'core list' results
  • Loading branch information
cmaglie authored and alessio-perugini committed Oct 23, 2023
commit f11b45d51fd0948d3774cd990a7b663f7e6830e0
32 changes: 32 additions & 0 deletions .licenses/go/github.com/iancoleman/orderedmap.dep.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: github.com/iancoleman/orderedmap
version: v0.3.0
type: go
summary:
homepage: https://pkg.go.dev/github.com/iancoleman/orderedmap
license: mit
licenses:
- sources: LICENSE
text: |
The MIT License (MIT)

Copyright (c) 2017 Ian Coleman

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, Subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or Substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
notices: []
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/fatih/color v1.15.0
github.com/go-git/go-git/v5 v5.4.2
github.com/gofrs/uuid/v5 v5.0.0
github.com/iancoleman/orderedmap v0.3.0
github.com/leonelquinteros/gotext v1.4.0
github.com/mailru/easyjson v0.7.7
github.com/marcinbor85/gohex v0.0.0-20210308104911-55fb1c624d84
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc=
github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
Expand Down
39 changes: 25 additions & 14 deletions internal/cli/core/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/internal/cli/feedback"
"github.com/arduino/arduino-cli/internal/cli/feedback/result"
"github.com/arduino/arduino-cli/internal/cli/instance"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/arduino-cli/table"
Expand Down Expand Up @@ -55,7 +56,7 @@ func runListCommand(args []string, all bool, updatableOnly bool) {
// List gets and prints a list of installed platforms.
func List(inst *rpc.Instance, all bool, updatableOnly bool) {
platforms := GetList(inst, all, updatableOnly)
feedback.PrintResult(installedResult{platforms})
feedback.PrintResult(newCoreListResult(platforms))
}

// GetList returns a list of installed platforms.
Expand All @@ -81,34 +82,44 @@ func GetList(inst *rpc.Instance, all bool, updatableOnly bool) []*rpc.PlatformSu
return result
}

// output from this command requires special formatting, let's create a dedicated
// feedback.Result implementation
type installedResult struct {
platforms []*rpc.PlatformSummary
func newCoreListResult(in []*rpc.PlatformSummary) *coreListResult {
res := &coreListResult{}
for _, platformSummary := range in {
res.platforms = append(res.platforms, result.NewPlatformResult(platformSummary))
}
return res
}

type coreListResult struct {
platforms []*result.Platform
}

func (ir installedResult) Data() interface{} {
// Data implements Result interface
func (ir coreListResult) Data() interface{} {
return ir.platforms
}

func (ir installedResult) String() string {
// String implements Result interface
func (ir coreListResult) String() string {
if len(ir.platforms) == 0 {
return tr("No platforms installed.")
}
t := table.New()
t.SetHeader(tr("ID"), tr("Installed"), tr("Latest"), tr("Name"))
for _, platform := range ir.platforms {
installedRelease := platform.GetInstalledRelease()
latestRelease := platform.GetLatestRelease()

name := installedRelease.GetName()
name := ""
if installed := platform.GetLatestRelease(); installed != nil {
name = installed.Name
}
if name == "" {
name = latestRelease.GetName()
if latest := platform.GetLatestRelease(); latest != nil {
name = latest.Name
}
}
if platform.Metadata.Deprecated {
if platform.Deprecated {
name = fmt.Sprintf("[%s] %s", tr("DEPRECATED"), name)
}
t.AddRow(platform.Metadata.Id, platform.InstalledVersion, platform.LatestVersion, name)
t.AddRow(platform.Id, platform.InstalledVersion, platform.LatestVersion, name)
}

return t.Render()
Expand Down
146 changes: 146 additions & 0 deletions internal/cli/feedback/result/rpc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// This file is part of arduino-cli.
//
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package result

import (
"slices"

rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/iancoleman/orderedmap"
semver "go.bug.st/relaxed-semver"
)

// NewPlatformResult creates a new result.Platform from rpc.PlatformSummary
func NewPlatformResult(in *rpc.PlatformSummary) *Platform {
meta := in.Metadata
res := &Platform{
Id: meta.Id,
Maintainer: meta.Maintainer,
Website: meta.Website,
Email: meta.Email,
ManuallyInstalled: meta.ManuallyInstalled,
Deprecated: meta.Deprecated,
Indexed: meta.Indexed,

Releases: orderedmap.New(),
InstalledVersion: in.InstalledVersion,
LatestVersion: in.LatestVersion,
}

for k, v := range in.Releases {
res.Releases.Set(k, NewPlatformReleaseResult(v))
}
res.Releases.SortKeys(func(keys []string) {
slices.SortFunc(keys, func(x, y string) int {
return semver.ParseRelaxed(x).CompareTo(semver.ParseRelaxed(y))
})
})

versions := []*semver.RelaxedVersion{}
for version := range in.Releases {
versions = append(versions, semver.ParseRelaxed(version))
}
slices.SortFunc(versions, (*semver.RelaxedVersion).CompareTo)
for _, version := range versions {
res.Releases.Set(version.String(), NewPlatformReleaseResult(in.Releases[version.String()]))
}
return res
}

// Platform maps a rpc.Platform
type Platform struct {
Id string `json:"id,omitempty"`
Maintainer string `json:"maintainer,omitempty"`
Website string `json:"website,omitempty"`
Email string `json:"email,omitempty"`
ManuallyInstalled bool `json:"manually_installed,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
Indexed bool `json:"indexed,omitempty"`

Releases *orderedmap.OrderedMap `json:"releases,omitempty"`

InstalledVersion string `json:"installed_version,omitempty"`
LatestVersion string `json:"latest_version,omitempty"`
}

// GetLatestRelease returns the latest relase of this platform or nil if none available.
func (p *Platform) GetLatestRelease() *PlatformRelease {
res, ok := p.Releases.Get(p.LatestVersion)
if !ok {
return nil
}
return res.(*PlatformRelease)
}

// GetInstalledRelease returns the installed relase of this platform or nil if none available.
func (p *Platform) GetInstalledRelease() *PlatformRelease {
res, ok := p.Releases.Get(p.InstalledVersion)
if !ok {
return nil
}
return res.(*PlatformRelease)
}

// NewPlatformReleaseResult creates a new result.PlatformRelease from rpc.PlatformRelease
func NewPlatformReleaseResult(in *rpc.PlatformRelease) *PlatformRelease {
var boards []*Board
for _, board := range in.Boards {
boards = append(boards, &Board{
Name: board.Name,
Fqbn: board.Fqbn,
})
}
var help *HelpResource
if in.Help != nil {
help = &HelpResource{
Online: in.Help.Online,
}
}
res := &PlatformRelease{
Name: in.Name,
Version: in.Version,
Type: in.Type,
Installed: in.Installed,
Boards: boards,
Help: help,
MissingMetadata: in.MissingMetadata,
Deprecated: in.Deprecated,
}
return res
}

// PlatformRelease maps a rpc.PlatformRelease
type PlatformRelease struct {
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
Type []string `json:"type,omitempty"`
Installed bool `json:"installed,omitempty"`
Boards []*Board `json:"boards,omitempty"`
Help *HelpResource `json:"help,omitempty"`
MissingMetadata bool `json:"missing_metadata,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
}

// Board maps a rpc.Board
type Board struct {
Name string `json:"name,omitempty"`
Fqbn string `json:"fqbn,omitempty"`
}

// HelpResource maps a rpc.HelpResource
type HelpResource struct {
Online string `json:"online,omitempty"`
}
0