Skip to content

Commit aaa0ce9

Browse files
committed
On core uninstall consider unversioned args as the installed, not the latest
Otherwise the command arduino-cli core unistall arduino:avr will fail with: arduino:[email protected] is not installed if the installed core it's an earlier version than 1.6.20
1 parent ad14f71 commit aaa0ce9

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

commands/commands_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,20 @@ func TestCoreCommands(t *testing.T) {
355355
require.Zero(t, exitCode, "exit code")
356356
require.Empty(t, strings.TrimSpace(string(d)))
357357

358-
// Install avr
359-
exitCode, d = executeWithArgs(t, "core", "install", "arduino:avr")
358+
// Install avr 1.6.16
359+
exitCode, d = executeWithArgs(t, "core", "install", "arduino:avr@1.6.16")
360360
require.Zero(t, exitCode, "exit code")
361-
require.Contains(t, string(d), AVR+" installed")
361+
require.Contains(t, string(d), "arduino:[email protected] installed")
362362

363363
exitCode, d = executeWithArgs(t, "core", "list")
364364
require.Zero(t, exitCode, "exit code")
365365
require.Contains(t, string(d), "arduino:avr")
366366

367+
// List updatable cores
368+
exitCode, d = executeWithArgs(t, "core", "list", "--updatable")
369+
require.Zero(t, exitCode, "exit code")
370+
require.Contains(t, string(d), "arduino:avr")
371+
367372
// Build sketch for arduino:avr:uno
368373
exitCode, d = executeWithArgs(t, "sketch", "new", "Test1")
369374
require.Zero(t, exitCode, "exit code")
@@ -376,7 +381,7 @@ func TestCoreCommands(t *testing.T) {
376381
// Uninstall arduino:avr
377382
exitCode, d = executeWithArgs(t, "core", "uninstall", "arduino:avr")
378383
require.Zero(t, exitCode, "exit code")
379-
require.Contains(t, string(d), AVR+" uninstalled")
384+
require.Contains(t, string(d), "arduino:[email protected] uninstalled")
380385

381386
// Empty cores list
382387
exitCode, d = executeWithArgs(t, "core", "list")

commands/core/uninstall.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ func runUninstallCommand(cmd *cobra.Command, args []string) {
5252
}
5353

5454
func uninstallPlatformByRef(pm *packagemanager.PackageManager, platformRef *packagemanager.PlatformReference) {
55+
// If no version is specified consider the installed
56+
if platformRef.PlatformVersion == nil {
57+
platform := pm.FindPlatform(platformRef)
58+
if platform == nil {
59+
formatter.PrintErrorMessage("Platform not found " + platformRef.String())
60+
os.Exit(commands.ErrBadCall)
61+
}
62+
platformRelease := platform.GetInstalled()
63+
if platformRelease == nil {
64+
formatter.PrintErrorMessage("Platform not installed " + platformRef.String())
65+
os.Exit(commands.ErrBadCall)
66+
}
67+
platformRef.PlatformVersion = platformRelease.Version
68+
}
69+
5570
platform, tools, err := pm.FindPlatformReleaseDependencies(platformRef)
5671
if err != nil {
5772
formatter.PrintError(err, "Could not determine platform dependencies")

0 commit comments

Comments
 (0)