Skip to content

Commit cffc6b3

Browse files
committed
Added lib upgrade command
1 parent 154e95f commit cffc6b3

File tree

3 files changed

+76
-5
lines changed

3 files changed

+76
-5
lines changed

commands/commands_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,24 @@ func TestLibDownloadAndInstall(t *testing.T) {
238238
require.Contains(t, string(d), "[email protected]")
239239
require.Contains(t, string(d), "not installed")
240240

241-
// Uninstall (with version)
242-
exitCode, d = executeWithArgs(t, "lib", "uninstall", "[email protected]")
241+
// Upgrade libraries
242+
exitCode, d = executeWithArgs(t, "lib", "upgrade")
243+
require.Zero(t, exitCode, "exit code")
244+
require.Contains(t, string(d), "Installed")
245+
require.Contains(t, string(d), "Audio")
246+
require.Contains(t, string(d), "1.0.5")
247+
248+
// Uninstall (without version)
249+
exitCode, d = executeWithArgs(t, "lib", "uninstall", "Audio")
243250
require.Zero(t, exitCode, "exit code")
244251
require.Contains(t, string(d), "Uninstalling")
245252
require.Contains(t, string(d), "Audio")
246-
require.Contains(t, string(d), "1.0.4")
253+
require.Contains(t, string(d), "1.0.5")
247254
exitCode, d = executeWithArgs(t, "lib", "list")
248255
require.Zero(t, exitCode, "exit code")
249256
require.NotContains(t, string(d), "Audio")
250257

251-
// Uninstall (without version)
258+
// Uninstall (with version)
252259
exitCode, d = executeWithArgs(t, "lib", "install", "[email protected]")
253260
require.Zero(t, exitCode, "exit code")
254261
require.Contains(t, string(d), "[email protected]")
@@ -257,7 +264,7 @@ func TestLibDownloadAndInstall(t *testing.T) {
257264
require.Zero(t, exitCode, "exit code")
258265
require.Contains(t, string(d), "Audio")
259266
require.Contains(t, string(d), "1.0.4")
260-
exitCode, d = executeWithArgs(t, "lib", "uninstall", "Audio")
267+
exitCode, d = executeWithArgs(t, "lib", "uninstall", "Audio@1.0.4")
261268
require.Zero(t, exitCode, "exit code")
262269
require.Contains(t, string(d), "Uninstalling")
263270
require.Contains(t, string(d), "Audio")

commands/lib/lib.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func InitCommand() *cobra.Command {
4848
libCommand.AddCommand(initListCommand())
4949
libCommand.AddCommand(initSearchCommand())
5050
libCommand.AddCommand(initUninstallCommand())
51+
libCommand.AddCommand(initUpgradeCommand())
5152
libCommand.AddCommand(initUpdateIndexCommand())
5253
return libCommand
5354
}

commands/lib/upgrade.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* This file is part of arduino-cli.
3+
*
4+
* arduino-cli is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*
18+
* As a special exception, you may use this file as part of a free software
19+
* library without restriction. Specifically, if other files instantiate
20+
* templates or use macros or inline functions from this file, or you compile
21+
* this file and link it with other files to produce an executable, this
22+
* file does not by itself cause the resulting executable to be covered by
23+
* the GNU General Public License. This exception does not however
24+
* invalidate any other reasons why the executable file might be covered by
25+
* the GNU General Public License.
26+
*
27+
* Copyright 2017 ARDUINO AG (http://www.arduino.cc/)
28+
*/
29+
30+
package lib
31+
32+
import (
33+
"github.com/bcmi-labs/arduino-cli/arduino/libraries/librariesindex"
34+
"github.com/bcmi-labs/arduino-cli/commands"
35+
"github.com/sirupsen/logrus"
36+
"github.com/spf13/cobra"
37+
)
38+
39+
func initUpgradeCommand() *cobra.Command {
40+
listCommand := &cobra.Command{
41+
Use: "upgrade",
42+
Short: "Upgrades installed libraries.",
43+
Long: "This command ungrades all installed libraries to the latest available version." +
44+
"To upgrade a single library use the 'install' command.",
45+
Example: "arduino lib upgrade",
46+
Args: cobra.NoArgs,
47+
Run: runUpgradeCommand,
48+
}
49+
return listCommand
50+
}
51+
52+
func runUpgradeCommand(cmd *cobra.Command, args []string) {
53+
lm := commands.InitLibraryManager(nil)
54+
list := listLibraries(lm, true)
55+
libReleases := []*librariesindex.Release{}
56+
for _, upgradeDesc := range list.Libraries {
57+
libReleases = append(libReleases, upgradeDesc.Available)
58+
}
59+
60+
downloadLibraries(lm, libReleases)
61+
installLibraries(lm, libReleases)
62+
logrus.Info("Done")
63+
}

0 commit comments

Comments
 (0)