Skip to content

Add outdate, update and upgrade commands #865

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 6 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 additions & 0 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ import (
"github.com/arduino/arduino-cli/cli/generatedocs"
"github.com/arduino/arduino-cli/cli/globals"
"github.com/arduino/arduino-cli/cli/lib"
"github.com/arduino/arduino-cli/cli/outdated"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/cli/sketch"
"github.com/arduino/arduino-cli/cli/update"
"github.com/arduino/arduino-cli/cli/upgrade"
"github.com/arduino/arduino-cli/cli/upload"
"github.com/arduino/arduino-cli/cli/version"
"github.com/arduino/arduino-cli/i18n"
Expand Down Expand Up @@ -85,7 +88,10 @@ func createCliCommandTree(cmd *cobra.Command) {
cmd.AddCommand(daemon.NewCommand())
cmd.AddCommand(generatedocs.NewCommand())
cmd.AddCommand(lib.NewCommand())
cmd.AddCommand(outdated.NewCommand())
cmd.AddCommand(sketch.NewCommand())
cmd.AddCommand(update.NewCommand())
cmd.AddCommand(upgrade.NewCommand())
cmd.AddCommand(upload.NewCommand())
cmd.AddCommand(debug.NewCommand())
cmd.AddCommand(burnbootloader.NewCommand())
Expand Down
98 changes: 98 additions & 0 deletions cli/outdated/outdated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// 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 [email protected].

package outdated

import (
"context"
"os"

"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"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/arduino/arduino-cli/table"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

// NewCommand creates a new `outdated` command
func NewCommand() *cobra.Command {
outdatedCommand := &cobra.Command{
Use: "outdated",
Short: "Lists cores and libraries that can be upgraded\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Short: "Lists cores and libraries that can be upgraded\n",
Short: "Lists cores and libraries that can be upgraded",

This created an empty row in the autocompletion like:

╰─$ ./arduino-cli
board            -- Arduino board commands.
burn-bootloader  -- Upload the bootloader.
cache            -- Arduino cache commands.
compile          -- Compiles Arduino sketches.
completion       -- Generates completion scripts
config           -- Arduino configuration commands.
core             -- Arduino core operations.
daemon           -- Run as a daemon on port 50051
debug            -- Debug Arduino sketches.
help             -- Help about any command
lib              -- Arduino commands about libraries.
outdated         -- Lists cores and libraries that can be upgraded
 
sketch           -- Arduino CLI sketch commands.
update           -- Updates the index of cores and libraries
upgrade          -- Upgrades installed cores and libraries.
upload           -- Upload Arduino sketches.
version          -- Shows version number of Arduino CLI.

Long: "This commands shows a list of installed cores and/or libraries\n" +
"that can be upgraded. If nothing needs to be updated the output is empty.",
Example: " " + os.Args[0] + " outdated\n",
Args: cobra.NoArgs,
Run: runOutdatedCommand,
}

return outdatedCommand
}

func runOutdatedCommand(cmd *cobra.Command, args []string) {
inst, err := instance.CreateInstance()
if err != nil {
feedback.Errorf("Error upgrading: %v", err)
os.Exit(errorcodes.ErrGeneric)
}

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To really see all the outdated cores and libraries, should we launch a commands.UpdateIndex() and a UpdateLibrariesIndex() before checking through the local libs and cores? (this is also a functional question for @ubidefeo 🙂 )

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in Homebrew style this command only returns something after an update, bit I like the idea that it implicitly runs arduino-cli update before running

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change that. 👍

// 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: true,
Updatable: true,
})
if err != nil {
feedback.Errorf("Error retrieving library list: %v", err)
os.Exit(errorcodes.ErrGeneric)
}

tab := table.New()
tab.SetHeader("Name", "Installed version", "New version")

// Prints outdated cores
if len(targets) > 0 {
for _, t := range targets {
plat := t.Platform
tab.AddRow(plat.Name, t.Version, plat.GetLatestRelease().Version)
}
}

// Prints outdated libraries
libs := res.GetInstalledLibrary()
if len(libs) > 0 {
for _, l := range libs {
tab.AddRow(l.Library.Name, l.Library.Version, l.Release.Version)
}
}
if len(targets) > 0 || len(libs) > 0 {
feedback.Print(tab.Render())
}

logrus.Info("Done")
}
68 changes: 68 additions & 0 deletions cli/update/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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 [email protected].

package update

import (
"context"
"os"

"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/cli/output"
"github.com/arduino/arduino-cli/commands"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

// NewCommand creates a new `update` command
func NewCommand() *cobra.Command {
updateCommand := &cobra.Command{
Use: "update",
Short: "Updates the index of cores and libraries",
Long: "Updates the index of cores and libraries to the latest versions.",
Example: " " + os.Args[0] + " update",
Args: cobra.NoArgs,
Run: runUpdateCommand,
}

return updateCommand
}

func runUpdateCommand(cmd *cobra.Command, args []string) {
instance := instance.CreateInstanceIgnorePlatformIndexErrors()

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

_, err := commands.UpdateIndex(context.Background(), &rpc.UpdateIndexReq{
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)
os.Exit(errorcodes.ErrGeneric)
}

logrus.Info("Done")
}
82 changes: 82 additions & 0 deletions cli/upgrade/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// 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 [email protected].

package upgrade

import (
"context"
"os"

"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/cli/output"
"github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/commands/lib"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

// NewCommand creates a new `upgrade` command
func NewCommand() *cobra.Command {
upgradeCommand := &cobra.Command{
Use: "upgrade",
Short: "Upgrades installed cores and libraries.",
Long: "Upgrades installed cores and libraries to latest version.",
Example: " " + os.Args[0] + " upgrade",
Args: cobra.NoArgs,
Run: runUpgradeCommand,
}

return upgradeCommand
}

func runUpgradeCommand(cmd *cobra.Command, args []string) {
inst, err := instance.CreateInstance()
if err != nil {
feedback.Errorf("Error upgrading: %v", err)
os.Exit(errorcodes.ErrGeneric)
}

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

err = lib.LibraryUpgradeAll(inst.Id, output.ProgressBar(), output.TaskProgress())
if err != nil {
feedback.Errorf("Error upgrading libraries: %v", err)
os.Exit(errorcodes.ErrGeneric)
}

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)
}
}

logrus.Info("Done")
}
3 changes: 3 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ nav:
- lib uninstall: commands/arduino-cli_lib_uninstall.md
- lib update-index: commands/arduino-cli_lib_update-index.md
- lib upgrade: commands/arduino-cli_lib_upgrade.md
- outdated: commands/arduino-cli_outdated.md
- sketch: commands/arduino-cli_sketch.md
- sketch new: commands/arduino-cli_sketch_new.md
- update: commands/arduino-cli_update.md
- upgrade: commands/arduino-cli_upgrade.md
- upload: commands/arduino-cli_upload.md
- version: commands/arduino-cli_version.md
- gRPC reference:
Expand Down
35 changes: 35 additions & 0 deletions test/test_outdated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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 [email protected].


def test_outdated(run_command):
# Updates index for cores and libraries
assert run_command("core update-index")
assert run_command("lib update-index")

# Installs an outdated core and library
assert run_command("core install arduino:[email protected]")
assert run_command("lib install [email protected]")

# Installs latest version of a core and a library
assert run_command("core install arduino:samd")
assert run_command("lib install ArduinoJson")

# Verifies only outdate core and library are returned
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Verifies only outdate core and library are returned
# Verifies only outdated cores and libraries are returned

result = run_command("outdated")
assert result.ok
lines = result.stdout.splitlines()
assert lines[1].startswith("Arduino AVR Boards")
assert lines[2].startswith("USBHost")
24 changes: 24 additions & 0 deletions test/test_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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 [email protected].


def test_update(run_command):
res = run_command("update")
assert res.ok
lines = [l.strip() for l in res.stdout.splitlines()]

assert "Updating index: package_index.json downloaded" in lines
assert "Updating index: package_index.json.sig downloaded" in lines
assert "Updating index: library_index.json downloaded" in lines
30 changes: 30 additions & 0 deletions test/test_upgrade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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 [email protected].


def test_upgrade(run_command):
# Updates index for cores and libraries
assert run_command("core update-index")
assert run_command("lib update-index")

# Installs an outdated core and library
assert run_command("core install arduino:[email protected]")
assert run_command("lib install [email protected]")

# Installs latest version of a core and a library
assert run_command("core install arduino:samd")
assert run_command("lib install ArduinoJson")

assert run_command("upgrade")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be reasonable to add a double check here like you did in the outdated test, checking if no more stuff to upgrade is present after an upgrade WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kinda problematic for upgrade since basically all the strings contain the latest versions of libraries and cores being upgraded, can't really hardcode it.

I can check oudated commands output though.