Skip to content

Commit ccba1a0

Browse files
committed
update everything when no args are passed
1 parent 81fa396 commit ccba1a0

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

Diff for: cli/core/upgrade.go

+29-7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package core
1919

2020
import (
2121
"context"
22+
"fmt"
2223
"os"
2324

2425
"github.com/arduino/arduino-cli/cli/errorcodes"
@@ -51,21 +52,42 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
5152
instance := instance.CreateInstance()
5253
logrus.Info("Executing `arduino core upgrade`")
5354

55+
// if no platform was passed, upgrade allthethings
56+
if len(args) == 0 {
57+
targets, err := core.GetPlatforms(instance.Id, true)
58+
if err != nil {
59+
formatter.PrintError(err, "Error retrieving core list")
60+
os.Exit(errorcodes.ErrGeneric)
61+
}
62+
63+
if len(targets) == 0 {
64+
formatter.PrintResult("All the cores are already at the latest version")
65+
return
66+
}
67+
68+
for _, t := range targets {
69+
args = append(args, t.Platform.String())
70+
}
71+
}
72+
73+
// proceed upgrading, if anything is upgradable
5474
platformsRefs := parsePlatformReferenceArgs(args)
5575
for i, platformRef := range platformsRefs {
5676
if platformRef.Version != "" {
5777
formatter.PrintErrorMessage(("Invalid item " + args[i]))
58-
os.Exit(errorcodes.ErrBadArgument)
78+
continue
5979
}
60-
}
61-
for _, platformRef := range platformsRefs {
62-
_, err := core.PlatformUpgrade(context.Background(), &rpc.PlatformUpgradeReq{
80+
81+
r := &rpc.PlatformUpgradeReq{
6382
Instance: instance,
6483
PlatformPackage: platformRef.Package,
6584
Architecture: platformRef.Architecture,
66-
}, output.ProgressBar(), output.TaskProgress(),
67-
globals.HTTPClientHeader)
68-
if err != nil {
85+
}
86+
87+
_, err := core.PlatformUpgrade(context.Background(), r, output.ProgressBar(), output.TaskProgress(), globals.HTTPClientHeader)
88+
if err == core.ErrAlreadyLatest {
89+
formatter.PrintResult(fmt.Sprintf("Platform %s is already at the latest version", platformRef))
90+
} else if err != nil {
6991
formatter.PrintError(err, "Error during upgrade")
7092
os.Exit(errorcodes.ErrGeneric)
7193
}

0 commit comments

Comments
 (0)