Skip to content

Commit 666e4ca

Browse files
committed
add completion for lib uninstall
1 parent 5ff678f commit 666e4ca

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

cli/arguments/completion.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/arduino/arduino-cli/commands"
99
"github.com/arduino/arduino-cli/commands/board"
1010
"github.com/arduino/arduino-cli/commands/core"
11+
"github.com/arduino/arduino-cli/commands/lib"
1112
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
1213
)
1314

@@ -125,3 +126,23 @@ func GetInstallableCores(toComplete string) []string {
125126
}
126127
return res
127128
}
129+
130+
// GetUninstallableLibs is an helper function useful to autocomplete.
131+
// It returns a list of libs which can be uninstalled
132+
func GetUninstallableLibs(toComplete string) []string {
133+
inst := instance.CreateAndInit() // TODO optimize this: it does not make sense to create an instance everytime
134+
libs, _ := lib.LibraryList(context.Background(), &rpc.LibraryListRequest{
135+
Instance: inst,
136+
All: false,
137+
Updatable: false,
138+
Name: "",
139+
Fqbn: "",
140+
})
141+
var res []string
142+
// transform the data structure for the completion
143+
for _, i := range libs.InstalledLibraries {
144+
res = append(res, i.GetLibrary().Name)
145+
}
146+
return res
147+
}
148+

cli/lib/uninstall.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"os"
2222

23+
"github.com/arduino/arduino-cli/cli/arguments"
2324
"github.com/arduino/arduino-cli/cli/errorcodes"
2425
"github.com/arduino/arduino-cli/cli/feedback"
2526
"github.com/arduino/arduino-cli/cli/instance"
@@ -38,6 +39,9 @@ func initUninstallCommand() *cobra.Command {
3839
Example: " " + os.Args[0] + " lib uninstall AudioZero",
3940
Args: cobra.MinimumNArgs(1),
4041
Run: runUninstallCommand,
42+
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
43+
return arguments.GetUninstallableLibs(toComplete), cobra.ShellCompDirectiveDefault
44+
},
4145
}
4246
return uninstallCommand
4347
}

i18n/data/en.po

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ msgstr "Error serializing compilation database: %s"
892892
msgid "Error starting board discoveries"
893893
msgstr "Error starting board discoveries"
894894

895-
#: cli/lib/uninstall.go:62
895+
#: cli/lib/uninstall.go:66
896896
msgid "Error uninstalling %[1]s: %[2]v"
897897
msgstr "Error uninstalling %[1]s: %[2]v"
898898

@@ -1221,7 +1221,7 @@ msgstr "Invalid additional URL: %v"
12211221
#: cli/core/uninstall.go:54
12221222
#: cli/core/upgrade.go:81
12231223
#: cli/lib/download.go:50
1224-
#: cli/lib/uninstall.go:51
1224+
#: cli/lib/uninstall.go:55
12251225
msgid "Invalid argument passed: %v"
12261226
msgstr "Invalid argument passed: %v"
12271227

@@ -1302,7 +1302,7 @@ msgstr "LIBRARY"
13021302
#: cli/lib/download.go:34
13031303
#: cli/lib/examples.go:39
13041304
#: cli/lib/search.go:39
1305-
#: cli/lib/uninstall.go:35
1305+
#: cli/lib/uninstall.go:36
13061306
msgid "LIBRARY_NAME"
13071307
msgstr "LIBRARY_NAME"
13081308

@@ -2105,8 +2105,8 @@ msgstr "Uninstalling %s: tool is no more required"
21052105
msgid "Uninstalls one or more cores and corresponding tool dependencies if no longer used."
21062106
msgstr "Uninstalls one or more cores and corresponding tool dependencies if no longer used."
21072107

2108-
#: cli/lib/uninstall.go:36
21092108
#: cli/lib/uninstall.go:37
2109+
#: cli/lib/uninstall.go:38
21102110
msgid "Uninstalls one or more libraries."
21112111
msgstr "Uninstalls one or more libraries."
21122112

i18n/rice-box.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)