-
-
Notifications
You must be signed in to change notification settings - Fork 405
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
add dynamic completion #1509
Changes from all commits
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 b7263bf
add completion for `-l` or `--protocol`
umbynos b6ed62f
the previous implementation was working only with a board connected t…
umbynos 3e57b18
add static completion for `--log-level, `--log-format` and `--format`
umbynos 0c0823f
add completion for `-P` or `--programmer` & fix typo
umbynos fe4ab51
add completion for `core uninstall`
umbynos fc82c12
add completion for `core install` and `core download`
umbynos e79ae01
add completion for `lib uninstall`
umbynos 6d560b2
add completion for `lib install`, `lib download`
umbynos 3486d94
add completion for `lib examples`
umbynos 28dfdc1
add completion for `config add`, `config remove`, `config delete` and…
umbynos 27d300c
add completion for `lib deps`
umbynos d7be814
add tests
umbynos 4559c25
enhance the completion for `config add` and `config remove`
umbynos 6b1a01c
add description completion suggestion for core, lib, fqbn, programmer
umbynos 5462031
add completion also for `-p` or `--port` flag
umbynos fe2cf65
remove the `toComplete` parameter from all the completion functions
umbynos 2a953a9
fixes after rebase
umbynos 7235896
update docs
umbynos d6c4732
add `-b` or `--fqbn` completion for the monitor command and tests
umbynos c5ee4d0
apply suggestions from code review
umbynos d6d4502
fixes after rebase
umbynos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
package arguments | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/arduino/arduino-cli/arduino/cores" | ||
"github.com/arduino/arduino-cli/cli/instance" | ||
"github.com/arduino/arduino-cli/commands" | ||
"github.com/arduino/arduino-cli/commands/board" | ||
"github.com/arduino/arduino-cli/commands/core" | ||
"github.com/arduino/arduino-cli/commands/lib" | ||
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" | ||
) | ||
|
||
// GetInstalledBoards is an helper function useful to autocomplete. | ||
// It returns a list of fqbn | ||
// it's taken from cli/board/listall.go | ||
func GetInstalledBoards() []string { | ||
inst := instance.CreateAndInit() | ||
|
||
list, _ := board.ListAll(context.Background(), &rpc.BoardListAllRequest{ | ||
Instance: inst, | ||
SearchArgs: nil, | ||
IncludeHiddenBoards: false, | ||
}) | ||
var res []string | ||
// transform the data structure for the completion | ||
for _, i := range list.Boards { | ||
res = append(res, i.Fqbn+"\t"+i.Name) | ||
} | ||
return res | ||
} | ||
|
||
// GetInstalledProtocols is an helper function useful to autocomplete. | ||
// It returns a list of protocols available based on the installed boards | ||
func GetInstalledProtocols() []string { | ||
inst := instance.CreateAndInit() | ||
pm := commands.GetPackageManager(inst.Id) | ||
boards := pm.InstalledBoards() | ||
|
||
installedProtocols := make(map[string]struct{}) | ||
for _, board := range boards { | ||
for _, protocol := range board.Properties.SubTree("upload.tool").FirstLevelKeys() { | ||
if protocol == "default" { | ||
// default is used as fallback when trying to upload to a board | ||
// using a protocol not defined for it, it's useless showing it | ||
// in autocompletion | ||
continue | ||
} | ||
installedProtocols[protocol] = struct{}{} | ||
} | ||
} | ||
res := make([]string, len(installedProtocols)) | ||
i := 0 | ||
for k := range installedProtocols { | ||
res[i] = k | ||
i++ | ||
} | ||
return res | ||
} | ||
|
||
// GetInstalledProgrammers is an helper function useful to autocomplete. | ||
// It returns a list of programmers available based on the installed boards | ||
func GetInstalledProgrammers() []string { | ||
inst := instance.CreateAndInit() | ||
pm := commands.GetPackageManager(inst.Id) | ||
|
||
// we need the list of the available fqbn in order to get the list of the programmers | ||
list, _ := board.ListAll(context.Background(), &rpc.BoardListAllRequest{ | ||
Instance: inst, | ||
SearchArgs: nil, | ||
IncludeHiddenBoards: false, | ||
}) | ||
|
||
installedProgrammers := make(map[string]string) | ||
for _, board := range list.Boards { | ||
fqbn, _ := cores.ParseFQBN(board.Fqbn) | ||
_, boardPlatform, _, _, _, _ := pm.ResolveFQBN(fqbn) | ||
for programmerID, programmer := range boardPlatform.Programmers { | ||
installedProgrammers[programmerID] = programmer.Name | ||
} | ||
} | ||
|
||
res := make([]string, len(installedProgrammers)) | ||
i := 0 | ||
for programmerID := range installedProgrammers { | ||
res[i] = programmerID + "\t" + installedProgrammers[programmerID] | ||
i++ | ||
} | ||
return res | ||
} | ||
|
||
// GetUninstallableCores is an helper function useful to autocomplete. | ||
// It returns a list of cores which can be uninstalled | ||
func GetUninstallableCores() []string { | ||
inst := instance.CreateAndInit() | ||
|
||
platforms, _ := core.GetPlatforms(&rpc.PlatformListRequest{ | ||
Instance: inst, | ||
UpdatableOnly: false, | ||
All: false, | ||
}) | ||
var res []string | ||
// transform the data structure for the completion | ||
for _, i := range platforms { | ||
res = append(res, i.Id+"\t"+i.Name) | ||
} | ||
return res | ||
} | ||
|
||
// GetInstallableCores is an helper function useful to autocomplete. | ||
// It returns a list of cores which can be installed/downloaded | ||
func GetInstallableCores() []string { | ||
inst := instance.CreateAndInit() | ||
|
||
platforms, _ := core.PlatformSearch(&rpc.PlatformSearchRequest{ | ||
Instance: inst, | ||
SearchArgs: "", | ||
AllVersions: false, | ||
}) | ||
var res []string | ||
// transform the data structure for the completion | ||
for _, i := range platforms.SearchOutput { | ||
res = append(res, i.Id+"\t"+i.Name) | ||
} | ||
return res | ||
} | ||
|
||
// GetInstalledLibraries is an helper function useful to autocomplete. | ||
// It returns a list of libs which are currently installed, including the builtin ones | ||
func GetInstalledLibraries() []string { | ||
return getLibraries(true) | ||
} | ||
|
||
// GetUninstallableLibraries is an helper function useful to autocomplete. | ||
// It returns a list of libs which can be uninstalled | ||
func GetUninstallableLibraries() []string { | ||
return getLibraries(false) | ||
} | ||
|
||
func getLibraries(all bool) []string { | ||
inst := instance.CreateAndInit() | ||
libs, _ := lib.LibraryList(context.Background(), &rpc.LibraryListRequest{ | ||
Instance: inst, | ||
All: all, | ||
Updatable: false, | ||
Name: "", | ||
Fqbn: "", | ||
}) | ||
var res []string | ||
// transform the data structure for the completion | ||
for _, i := range libs.InstalledLibraries { | ||
res = append(res, i.Library.Name+"\t"+i.Library.Sentence) | ||
} | ||
return res | ||
} | ||
|
||
// GetInstallableLibs is an helper function useful to autocomplete. | ||
// It returns a list of libs which can be installed/downloaded | ||
func GetInstallableLibs() []string { | ||
inst := instance.CreateAndInit() | ||
|
||
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+"\t"+i.Latest.Sentence) | ||
} | ||
return res | ||
} | ||
|
||
// GetConnectedBoards is an helper function useful to autocomplete. | ||
// It returns a list of boards which are currently connected | ||
// Obviously it does not suggests network ports because of the timeout | ||
func GetConnectedBoards() []string { | ||
inst := instance.CreateAndInit() | ||
|
||
list, _ := board.List(&rpc.BoardListRequest{ | ||
Instance: inst, | ||
}) | ||
var res []string | ||
// transform the data structure for the completion | ||
for _, i := range list { | ||
res = append(res, i.Port.Address) | ||
} | ||
return res | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.