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