|
| 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 | +} |
0 commit comments