Skip to content

Create gRPC interface for update, upgrade and outdated commands #903

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 1 commit into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 10 additions & 24 deletions cli/outdated/outdated.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import (
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/feedback"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/commands/lib"
"github.com/arduino/arduino-cli/commands"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/arduino/arduino-cli/table"
"github.com/sirupsen/logrus"
Expand All @@ -48,47 +47,34 @@ func NewCommand() *cobra.Command {
func runOutdatedCommand(cmd *cobra.Command, args []string) {
inst, err := instance.CreateInstance()
if err != nil {
feedback.Errorf("Error upgrading: %v", err)
feedback.Errorf("Error running outdated command: %v", err)
os.Exit(errorcodes.ErrGeneric)
}

logrus.Info("Executing `arduino outdated`")

// Gets outdated cores
targets, err := core.GetPlatforms(inst.Id, true)
if err != nil {
feedback.Errorf("Error retrieving core list: %v", err)
os.Exit(errorcodes.ErrGeneric)
}

// Gets outdated libraries
res, err := lib.LibraryList(context.Background(), &rpc.LibraryListReq{
Instance: inst,
All: false,
Updatable: true,
outdatedResp, err := commands.Outdated(context.Background(), &rpc.OutdatedReq{
Instance: inst,
})
if err != nil {
feedback.Errorf("Error retrieving library list: %v", err)
os.Exit(errorcodes.ErrGeneric)
feedback.Errorf("Error retrieving outdated cores and libraries: %v", err)
}

// Prints outdated cores
tab := table.New()
tab.SetHeader("Core name", "Installed version", "New version")
if len(targets) > 0 {
for _, t := range targets {
plat := t.Platform
tab.AddRow(plat.Name, t.Version, plat.GetLatestRelease().Version)
if len(outdatedResp.OutdatedPlatform) > 0 {
for _, p := range outdatedResp.OutdatedPlatform {
tab.AddRow(p.Name, p.Installed, p.Latest)
}
feedback.Print(tab.Render())
}

// Prints outdated libraries
tab = table.New()
tab.SetHeader("Library name", "Installed version", "New version")
libs := res.GetInstalledLibrary()
if len(libs) > 0 {
for _, l := range libs {
if len(outdatedResp.OutdatedLibrary) > 0 {
for _, l := range outdatedResp.OutdatedLibrary {
tab.AddRow(l.Library.Name, l.Library.Version, l.Release.Version)
}
feedback.Print(tab.Render())
Expand Down
44 changes: 10 additions & 34 deletions cli/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/commands/lib"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/arduino/arduino-cli/table"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -55,63 +53,41 @@ func runUpdateCommand(cmd *cobra.Command, args []string) {

logrus.Info("Executing `arduino update`")

_, err := commands.UpdateIndex(context.Background(), &rpc.UpdateIndexReq{
err := commands.UpdateCoreLibrariesIndex(context.Background(), &rpc.UpdateCoreLibrariesIndexReq{
Instance: instance,
}, output.ProgressBar())
if err != nil {
feedback.Errorf("Error updating core index: %v", err)
os.Exit(errorcodes.ErrGeneric)
}

err = commands.UpdateLibrariesIndex(context.Background(), &rpc.UpdateLibrariesIndexReq{
Instance: instance,
}, output.ProgressBar())
if err != nil {
feedback.Errorf("Error updating library index: %v", err)
feedback.Errorf("Error updating core and libraries index: %v", err)
os.Exit(errorcodes.ErrGeneric)
}

if updateFlags.showOutdated {
// Gets outdated cores
targets, err := core.GetPlatforms(instance.Id, true)
if err != nil {
feedback.Errorf("Error retrieving core list: %v", err)
os.Exit(errorcodes.ErrGeneric)
}

// Gets outdated libraries
res, err := lib.LibraryList(context.Background(), &rpc.LibraryListReq{
Instance: instance,
All: false,
Updatable: true,
outdatedResp, err := commands.Outdated(context.Background(), &rpc.OutdatedReq{
Instance: instance,
})
if err != nil {
feedback.Errorf("Error retrieving library list: %v", err)
os.Exit(errorcodes.ErrGeneric)
feedback.Errorf("Error retrieving outdated cores and libraries: %v", err)
}

// Prints outdated cores
tab := table.New()
tab.SetHeader("Core name", "Installed version", "New version")
if len(targets) > 0 {
for _, t := range targets {
plat := t.Platform
tab.AddRow(plat.Name, t.Version, plat.GetLatestRelease().Version)
if len(outdatedResp.OutdatedPlatform) > 0 {
for _, p := range outdatedResp.OutdatedPlatform {
tab.AddRow(p.Name, p.Installed, p.Latest)
}
feedback.Print(tab.Render())
}

// Prints outdated libraries
tab = table.New()
tab.SetHeader("Library name", "Installed version", "New version")
libs := res.GetInstalledLibrary()
if len(libs) > 0 {
for _, l := range libs {
if len(outdatedResp.OutdatedLibrary) > 0 {
for _, l := range outdatedResp.OutdatedLibrary {
tab.AddRow(l.Library.Name, l.Library.Version, l.Release.Version)
}
feedback.Print(tab.Render())
}

}

logrus.Info("Done")
Expand Down
45 changes: 5 additions & 40 deletions cli/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import (
"github.com/arduino/arduino-cli/cli/feedback"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/commands/lib"
"github.com/arduino/arduino-cli/commands"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -53,46 +52,12 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {

logrus.Info("Executing `arduino upgrade`")

// Gets list of libraries to upgrade, cores' libraries are ignored since they're upgraded
// when the core is
res, err := lib.LibraryList(context.Background(), &rpc.LibraryListReq{
Instance: inst,
All: false,
Updatable: true,
})
if err != nil {
feedback.Errorf("Error retrieving library list: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
libraries := []string{}
for _, l := range res.InstalledLibrary {
libraries = append(libraries, l.Library.Name)
}

// Upgrades libraries
err = lib.LibraryUpgrade(inst.Id, libraries, output.ProgressBar(), output.TaskProgress())
if err != nil {
feedback.Errorf("Error upgrading libraries: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
err = commands.Upgrade(context.Background(), &rpc.UpgradeReq{
Instance: inst,
}, output.NewDownloadProgressBarCB(), output.TaskProgress())

targets, err := core.GetPlatforms(inst.Id, true)
if err != nil {
feedback.Errorf("Error retrieving core list: %v", err)
os.Exit(errorcodes.ErrGeneric)
}

for _, t := range targets {
r := &rpc.PlatformUpgradeReq{
Instance: inst,
PlatformPackage: t.Platform.Package.Name,
Architecture: t.Platform.Architecture,
}
_, err := core.PlatformUpgrade(context.Background(), r, output.ProgressBar(), output.TaskProgress())
if err != nil {
feedback.Errorf("Error during upgrade: %v", err)
os.Exit(errorcodes.ErrGeneric)
}
feedback.Errorf("Error upgrading: %v", err)
}

logrus.Info("Done")
Expand Down
2 changes: 1 addition & 1 deletion commands/core/core.go → commands/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package core
package commands

import (
"github.com/arduino/arduino-cli/arduino/cores"
Expand Down
2 changes: 1 addition & 1 deletion commands/core/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func PlatformSearch(instanceID int32, searchArgs string, allVersions bool) (*rpc

out := make([]*rpc.Platform, len(res))
for i, platformRelease := range res {
out[i] = PlatformReleaseToRPC(platformRelease)
out[i] = commands.PlatformReleaseToRPC(platformRelease)
}
return &rpc.PlatformSearchResp{SearchOutput: out}, nil
}
38 changes: 37 additions & 1 deletion commands/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,42 @@ func (s *ArduinoCoreServerImpl) UpdateLibrariesIndex(req *rpc.UpdateLibrariesInd
return stream.Send(&rpc.UpdateLibrariesIndexResp{})
}

// UpdateCoreLibrariesIndex FIXMEDOC
func (s *ArduinoCoreServerImpl) UpdateCoreLibrariesIndex(req *rpc.UpdateCoreLibrariesIndexReq, stream rpc.ArduinoCore_UpdateCoreLibrariesIndexServer) error {
err := commands.UpdateCoreLibrariesIndex(stream.Context(), req,
func(p *rpc.DownloadProgress) { stream.Send(&rpc.UpdateCoreLibrariesIndexResp{DownloadProgress: p}) },
)
if err != nil {
return err
}
return stream.Send(&rpc.UpdateCoreLibrariesIndexResp{})
}

// Outdated FIXMEDOC
func (s *ArduinoCoreServerImpl) Outdated(ctx context.Context, req *rpc.OutdatedReq) (*rpc.OutdatedResp, error) {
return commands.Outdated(ctx, req)
}

// Upgrade FIXMEDOC
func (s *ArduinoCoreServerImpl) Upgrade(req *rpc.UpgradeReq, stream rpc.ArduinoCore_UpgradeServer) error {
err := commands.Upgrade(stream.Context(), req,
func(p *rpc.DownloadProgress) {
stream.Send(&rpc.UpgradeResp{
Progress: p,
})
},
func(p *rpc.TaskProgress) {
stream.Send(&rpc.UpgradeResp{
TaskProgress: p,
})
},
)
if err != nil {
return err
}
return stream.Send(&rpc.UpgradeResp{})
}

// Init FIXMEDOC
func (s *ArduinoCoreServerImpl) Init(req *rpc.InitReq, stream rpc.ArduinoCore_InitServer) error {
resp, err := commands.Init(stream.Context(), req,
Expand Down Expand Up @@ -195,7 +231,7 @@ func (s *ArduinoCoreServerImpl) PlatformList(ctx context.Context, req *rpc.Platf

installed := []*rpc.Platform{}
for _, p := range platforms {
rpcPlatform := core.PlatformReleaseToRPC(p)
rpcPlatform := commands.PlatformReleaseToRPC(p)
rpcPlatform.Installed = p.Version.String()
installed = append(installed, rpcPlatform)
}
Expand Down
Loading