Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6a16d42

Browse files
committedJul 24, 2020
Add upgrade command to upgrade all installed cores and libs
1 parent d0a4042 commit 6a16d42

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed
 

‎cli/cli.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"github.com/arduino/arduino-cli/cli/output"
4040
"github.com/arduino/arduino-cli/cli/sketch"
4141
"github.com/arduino/arduino-cli/cli/update"
42+
"github.com/arduino/arduino-cli/cli/upgrade"
4243
"github.com/arduino/arduino-cli/cli/upload"
4344
"github.com/arduino/arduino-cli/cli/version"
4445
"github.com/arduino/arduino-cli/i18n"
@@ -90,6 +91,7 @@ func createCliCommandTree(cmd *cobra.Command) {
9091
cmd.AddCommand(outdated.NewCommand())
9192
cmd.AddCommand(sketch.NewCommand())
9293
cmd.AddCommand(update.NewCommand())
94+
cmd.AddCommand(upgrade.NewCommand())
9395
cmd.AddCommand(upload.NewCommand())
9496
cmd.AddCommand(debug.NewCommand())
9597
cmd.AddCommand(burnbootloader.NewCommand())

‎cli/upgrade/upgrade.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to license@arduino.cc.
15+
16+
package upgrade
17+
18+
import (
19+
"context"
20+
"os"
21+
22+
"github.com/arduino/arduino-cli/cli/errorcodes"
23+
"github.com/arduino/arduino-cli/cli/feedback"
24+
"github.com/arduino/arduino-cli/cli/instance"
25+
"github.com/arduino/arduino-cli/cli/output"
26+
"github.com/arduino/arduino-cli/commands/core"
27+
"github.com/arduino/arduino-cli/commands/lib"
28+
rpc "github.com/arduino/arduino-cli/rpc/commands"
29+
"github.com/sirupsen/logrus"
30+
"github.com/spf13/cobra"
31+
)
32+
33+
// NewCommand creates a new `upgrade` command
34+
func NewCommand() *cobra.Command {
35+
upgradeCommand := &cobra.Command{
36+
Use: "upgrade",
37+
Short: "Upgrades installed cores and libraries.",
38+
Long: "Upgrades installed cores and libraries to latest version.",
39+
Example: " " + os.Args[0] + " upgrade",
40+
Args: cobra.NoArgs,
41+
Run: runUpgradeCommand,
42+
}
43+
44+
return upgradeCommand
45+
}
46+
47+
func runUpgradeCommand(cmd *cobra.Command, args []string) {
48+
inst, err := instance.CreateInstance()
49+
if err != nil {
50+
feedback.Errorf("Error upgrading: %v", err)
51+
os.Exit(errorcodes.ErrGeneric)
52+
}
53+
54+
logrus.Info("Executing `arduino upgrade`")
55+
56+
err = lib.LibraryUpgradeAll(inst.Id, output.ProgressBar(), output.TaskProgress())
57+
if err != nil {
58+
feedback.Errorf("Error upgrading libraries: %v", err)
59+
os.Exit(errorcodes.ErrGeneric)
60+
}
61+
62+
targets, err := core.GetPlatforms(inst.Id, true)
63+
if err != nil {
64+
feedback.Errorf("Error retrieving core list: %v", err)
65+
os.Exit(errorcodes.ErrGeneric)
66+
}
67+
68+
for _, t := range targets {
69+
r := &rpc.PlatformUpgradeReq{
70+
Instance: inst,
71+
PlatformPackage: t.Platform.Package.Name,
72+
Architecture: t.Platform.Architecture,
73+
}
74+
_, err := core.PlatformUpgrade(context.Background(), r, output.ProgressBar(), output.TaskProgress())
75+
if err != nil {
76+
feedback.Errorf("Error during upgrade: %v", err)
77+
os.Exit(errorcodes.ErrGeneric)
78+
}
79+
}
80+
81+
logrus.Info("Done")
82+
}

‎test/test_upgrade.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This file is part of arduino-cli.
2+
#
3+
# Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
#
5+
# This software is released under the GNU General Public License version 3,
6+
# which covers the main part of arduino-cli.
7+
# The terms of this license can be found at:
8+
# https://www.gnu.org/licenses/gpl-3.0.en.html
9+
#
10+
# You can be released from the requirements of the above licenses by purchasing
11+
# a commercial license. Buying such a license is mandatory if you want to modify or
12+
# otherwise use the software for commercial activities involving the Arduino
13+
# software without disclosing the source code of your own applications. To purchase
14+
# a commercial license, send an email to license@arduino.cc.
15+
16+
17+
def test_upgrade(run_command):
18+
# Updates index for cores and libraries
19+
assert run_command("core update-index")
20+
assert run_command("lib update-index")
21+
22+
# Installs an outdated core and library
23+
assert run_command("core install arduino:avr@1.6.3")
24+
assert run_command("lib install USBHost@1.0.0")
25+
26+
# Installs latest version of a core and a library
27+
assert run_command("core install arduino:samd")
28+
assert run_command("lib install ArduinoJson")
29+
30+
assert run_command("upgrade")

0 commit comments

Comments
 (0)
Please sign in to comment.