From 1d3db71a1a4f471d627de6e8743489260c2d55c0 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Fri, 24 Jul 2020 12:32:42 +0200 Subject: [PATCH 1/6] Add outdated command to list cores and libs that needs upgrade --- cli/cli.go | 2 + cli/outdated/outdated.go | 98 ++++++++++++++++++++++++++++++++++++++++ test/test_outdated.py | 35 ++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 cli/outdated/outdated.go create mode 100644 test/test_outdated.py diff --git a/cli/cli.go b/cli/cli.go index a29faa25a08..b0f55a1d7d9 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -35,6 +35,7 @@ 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/upload" @@ -85,6 +86,7 @@ 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(upload.NewCommand()) cmd.AddCommand(debug.NewCommand()) diff --git a/cli/outdated/outdated.go b/cli/outdated/outdated.go new file mode 100644 index 00000000000..93a6ec69ec1 --- /dev/null +++ b/cli/outdated/outdated.go @@ -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 license@arduino.cc. + +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", + 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`") + + // 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") +} diff --git a/test/test_outdated.py b/test/test_outdated.py new file mode 100644 index 00000000000..735994bc8c6 --- /dev/null +++ b/test/test_outdated.py @@ -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 license@arduino.cc. + + +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:avr@1.6.3") + assert run_command("lib install USBHost@1.0.0") + + # 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 + result = run_command("outdated") + assert result.ok + lines = result.stdout.splitlines() + assert lines[1].startswith("Arduino AVR Boards") + assert lines[2].startswith("USBHost") From d0a4042b27d9463851a4c27a6e3d08ca36b2cf22 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Fri, 24 Jul 2020 12:40:15 +0200 Subject: [PATCH 2/6] Add update command to update the index of cores and libs --- cli/cli.go | 2 ++ cli/update/update.go | 68 ++++++++++++++++++++++++++++++++++++++++++++ test/test_update.py | 24 ++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 cli/update/update.go create mode 100644 test/test_update.py diff --git a/cli/cli.go b/cli/cli.go index b0f55a1d7d9..71ed457119b 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -38,6 +38,7 @@ import ( "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/upload" "github.com/arduino/arduino-cli/cli/version" "github.com/arduino/arduino-cli/i18n" @@ -88,6 +89,7 @@ func createCliCommandTree(cmd *cobra.Command) { cmd.AddCommand(lib.NewCommand()) cmd.AddCommand(outdated.NewCommand()) cmd.AddCommand(sketch.NewCommand()) + cmd.AddCommand(update.NewCommand()) cmd.AddCommand(upload.NewCommand()) cmd.AddCommand(debug.NewCommand()) cmd.AddCommand(burnbootloader.NewCommand()) diff --git a/cli/update/update.go b/cli/update/update.go new file mode 100644 index 00000000000..097c0be5c49 --- /dev/null +++ b/cli/update/update.go @@ -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 license@arduino.cc. + +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") +} diff --git a/test/test_update.py b/test/test_update.py new file mode 100644 index 00000000000..1209aa7a218 --- /dev/null +++ b/test/test_update.py @@ -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 license@arduino.cc. + + +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 From 6a16d4282125a0ebbc18f925d76fe547ca6ad704 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Fri, 24 Jul 2020 14:24:14 +0200 Subject: [PATCH 3/6] Add upgrade command to upgrade all installed cores and libs --- cli/cli.go | 2 ++ cli/upgrade/upgrade.go | 82 ++++++++++++++++++++++++++++++++++++++++++ test/test_upgrade.py | 30 ++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 cli/upgrade/upgrade.go create mode 100644 test/test_upgrade.py diff --git a/cli/cli.go b/cli/cli.go index 71ed457119b..c69f9398cd5 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -39,6 +39,7 @@ import ( "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" @@ -90,6 +91,7 @@ func createCliCommandTree(cmd *cobra.Command) { 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()) diff --git a/cli/upgrade/upgrade.go b/cli/upgrade/upgrade.go new file mode 100644 index 00000000000..4be00d52b59 --- /dev/null +++ b/cli/upgrade/upgrade.go @@ -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 license@arduino.cc. + +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") +} diff --git a/test/test_upgrade.py b/test/test_upgrade.py new file mode 100644 index 00000000000..5f7446d27e0 --- /dev/null +++ b/test/test_upgrade.py @@ -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 license@arduino.cc. + + +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:avr@1.6.3") + assert run_command("lib install USBHost@1.0.0") + + # 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") From 92e85b668fa66cb0bae78eaf7e72d830b5cfc586 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Fri, 24 Jul 2020 16:24:27 +0200 Subject: [PATCH 4/6] [skip changelog] Update docs with new commands --- mkdocs.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mkdocs.yml b/mkdocs.yml index 92113595dac..c5434f69349 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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: From b9b430b40f5bb37989fe00fa39b5a9759380088a Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Mon, 27 Jul 2020 12:36:19 +0200 Subject: [PATCH 5/6] [skip changelog] Fix outdated and upgrade command --- cli/outdated/outdated.go | 23 +++++++++++++++++++++-- cli/upgrade/upgrade.go | 19 ++++++++++++++++++- test/test_outdated.py | 8 ++++---- test/test_upgrade.py | 18 +++++++++++++++++- 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/cli/outdated/outdated.go b/cli/outdated/outdated.go index 93a6ec69ec1..0a2fac2a949 100644 --- a/cli/outdated/outdated.go +++ b/cli/outdated/outdated.go @@ -22,6 +22,8 @@ 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/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" @@ -34,7 +36,7 @@ import ( func NewCommand() *cobra.Command { outdatedCommand := &cobra.Command{ Use: "outdated", - Short: "Lists cores and libraries that can be upgraded\n", + Short: "Lists cores and libraries that can be upgraded", 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", @@ -54,6 +56,23 @@ func runOutdatedCommand(cmd *cobra.Command, args []string) { logrus.Info("Executing `arduino outdated`") + // Updates indexes before getting list of outdated cores and libraries + _, err = commands.UpdateIndex(context.Background(), &rpc.UpdateIndexReq{ + Instance: inst, + }, 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: inst, + }, output.ProgressBar()) + if err != nil { + feedback.Errorf("Error updating library index: %v", err) + os.Exit(errorcodes.ErrGeneric) + } + // Gets outdated cores targets, err := core.GetPlatforms(inst.Id, true) if err != nil { @@ -64,7 +83,7 @@ func runOutdatedCommand(cmd *cobra.Command, args []string) { // Gets outdated libraries res, err := lib.LibraryList(context.Background(), &rpc.LibraryListReq{ Instance: inst, - All: true, + All: false, Updatable: true, }) if err != nil { diff --git a/cli/upgrade/upgrade.go b/cli/upgrade/upgrade.go index 4be00d52b59..2a191326131 100644 --- a/cli/upgrade/upgrade.go +++ b/cli/upgrade/upgrade.go @@ -53,7 +53,24 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) { logrus.Info("Executing `arduino upgrade`") - err = lib.LibraryUpgradeAll(inst.Id, output.ProgressBar(), output.TaskProgress()) + // 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) diff --git a/test/test_outdated.py b/test/test_outdated.py index 735994bc8c6..64d74c284ec 100644 --- a/test/test_outdated.py +++ b/test/test_outdated.py @@ -27,9 +27,9 @@ def test_outdated(run_command): assert run_command("core install arduino:samd") assert run_command("lib install ArduinoJson") - # 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") + lines = [l.strip() for l in result.stdout.splitlines()] + assert lines[-3].startswith("Arduino AVR Boards") + assert lines[-2].startswith("USBHost") diff --git a/test/test_upgrade.py b/test/test_upgrade.py index 5f7446d27e0..bf825283a17 100644 --- a/test/test_upgrade.py +++ b/test/test_upgrade.py @@ -27,4 +27,20 @@ def test_upgrade(run_command): assert run_command("core install arduino:samd") assert run_command("lib install ArduinoJson") - assert run_command("upgrade") + # Verifies outdated core and libraries are shown + result = run_command("outdated") + assert result.ok + lines = result.stdout.splitlines() + assert lines[-3].startswith("Arduino AVR Boards") + assert lines[-2].startswith("USBHost") + + result = run_command("upgrade") + assert result.ok + + # Verifies cores and libraries have been updated + result = run_command("outdated") + assert result.ok + lines = result.stdout.splitlines() + for l in lines: + assert "Arduino AVR Boards" not in l + assert "USBHost" not in l From 4b0152f644002c6b281ec252652b509157b7e5c4 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Mon, 27 Jul 2020 14:50:01 +0200 Subject: [PATCH 6/6] [skip changelog] Changed update and outdated commands behaviour --- cli/outdated/outdated.go | 29 ++++------------------ cli/update/update.go | 52 +++++++++++++++++++++++++++++++++++++++- test/test_outdated.py | 4 ++-- test/test_update.py | 25 +++++++++++++++++++ test/test_upgrade.py | 9 +++---- 5 files changed, 86 insertions(+), 33 deletions(-) diff --git a/cli/outdated/outdated.go b/cli/outdated/outdated.go index 0a2fac2a949..dc8b68a2ec7 100644 --- a/cli/outdated/outdated.go +++ b/cli/outdated/outdated.go @@ -22,8 +22,6 @@ 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/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" @@ -56,23 +54,6 @@ func runOutdatedCommand(cmd *cobra.Command, args []string) { logrus.Info("Executing `arduino outdated`") - // Updates indexes before getting list of outdated cores and libraries - _, err = commands.UpdateIndex(context.Background(), &rpc.UpdateIndexReq{ - Instance: inst, - }, 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: inst, - }, output.ProgressBar()) - if err != nil { - feedback.Errorf("Error updating library index: %v", err) - os.Exit(errorcodes.ErrGeneric) - } - // Gets outdated cores targets, err := core.GetPlatforms(inst.Id, true) if err != nil { @@ -91,25 +72,25 @@ func runOutdatedCommand(cmd *cobra.Command, args []string) { os.Exit(errorcodes.ErrGeneric) } - tab := table.New() - tab.SetHeader("Name", "Installed version", "New version") - // 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) } + 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 { tab.AddRow(l.Library.Name, l.Library.Version, l.Release.Version) } - } - if len(targets) > 0 || len(libs) > 0 { feedback.Print(tab.Render()) } diff --git a/cli/update/update.go b/cli/update/update.go index 097c0be5c49..42b6280ba93 100644 --- a/cli/update/update.go +++ b/cli/update/update.go @@ -24,7 +24,10 @@ 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" "github.com/spf13/cobra" ) @@ -39,10 +42,14 @@ func NewCommand() *cobra.Command { Args: cobra.NoArgs, Run: runUpdateCommand, } - + updateCommand.Flags().BoolVar(&updateFlags.showOutdated, "outdated", false, "Show outdated cores and libraries after index update") return updateCommand } +var updateFlags struct { + showOutdated bool +} + func runUpdateCommand(cmd *cobra.Command, args []string) { instance := instance.CreateInstanceIgnorePlatformIndexErrors() @@ -64,5 +71,48 @@ func runUpdateCommand(cmd *cobra.Command, args []string) { 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, + }) + if err != nil { + feedback.Errorf("Error retrieving library list: %v", err) + os.Exit(errorcodes.ErrGeneric) + } + + // 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) + } + 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 { + tab.AddRow(l.Library.Name, l.Library.Version, l.Release.Version) + } + feedback.Print(tab.Render()) + } + + } + logrus.Info("Done") } diff --git a/test/test_outdated.py b/test/test_outdated.py index 64d74c284ec..99b83ee9271 100644 --- a/test/test_outdated.py +++ b/test/test_outdated.py @@ -31,5 +31,5 @@ def test_outdated(run_command): result = run_command("outdated") assert result.ok lines = [l.strip() for l in result.stdout.splitlines()] - assert lines[-3].startswith("Arduino AVR Boards") - assert lines[-2].startswith("USBHost") + assert lines[1].startswith("Arduino AVR Boards") + assert lines[4].startswith("USBHost") diff --git a/test/test_update.py b/test/test_update.py index 1209aa7a218..84b547e3784 100644 --- a/test/test_update.py +++ b/test/test_update.py @@ -22,3 +22,28 @@ def test_update(run_command): 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 + + +def test_update_showing_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:avr@1.6.3") + assert run_command("lib install USBHost@1.0.0") + + # Installs latest version of a core and a library + assert run_command("core install arduino:samd") + assert run_command("lib install ArduinoJson") + + # Verifies outdated cores and libraries are printed after updating indexes + result = run_command("update --outdated") + assert result.ok + lines = [l.strip() for l in result.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 + assert lines[-5].startswith("Arduino AVR Boards") + assert lines[-2].startswith("USBHost") diff --git a/test/test_upgrade.py b/test/test_upgrade.py index bf825283a17..f90a5356520 100644 --- a/test/test_upgrade.py +++ b/test/test_upgrade.py @@ -31,8 +31,8 @@ def test_upgrade(run_command): result = run_command("outdated") assert result.ok lines = result.stdout.splitlines() - assert lines[-3].startswith("Arduino AVR Boards") - assert lines[-2].startswith("USBHost") + assert lines[1].startswith("Arduino AVR Boards") + assert lines[4].startswith("USBHost") result = run_command("upgrade") assert result.ok @@ -40,7 +40,4 @@ def test_upgrade(run_command): # Verifies cores and libraries have been updated result = run_command("outdated") assert result.ok - lines = result.stdout.splitlines() - for l in lines: - assert "Arduino AVR Boards" not in l - assert "USBHost" not in l + assert result.stdout == ""