Skip to content

Commit b8475a0

Browse files
authored
Add outdated, update and upgrade commands (#865)
* Add outdated command to list cores and libs that needs upgrade * Add update command to update the index of cores and libs * Add upgrade command to upgrade all installed cores and libs * [skip changelog] Update docs with new commands * [skip changelog] Fix outdated and upgrade command * [skip changelog] Changed update and outdated commands behaviour
1 parent abb7279 commit b8475a0

File tree

8 files changed

+451
-0
lines changed

8 files changed

+451
-0
lines changed

Diff for: cli/cli.go

+6
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ import (
3535
"github.com/arduino/arduino-cli/cli/generatedocs"
3636
"github.com/arduino/arduino-cli/cli/globals"
3737
"github.com/arduino/arduino-cli/cli/lib"
38+
"github.com/arduino/arduino-cli/cli/outdated"
3839
"github.com/arduino/arduino-cli/cli/output"
3940
"github.com/arduino/arduino-cli/cli/sketch"
41+
"github.com/arduino/arduino-cli/cli/update"
42+
"github.com/arduino/arduino-cli/cli/upgrade"
4043
"github.com/arduino/arduino-cli/cli/upload"
4144
"github.com/arduino/arduino-cli/cli/version"
4245
"github.com/arduino/arduino-cli/i18n"
@@ -85,7 +88,10 @@ func createCliCommandTree(cmd *cobra.Command) {
8588
cmd.AddCommand(daemon.NewCommand())
8689
cmd.AddCommand(generatedocs.NewCommand())
8790
cmd.AddCommand(lib.NewCommand())
91+
cmd.AddCommand(outdated.NewCommand())
8892
cmd.AddCommand(sketch.NewCommand())
93+
cmd.AddCommand(update.NewCommand())
94+
cmd.AddCommand(upgrade.NewCommand())
8995
cmd.AddCommand(upload.NewCommand())
9096
cmd.AddCommand(debug.NewCommand())
9197
cmd.AddCommand(burnbootloader.NewCommand())

Diff for: cli/outdated/outdated.go

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 [email protected].
15+
16+
package outdated
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/commands/core"
26+
"github.com/arduino/arduino-cli/commands/lib"
27+
rpc "github.com/arduino/arduino-cli/rpc/commands"
28+
"github.com/arduino/arduino-cli/table"
29+
"github.com/sirupsen/logrus"
30+
"github.com/spf13/cobra"
31+
)
32+
33+
// NewCommand creates a new `outdated` command
34+
func NewCommand() *cobra.Command {
35+
outdatedCommand := &cobra.Command{
36+
Use: "outdated",
37+
Short: "Lists cores and libraries that can be upgraded",
38+
Long: "This commands shows a list of installed cores and/or libraries\n" +
39+
"that can be upgraded. If nothing needs to be updated the output is empty.",
40+
Example: " " + os.Args[0] + " outdated\n",
41+
Args: cobra.NoArgs,
42+
Run: runOutdatedCommand,
43+
}
44+
45+
return outdatedCommand
46+
}
47+
48+
func runOutdatedCommand(cmd *cobra.Command, args []string) {
49+
inst, err := instance.CreateInstance()
50+
if err != nil {
51+
feedback.Errorf("Error upgrading: %v", err)
52+
os.Exit(errorcodes.ErrGeneric)
53+
}
54+
55+
logrus.Info("Executing `arduino outdated`")
56+
57+
// Gets outdated cores
58+
targets, err := core.GetPlatforms(inst.Id, true)
59+
if err != nil {
60+
feedback.Errorf("Error retrieving core list: %v", err)
61+
os.Exit(errorcodes.ErrGeneric)
62+
}
63+
64+
// Gets outdated libraries
65+
res, err := lib.LibraryList(context.Background(), &rpc.LibraryListReq{
66+
Instance: inst,
67+
All: false,
68+
Updatable: true,
69+
})
70+
if err != nil {
71+
feedback.Errorf("Error retrieving library list: %v", err)
72+
os.Exit(errorcodes.ErrGeneric)
73+
}
74+
75+
// Prints outdated cores
76+
tab := table.New()
77+
tab.SetHeader("Core name", "Installed version", "New version")
78+
if len(targets) > 0 {
79+
for _, t := range targets {
80+
plat := t.Platform
81+
tab.AddRow(plat.Name, t.Version, plat.GetLatestRelease().Version)
82+
}
83+
feedback.Print(tab.Render())
84+
}
85+
86+
// Prints outdated libraries
87+
tab = table.New()
88+
tab.SetHeader("Library name", "Installed version", "New version")
89+
libs := res.GetInstalledLibrary()
90+
if len(libs) > 0 {
91+
for _, l := range libs {
92+
tab.AddRow(l.Library.Name, l.Library.Version, l.Release.Version)
93+
}
94+
feedback.Print(tab.Render())
95+
}
96+
97+
logrus.Info("Done")
98+
}

Diff for: cli/update/update.go

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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 [email protected].
15+
16+
package update
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"
27+
"github.com/arduino/arduino-cli/commands/core"
28+
"github.com/arduino/arduino-cli/commands/lib"
29+
rpc "github.com/arduino/arduino-cli/rpc/commands"
30+
"github.com/arduino/arduino-cli/table"
31+
"github.com/sirupsen/logrus"
32+
"github.com/spf13/cobra"
33+
)
34+
35+
// NewCommand creates a new `update` command
36+
func NewCommand() *cobra.Command {
37+
updateCommand := &cobra.Command{
38+
Use: "update",
39+
Short: "Updates the index of cores and libraries",
40+
Long: "Updates the index of cores and libraries to the latest versions.",
41+
Example: " " + os.Args[0] + " update",
42+
Args: cobra.NoArgs,
43+
Run: runUpdateCommand,
44+
}
45+
updateCommand.Flags().BoolVar(&updateFlags.showOutdated, "outdated", false, "Show outdated cores and libraries after index update")
46+
return updateCommand
47+
}
48+
49+
var updateFlags struct {
50+
showOutdated bool
51+
}
52+
53+
func runUpdateCommand(cmd *cobra.Command, args []string) {
54+
instance := instance.CreateInstanceIgnorePlatformIndexErrors()
55+
56+
logrus.Info("Executing `arduino update`")
57+
58+
_, err := commands.UpdateIndex(context.Background(), &rpc.UpdateIndexReq{
59+
Instance: instance,
60+
}, output.ProgressBar())
61+
if err != nil {
62+
feedback.Errorf("Error updating core index: %v", err)
63+
os.Exit(errorcodes.ErrGeneric)
64+
}
65+
66+
err = commands.UpdateLibrariesIndex(context.Background(), &rpc.UpdateLibrariesIndexReq{
67+
Instance: instance,
68+
}, output.ProgressBar())
69+
if err != nil {
70+
feedback.Errorf("Error updating library index: %v", err)
71+
os.Exit(errorcodes.ErrGeneric)
72+
}
73+
74+
if updateFlags.showOutdated {
75+
// Gets outdated cores
76+
targets, err := core.GetPlatforms(instance.Id, true)
77+
if err != nil {
78+
feedback.Errorf("Error retrieving core list: %v", err)
79+
os.Exit(errorcodes.ErrGeneric)
80+
}
81+
82+
// Gets outdated libraries
83+
res, err := lib.LibraryList(context.Background(), &rpc.LibraryListReq{
84+
Instance: instance,
85+
All: false,
86+
Updatable: true,
87+
})
88+
if err != nil {
89+
feedback.Errorf("Error retrieving library list: %v", err)
90+
os.Exit(errorcodes.ErrGeneric)
91+
}
92+
93+
// Prints outdated cores
94+
tab := table.New()
95+
tab.SetHeader("Core name", "Installed version", "New version")
96+
if len(targets) > 0 {
97+
for _, t := range targets {
98+
plat := t.Platform
99+
tab.AddRow(plat.Name, t.Version, plat.GetLatestRelease().Version)
100+
}
101+
feedback.Print(tab.Render())
102+
}
103+
104+
// Prints outdated libraries
105+
tab = table.New()
106+
tab.SetHeader("Library name", "Installed version", "New version")
107+
libs := res.GetInstalledLibrary()
108+
if len(libs) > 0 {
109+
for _, l := range libs {
110+
tab.AddRow(l.Library.Name, l.Library.Version, l.Release.Version)
111+
}
112+
feedback.Print(tab.Render())
113+
}
114+
115+
}
116+
117+
logrus.Info("Done")
118+
}

Diff for: cli/upgrade/upgrade.go

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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 [email protected].
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+
// Gets list of libraries to upgrade, cores' libraries are ignored since they're upgraded
57+
// when the core is
58+
res, err := lib.LibraryList(context.Background(), &rpc.LibraryListReq{
59+
Instance: inst,
60+
All: false,
61+
Updatable: true,
62+
})
63+
if err != nil {
64+
feedback.Errorf("Error retrieving library list: %v", err)
65+
os.Exit(errorcodes.ErrGeneric)
66+
}
67+
libraries := []string{}
68+
for _, l := range res.InstalledLibrary {
69+
libraries = append(libraries, l.Library.Name)
70+
}
71+
72+
// Upgrades libraries
73+
err = lib.LibraryUpgrade(inst.Id, libraries, output.ProgressBar(), output.TaskProgress())
74+
if err != nil {
75+
feedback.Errorf("Error upgrading libraries: %v", err)
76+
os.Exit(errorcodes.ErrGeneric)
77+
}
78+
79+
targets, err := core.GetPlatforms(inst.Id, true)
80+
if err != nil {
81+
feedback.Errorf("Error retrieving core list: %v", err)
82+
os.Exit(errorcodes.ErrGeneric)
83+
}
84+
85+
for _, t := range targets {
86+
r := &rpc.PlatformUpgradeReq{
87+
Instance: inst,
88+
PlatformPackage: t.Platform.Package.Name,
89+
Architecture: t.Platform.Architecture,
90+
}
91+
_, err := core.PlatformUpgrade(context.Background(), r, output.ProgressBar(), output.TaskProgress())
92+
if err != nil {
93+
feedback.Errorf("Error during upgrade: %v", err)
94+
os.Exit(errorcodes.ErrGeneric)
95+
}
96+
}
97+
98+
logrus.Info("Done")
99+
}

Diff for: mkdocs.yml

+3
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,11 @@ nav:
9696
- lib uninstall: commands/arduino-cli_lib_uninstall.md
9797
- lib update-index: commands/arduino-cli_lib_update-index.md
9898
- lib upgrade: commands/arduino-cli_lib_upgrade.md
99+
- outdated: commands/arduino-cli_outdated.md
99100
- sketch: commands/arduino-cli_sketch.md
100101
- sketch new: commands/arduino-cli_sketch_new.md
102+
- update: commands/arduino-cli_update.md
103+
- upgrade: commands/arduino-cli_upgrade.md
101104
- upload: commands/arduino-cli_upload.md
102105
- version: commands/arduino-cli_version.md
103106
- gRPC reference:

Diff for: test/test_outdated.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 [email protected].
15+
16+
17+
def test_outdated(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:[email protected]")
24+
assert run_command("lib install [email protected]")
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+
# Verifies only outdated cores and libraries are returned
31+
result = run_command("outdated")
32+
assert result.ok
33+
lines = [l.strip() for l in result.stdout.splitlines()]
34+
assert lines[1].startswith("Arduino AVR Boards")
35+
assert lines[4].startswith("USBHost")

0 commit comments

Comments
 (0)