Skip to content

Commit

Permalink
On core uninstall consider unversioned args as the installed, not the…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
cmaglie committed Aug 13, 2018
1 parent ad14f71 commit aaa0ce9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
13 changes: 9 additions & 4 deletions commands/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,20 @@ func TestCoreCommands(t *testing.T) {
require.Zero(t, exitCode, "exit code")
require.Empty(t, strings.TrimSpace(string(d)))

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

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

// List updatable cores
exitCode, d = executeWithArgs(t, "core", "list", "--updatable")
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), "arduino:avr")

// Build sketch for arduino:avr:uno
exitCode, d = executeWithArgs(t, "sketch", "new", "Test1")
require.Zero(t, exitCode, "exit code")
Expand All @@ -376,7 +381,7 @@ func TestCoreCommands(t *testing.T) {
// Uninstall arduino:avr
exitCode, d = executeWithArgs(t, "core", "uninstall", "arduino:avr")
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), AVR+" uninstalled")
require.Contains(t, string(d), "arduino:[email protected] uninstalled")

// Empty cores list
exitCode, d = executeWithArgs(t, "core", "list")
Expand Down
15 changes: 15 additions & 0 deletions commands/core/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ func runUninstallCommand(cmd *cobra.Command, args []string) {
}

func uninstallPlatformByRef(pm *packagemanager.PackageManager, platformRef *packagemanager.PlatformReference) {
// If no version is specified consider the installed
if platformRef.PlatformVersion == nil {
platform := pm.FindPlatform(platformRef)
if platform == nil {
formatter.PrintErrorMessage("Platform not found " + platformRef.String())
os.Exit(commands.ErrBadCall)
}
platformRelease := platform.GetInstalled()
if platformRelease == nil {
formatter.PrintErrorMessage("Platform not installed " + platformRef.String())
os.Exit(commands.ErrBadCall)
}
platformRef.PlatformVersion = platformRelease.Version
}

platform, tools, err := pm.FindPlatformReleaseDependencies(platformRef)
if err != nil {
formatter.PrintError(err, "Could not determine platform dependencies")
Expand Down

0 comments on commit aaa0ce9

Please sign in to comment.