Commit cffc6b30 authored by Cristian Maglie's avatar Cristian Maglie

Added lib upgrade command

parent 154e95f7
......@@ -238,17 +238,24 @@ func TestLibDownloadAndInstall(t *testing.T) {
require.Contains(t, string(d), "Audio@1.0.3")
require.Contains(t, string(d), "not installed")
// Uninstall (with version)
exitCode, d = executeWithArgs(t, "lib", "uninstall", "Audio@1.0.4")
// Upgrade libraries
exitCode, d = executeWithArgs(t, "lib", "upgrade")
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), "Installed")
require.Contains(t, string(d), "Audio")
require.Contains(t, string(d), "1.0.5")
// Uninstall (without version)
exitCode, d = executeWithArgs(t, "lib", "uninstall", "Audio")
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), "Uninstalling")
require.Contains(t, string(d), "Audio")
require.Contains(t, string(d), "1.0.4")
require.Contains(t, string(d), "1.0.5")
exitCode, d = executeWithArgs(t, "lib", "list")
require.Zero(t, exitCode, "exit code")
require.NotContains(t, string(d), "Audio")
// Uninstall (without version)
// Uninstall (with version)
exitCode, d = executeWithArgs(t, "lib", "install", "Audio@1.0.4")
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), "Audio@1.0.4")
......@@ -257,7 +264,7 @@ func TestLibDownloadAndInstall(t *testing.T) {
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), "Audio")
require.Contains(t, string(d), "1.0.4")
exitCode, d = executeWithArgs(t, "lib", "uninstall", "Audio")
exitCode, d = executeWithArgs(t, "lib", "uninstall", "Audio@1.0.4")
require.Zero(t, exitCode, "exit code")
require.Contains(t, string(d), "Uninstalling")
require.Contains(t, string(d), "Audio")
......
......@@ -48,6 +48,7 @@ func InitCommand() *cobra.Command {
libCommand.AddCommand(initListCommand())
libCommand.AddCommand(initSearchCommand())
libCommand.AddCommand(initUninstallCommand())
libCommand.AddCommand(initUpgradeCommand())
libCommand.AddCommand(initUpdateIndexCommand())
return libCommand
}
/*
* This file is part of arduino-cli.
*
* arduino-cli is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2017 ARDUINO AG (http://www.arduino.cc/)
*/
package lib
import (
"github.com/bcmi-labs/arduino-cli/arduino/libraries/librariesindex"
"github.com/bcmi-labs/arduino-cli/commands"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func initUpgradeCommand() *cobra.Command {
listCommand := &cobra.Command{
Use: "upgrade",
Short: "Upgrades installed libraries.",
Long: "This command ungrades all installed libraries to the latest available version." +
"To upgrade a single library use the 'install' command.",
Example: "arduino lib upgrade",
Args: cobra.NoArgs,
Run: runUpgradeCommand,
}
return listCommand
}
func runUpgradeCommand(cmd *cobra.Command, args []string) {
lm := commands.InitLibraryManager(nil)
list := listLibraries(lm, true)
libReleases := []*librariesindex.Release{}
for _, upgradeDesc := range list.Libraries {
libReleases = append(libReleases, upgradeDesc.Available)
}
downloadLibraries(lm, libReleases)
installLibraries(lm, libReleases)
logrus.Info("Done")
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment