Skip to content

Commit d0a4042

Browse files
committed
Add update command to update the index of cores and libs
1 parent 1d3db71 commit d0a4042

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

cli/cli.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/arduino/arduino-cli/cli/outdated"
3939
"github.com/arduino/arduino-cli/cli/output"
4040
"github.com/arduino/arduino-cli/cli/sketch"
41+
"github.com/arduino/arduino-cli/cli/update"
4142
"github.com/arduino/arduino-cli/cli/upload"
4243
"github.com/arduino/arduino-cli/cli/version"
4344
"github.com/arduino/arduino-cli/i18n"
@@ -88,6 +89,7 @@ func createCliCommandTree(cmd *cobra.Command) {
8889
cmd.AddCommand(lib.NewCommand())
8990
cmd.AddCommand(outdated.NewCommand())
9091
cmd.AddCommand(sketch.NewCommand())
92+
cmd.AddCommand(update.NewCommand())
9193
cmd.AddCommand(upload.NewCommand())
9294
cmd.AddCommand(debug.NewCommand())
9395
cmd.AddCommand(burnbootloader.NewCommand())

cli/update/update.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
rpc "github.com/arduino/arduino-cli/rpc/commands"
28+
"github.com/sirupsen/logrus"
29+
"github.com/spf13/cobra"
30+
)
31+
32+
// NewCommand creates a new `update` command
33+
func NewCommand() *cobra.Command {
34+
updateCommand := &cobra.Command{
35+
Use: "update",
36+
Short: "Updates the index of cores and libraries",
37+
Long: "Updates the index of cores and libraries to the latest versions.",
38+
Example: " " + os.Args[0] + " update",
39+
Args: cobra.NoArgs,
40+
Run: runUpdateCommand,
41+
}
42+
43+
return updateCommand
44+
}
45+
46+
func runUpdateCommand(cmd *cobra.Command, args []string) {
47+
instance := instance.CreateInstanceIgnorePlatformIndexErrors()
48+
49+
logrus.Info("Executing `arduino update`")
50+
51+
_, err := commands.UpdateIndex(context.Background(), &rpc.UpdateIndexReq{
52+
Instance: instance,
53+
}, output.ProgressBar())
54+
if err != nil {
55+
feedback.Errorf("Error updating core index: %v", err)
56+
os.Exit(errorcodes.ErrGeneric)
57+
}
58+
59+
err = commands.UpdateLibrariesIndex(context.Background(), &rpc.UpdateLibrariesIndexReq{
60+
Instance: instance,
61+
}, output.ProgressBar())
62+
if err != nil {
63+
feedback.Errorf("Error updating library index: %v", err)
64+
os.Exit(errorcodes.ErrGeneric)
65+
}
66+
67+
logrus.Info("Done")
68+
}

test/test_update.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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_update(run_command):
18+
res = run_command("update")
19+
assert res.ok
20+
lines = [l.strip() for l in res.stdout.splitlines()]
21+
22+
assert "Updating index: package_index.json downloaded" in lines
23+
assert "Updating index: package_index.json.sig downloaded" in lines
24+
assert "Updating index: library_index.json downloaded" in lines

0 commit comments

Comments
 (0)