@@ -19,6 +19,7 @@ package core
19
19
20
20
import (
21
21
"context"
22
+ "fmt"
22
23
"os"
23
24
24
25
"github.com/arduino/arduino-cli/cli/errorcodes"
@@ -51,21 +52,42 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
51
52
instance := instance .CreateInstance ()
52
53
logrus .Info ("Executing `arduino core upgrade`" )
53
54
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
54
74
platformsRefs := parsePlatformReferenceArgs (args )
55
75
for i , platformRef := range platformsRefs {
56
76
if platformRef .Version != "" {
57
77
formatter .PrintErrorMessage (("Invalid item " + args [i ]))
58
- os . Exit ( errorcodes . ErrBadArgument )
78
+ continue
59
79
}
60
- }
61
- for _ , platformRef := range platformsRefs {
62
- _ , err := core .PlatformUpgrade (context .Background (), & rpc.PlatformUpgradeReq {
80
+
81
+ r := & rpc.PlatformUpgradeReq {
63
82
Instance : instance ,
64
83
PlatformPackage : platformRef .Package ,
65
84
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 {
69
91
formatter .PrintError (err , "Error during upgrade" )
70
92
os .Exit (errorcodes .ErrGeneric )
71
93
}
0 commit comments