Skip to content

Commit 342a150

Browse files
committed
add completion for lib install, lib download
1 parent 666e4ca commit 342a150

File tree

5 files changed

+47
-23
lines changed

5 files changed

+47
-23
lines changed

cli/arguments/completion.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,19 @@ func GetUninstallableLibs(toComplete string) []string {
146146
return res
147147
}
148148

149+
// GetInstallableLibs is an helper function useful to autocomplete.
150+
// It returns a list of libs which can be installed/downloaded
151+
func GetInstallableLibs(toComplete string) []string {
152+
inst := instance.CreateAndInit() // TODO optimize this: it does not make sense to create an instance everytime
153+
154+
libs, _ := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchRequest{
155+
Instance: inst,
156+
Query: "", // if no query is specified all the libs are returned
157+
})
158+
var res []string
159+
// transform the data structure for the completion
160+
for _, i := range libs.Libraries {
161+
res = append(res, i.Name)
162+
}
163+
return res
164+
}

cli/lib/download.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"
@@ -39,6 +40,9 @@ func initDownloadCommand() *cobra.Command {
3940
" " + os.Args[0] + " lib download AudioZero@1.0.0 # " + tr("for a specific version."),
4041
Args: cobra.MinimumNArgs(1),
4142
Run: runDownloadCommand,
43+
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
44+
return arguments.GetInstallableLibs(toComplete), cobra.ShellCompDirectiveDefault
45+
},
4246
}
4347
return downloadCommand
4448
}

cli/lib/install.go

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

24+
"github.com/arduino/arduino-cli/cli/arguments"
2425
"github.com/arduino/arduino-cli/cli/errorcodes"
2526
"github.com/arduino/arduino-cli/cli/feedback"
2627
"github.com/arduino/arduino-cli/cli/globals"
@@ -46,6 +47,9 @@ func initInstallCommand() *cobra.Command {
4647
" " + os.Args[0] + " lib install --zip-path /path/to/WiFi101.zip /path/to/ArduinoBLE.zip\n",
4748
Args: cobra.MinimumNArgs(1),
4849
Run: runInstallCommand,
50+
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
51+
return arguments.GetInstallableLibs(toComplete), cobra.ShellCompDirectiveDefault
52+
},
4953
}
5054
installCommand.Flags().BoolVar(&installFlags.noDeps, "no-deps", false, tr("Do not install dependencies."))
5155
installCommand.Flags().BoolVar(&installFlags.gitURL, "git-url", false, tr("Enter git url for libraries hosted on repositories"))

i18n/data/en.po

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ msgstr "(hidden)"
8383
msgid "(legacy)"
8484
msgstr "(legacy)"
8585

86-
#: cli/lib/install.go:73
86+
#: cli/lib/install.go:77
8787
msgid "--git-url and --zip-path are disabled by default, for more information see: %v"
8888
msgstr "--git-url and --zip-path are disabled by default, for more information see: %v"
8989

90-
#: cli/lib/install.go:76
90+
#: cli/lib/install.go:80
9191
msgid "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk."
9292
msgstr "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk."
9393

@@ -186,7 +186,7 @@ msgid "Arduino core operations."
186186
msgstr "Arduino core operations."
187187

188188
#: cli/lib/check_deps.go:50
189-
#: cli/lib/install.go:119
189+
#: cli/lib/install.go:123
190190
msgid "Arguments error: %v"
191191
msgstr "Arguments error: %v"
192192

@@ -453,7 +453,7 @@ msgid "Couldn't determine program size"
453453
msgstr "Couldn't determine program size"
454454

455455
#: cli/arguments/sketch.go:36
456-
#: cli/lib/install.go:99
456+
#: cli/lib/install.go:103
457457
msgid "Couldn't get current working directory: %v"
458458
msgstr "Couldn't get current working directory: %v"
459459

@@ -553,7 +553,7 @@ msgstr "Disconnected"
553553
msgid "Display only the provided gRPC calls"
554554
msgstr "Display only the provided gRPC calls"
555555

556-
#: cli/lib/install.go:50
556+
#: cli/lib/install.go:54
557557
msgid "Do not install dependencies."
558558
msgstr "Do not install dependencies."
559559

@@ -585,20 +585,20 @@ msgstr "Downloading packages"
585585
msgid "Downloads one or more cores and corresponding tool dependencies."
586586
msgstr "Downloads one or more cores and corresponding tool dependencies."
587587

588-
#: cli/lib/download.go:35
589588
#: cli/lib/download.go:36
589+
#: cli/lib/download.go:37
590590
msgid "Downloads one or more libraries without installing them."
591591
msgstr "Downloads one or more libraries without installing them."
592592

593593
#: cli/daemon/daemon.go:59
594594
msgid "Enable debug logging of gRPC calls"
595595
msgstr "Enable debug logging of gRPC calls"
596596

597-
#: cli/lib/install.go:52
597+
#: cli/lib/install.go:56
598598
msgid "Enter a path to zip file"
599599
msgstr "Enter a path to zip file"
600600

601-
#: cli/lib/install.go:51
601+
#: cli/lib/install.go:55
602602
msgid "Enter git url for libraries hosted on repositories"
603603
msgstr "Enter git url for libraries hosted on repositories"
604604

@@ -654,7 +654,7 @@ msgid "Error detecting boards: %v"
654654
msgstr "Error detecting boards: %v"
655655

656656
#: cli/core/download.go:71
657-
#: cli/lib/download.go:62
657+
#: cli/lib/download.go:66
658658
msgid "Error downloading %[1]s: %[2]v"
659659
msgstr "Error downloading %[1]s: %[2]v"
660660

@@ -789,15 +789,15 @@ msgstr "Error in FQBN: %s"
789789
msgid "Error initializing instance: %v"
790790
msgstr "Error initializing instance: %v"
791791

792-
#: cli/lib/install.go:132
792+
#: cli/lib/install.go:136
793793
msgid "Error installing %s: %v"
794794
msgstr "Error installing %s: %v"
795795

796-
#: cli/lib/install.go:110
796+
#: cli/lib/install.go:114
797797
msgid "Error installing Git Library: %v"
798798
msgstr "Error installing Git Library: %v"
799799

800-
#: cli/lib/install.go:87
800+
#: cli/lib/install.go:91
801801
msgid "Error installing Zip Library: %v"
802802
msgstr "Error installing Zip Library: %v"
803803

@@ -1183,8 +1183,8 @@ msgstr "Installing platform %s"
11831183
msgid "Installs one or more cores and corresponding tool dependencies."
11841184
msgstr "Installs one or more cores and corresponding tool dependencies."
11851185

1186-
#: cli/lib/install.go:40
11871186
#: cli/lib/install.go:41
1187+
#: cli/lib/install.go:42
11881188
msgid "Installs one or more specified libraries into the system."
11891189
msgstr "Installs one or more specified libraries into the system."
11901190

@@ -1220,7 +1220,7 @@ msgstr "Invalid additional URL: %v"
12201220
#: cli/core/install.go:95
12211221
#: cli/core/uninstall.go:54
12221222
#: cli/core/upgrade.go:81
1223-
#: cli/lib/download.go:50
1223+
#: cli/lib/download.go:54
12241224
#: cli/lib/uninstall.go:55
12251225
msgid "Invalid argument passed: %v"
12261226
msgstr "Invalid argument passed: %v"
@@ -1295,11 +1295,11 @@ msgid "LIBNAME"
12951295
msgstr "LIBNAME"
12961296

12971297
#: cli/lib/check_deps.go:34
1298-
#: cli/lib/install.go:39
1298+
#: cli/lib/install.go:40
12991299
msgid "LIBRARY"
13001300
msgstr "LIBRARY"
13011301

1302-
#: cli/lib/download.go:34
1302+
#: cli/lib/download.go:35
13031303
#: cli/lib/examples.go:39
13041304
#: cli/lib/search.go:39
13051305
#: cli/lib/uninstall.go:36
@@ -2285,7 +2285,7 @@ msgid "VERSION"
22852285
msgstr "VERSION"
22862286

22872287
#: cli/lib/check_deps.go:34
2288-
#: cli/lib/install.go:39
2288+
#: cli/lib/install.go:40
22892289
msgid "VERSION_NUMBER"
22902290
msgstr "VERSION_NUMBER"
22912291

@@ -2624,18 +2624,18 @@ msgstr "flags"
26242624
msgid "following possible symlink %[1]s: %[2]s"
26252625
msgstr "following possible symlink %[1]s: %[2]s"
26262626

2627-
#: cli/lib/download.go:39
2627+
#: cli/lib/download.go:40
26282628
msgid "for a specific version."
26292629
msgstr "for a specific version."
26302630

26312631
#: cli/lib/check_deps.go:38
2632-
#: cli/lib/download.go:38
2633-
#: cli/lib/install.go:43
2632+
#: cli/lib/download.go:39
2633+
#: cli/lib/install.go:44
26342634
msgid "for the latest version."
26352635
msgstr "for the latest version."
26362636

26372637
#: cli/lib/check_deps.go:39
2638-
#: cli/lib/install.go:44
2638+
#: cli/lib/install.go:45
26392639
msgid "for the specific version."
26402640
msgstr "for the specific version."
26412641

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)