10000 add dynamic completion by umbynos · Pull Request #1509 · arduino/arduino-cli · GitHub
[go: up one dir, main page]

Skip to content

add dynamic completion #1509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9d61a6e
add completion for `-b` or `--fqbn` for every command
umbynos Oct 18, 2021
b7263bf
add completion for `-l` or `--protocol`
umbynos Oct 18, 2021
b6ed62f
the previous implementation was working only with a board connected t…
umbynos Oct 5, 2021
3e57b18
add static completion for `--log-level, `--log-format` and `--format`
umbynos Oct 6, 2021
0c0823f
add completion for `-P` or `--programmer` & fix typo
umbynos Oct 6, 2021
fe4ab51
add completion for `core uninstall`
umbynos Oct 6, 2021
fc82c12
add completion for `core install` and `core download`
umbynos Oct 6, 2021
e79ae01
add completion for `lib uninstall`
umbynos Oct 6, 2021
6d560b2
add completion for `lib install`, `lib download`
umbynos Oct 7, 2021
3486d94
add completion for `lib examples`
umbynos Oct 7, 2021
28dfdc1
add completion for `config add`, `config remove`, `config delete` and…
umbynos Oct 7, 2021
27d300c
add completion for `lib deps`
umbynos Oct 7, 2021
d7be814
add tests
umbynos Oct 12, 2021
4559c25
enhance the completion for `config add` and `config remove`
umbynos Oct 13, 2021
6b1a01c
add description completion suggestion for core, lib, fqbn, programmer
umbynos Oct 13, 2021
5462031
add completion also for `-p` or `--port` flag
umbynos Oct 13, 2021
fe2cf65
remove the `toComplete` parameter from all the completion functions
umbynos Oct 13, 2021
2a953a9
fixes after rebase
umbynos Oct 13, 2021
7235896
update docs
umbynos Oct 13, 2021
d6c4732
add `-b` or `--fqbn` completion for the monitor command and tests
umbynos Oct 14, 2021
c5ee4d0
apply suggestions from code review
umbynos Oct 15, 2021
d6d4502
fixes after rebase
umbynos Oct 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add completion for lib install, lib download
  • Loading branch information
umbynos committed Oct 18, 2021
commit 6d560b2112df5c55a291f62e0094e75913d5b641
16 changes: 16 additions & 0 deletions cli/arguments/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,19 @@ func GetUninstallableLibs(toComplete string) []string {
return res
}

// GetInstallableLibs is an helper function useful to autocomplete.
// It returns a list of libs which can be installed/downloaded
func GetInstallableLibs(toComplete string) []string {
inst := instance.CreateAndInit() // TODO optimize this: it does not make sense to create an instance everytime

libs, _ := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchRequest{
Instance: inst,
Query: "", // if no query is specified all the libs are returned
})
var res []string
// transform the data structure for the completion
for _, i := range libs.Libraries {
res = append(res, i.Name)
}
return res
}
4 changes: 4 additions & 0 deletions cli/lib/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"os"

"github.com/arduino/arduino-cli/cli/arguments"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/feedback"
"github.com/arduino/arduino-cli/cli/instance"
Expand All @@ -39,6 +40,9 @@ func initDownloadCommand() *cobra.Command {
" " + os.Args[0] + " lib download AudioZero@1.0.0 # " + tr("for a specific version."),
Args: cobra.MinimumNArgs(1),
Run: runDownloadCommand,
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstallableLibs(toComplete), cobra.ShellCompDirectiveDefault
},
}
return downloadCommand
}
Expand Down
4 changes: 4 additions & 0 deletions cli/lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"os"
"strings"

"github.com/arduino/arduino-cli/cli/arguments"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/feedback"
"github.com/arduino/arduino-cli/cli/globals"
Expand All @@ -46,6 +47,9 @@ func initInstallCommand() *cobra.Command {
" " + os.Args[0] + " lib install --zip-path /path/to/WiFi101.zip /path/to/ArduinoBLE.zip\n",
Args: cobra.MinimumNArgs(1),
Run: runInstallCommand,
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstallableLibs(toComplete), cobra.ShellCompDirectiveDefault
},
}
installCommand.Flags().BoolVar(&installFlags.noDeps, "no-deps", false, tr("Do not install dependencies."))
installCommand.Flags().BoolVar(&installFlags.gitURL, "git-url", false, tr("Enter git url for libraries hosted on repositories"))
Expand Down
42 changes: 21 additions & 21 deletions i18n/data/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ msgstr "(hidden)"
msgid "(legacy)"
msgstr "(legacy)"

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

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

Expand Down Expand Up @@ -186,7 +186,7 @@ msgid "Arduino core operations."
msgstr "Arduino core operations."

#: cli/lib/check_deps.go:50
#: cli/lib/install.go:119
#: cli/lib/install.go:123
msgid "Arguments error: %v"
msgstr "Arguments error: %v"

Expand Down Expand Up @@ -453,7 +453,7 @@ msgid "Couldn't determine program size"
msgstr "Couldn't determine program size"

#: cli/arguments/sketch.go:36
#: cli/lib/install.go:99
#: cli/lib/install.go:103
msgid "Couldn't get current working directory: %v"
msgstr "Couldn't get current working directory: %v"

Expand Down Expand Up @@ -553,7 +553,7 @@ msgstr "Disconnected"
msgid "Display only the provided gRPC calls"
msgstr "Display only the provided gRPC calls"

#: cli/lib/install.go:50
#: cli/lib/install.go:54
msgid "Do not install dependencies."
msgstr "Do not install dependencies."

Expand Down Expand Up @@ -585,20 +585,20 @@ msgstr "Downloading packages"
msgid "Downloads one or more cores and corresponding tool dependencies."
msgstr "Downloads one or more cores and corresponding tool dependencies."

#: cli/lib/download.go:35
#: cli/lib/download.go:36
#: cli/lib/download.go:37
msgid "Downloads one or more libraries without installing them."
msgstr "Downloads one or more libraries without installing them."

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

#: cli/lib/install.go:52
#: cli/lib/install.go:56
msgid "Enter a path to zip file"
msgstr "Enter a path to zip file"

#: cli/lib/install.go:51
#: cli/lib/install.go:55
msgid "Enter git url for libraries hosted on repositories"
msgstr "Enter git url for libraries hosted on repositories"

Expand Down Expand Up @@ -654,7 +654,7 @@ msgid "Error detecting boards: %v"
msgstr "Error detecting boards: %v"

#: cli/core/download.go:71
#: cli/lib/download.go:62
#: cli/lib/download.go:66
msgid "Error downloading %[1]s: %[2]v"
msgstr "Error downloading %[1]s: %[2]v"

Expand Down Expand Up @@ -789,15 +789,15 @@ msgstr "Error in FQBN: %s"
msgid "Error initializing instance: %v"
msgstr "Error initializing instance: %v"

#: cli/lib/install.go:132
#: cli/lib/install.go:136
msgid "Error installing %s: %v"
msgstr "Error installing %s: %v"

#: cli/lib/install.go:110
#: cli/lib/install.go:114
msgid "Error installing Git Library: %v"
msgstr "Error installing Git Library: %v"

#: cli/lib/install.go:87
#: cli/lib/install.go:91
msgid "Error installing Zip Library: %v"
msgstr "Error installing Zip Library: %v"

Expand Down Expand Up @@ -1183,8 +1183,8 @@ msgstr "Installing platform %s"
msgid "Installs one or more cores and corresponding tool dependencies."
msgstr "Installs one or more cores and corresponding tool dependencies."

#: cli/lib/install.go:40
#: cli/lib/install.go:41
#: cli/lib/install.go:42
msgid "Installs one or more specified libraries into the system."
msgstr "Installs one or more specified libraries into the system."

Expand Down Expand Up @@ -1220,7 +1220,7 @@ msgstr "Invalid additional URL: %v"
#: cli/core/install.go:95
#: cli/core/uninstall.go:54
#: cli/core/upgrade.go:81
#: cli/lib/download.go:50
#: cli/lib/download.go:54
#: cli/lib/uninstall.go:55
msgid "Invalid argument passed: %v"
msgstr "Invalid argument passed: %v"
Expand Down Expand Up @@ -1295,11 +1295,11 @@ msgid "LIBNAME"
msgstr "LIBNAME"

#: cli/lib/check_deps.go:34
#: cli/lib/install.go:39
#: cli/lib/install.go:40
msgid "LIBRARY"
msgstr "LIBRARY"

#: cli/lib/download.go:34
#: cli/lib/download.go:35
#: cli/lib/examples.go:39
#: cli/lib/search.go:39
#: cli/lib/uni A92F nstall.go:36
Expand Down Expand Up @@ -2285,7 +2285,7 @@ msgid "VERSION"
msgstr "VERSION"

#: cli/lib/check_deps.go:34
#: cli/lib/install.go:39
#: cli/lib/install.go:40
msgid "VERSION_NUMBER"
msgstr "VERSION_NUMBER"

Expand Down Expand Up @@ -2624,18 +2624,18 @@ msgstr "flags"
msgid "following possible symlink %[1]s: %[2]s"
msgstr "following possible symlink %[1]s: %[2]s"

#: cli/lib/download.go:39
#: cli/lib/download.go:40
msgid "for a specific version."
msgstr "for a specific version."

#: cli/lib/check_deps.go:38
#: cli/lib/download.go:38
#: cli/lib/install.go:43
#: cli/lib/download.go:39
#: cli/lib/install.go:44
msgid "for the latest version."
msgstr "for the latest version."

#: cli/lib/check_deps.go:39
#: cli/lib/install.go:44
#: cli/lib/install.go:45
msgid "for the specific version."
msgstr "for the specific version."

Expand Down
0