8000 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
Next Next commit
add completion for -b or --fqbn for every command
  • Loading branch information
umbynos committed Oct 18, 2021
commit 9d61a6eac559432203e9fd9fa40ec47c15f076f5
28 changes: 28 additions & 0 deletions cli/arguments/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package arguments

import (
"context"

"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/commands/board"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
)

// GetInstalledBoards is an helper function usefull to autocomplete.
// It returns a list of fqbn
// it's taken from cli/board/listall.go
func GetInstalledBoards(toComplete string) []string {
inst := instance.CreateAndInit() // TODO optimize this: it does not make sense to create an instance everytime

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.GetBoards() {
res = append(res, i.Fqbn)
}
return res
}
4 changes: 4 additions & 0 deletions cli/board/details.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 Down Expand Up @@ -48,6 +49,9 @@ func initDetailsCommand() *cobra.Command {

detailsCommand.Flags().BoolVarP(&showFullDetails, "full", "f", false, tr("Show full board details"))
detailsCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
detailsCommand.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstalledBoards(toComplete), cobra.ShellCompDirectiveDefault
})
detailsCommand.Flags().BoolVarP(&listProgrammers, "list-programmers", "", false, tr("Show list of available programmers"))
// detailsCommand.MarkFlagRequired("fqbn") // enable once `board details <fqbn>` is removed

Expand Down
3 changes: 3 additions & 0 deletions cli/burnbootloader/burnbootloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func NewCommand() *cobra.Command {
}

burnBootloaderCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
burnBootloaderCommand.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstalledBoards(toComplete), cobra.ShellCompDirectiveDefault
})
port.AddToCommand(burnBootloaderCommand)
burnBootloaderCommand.Flags().BoolVarP(&verify, "verify", "t", false, tr("Verify uploaded binary after the upload."))
burnBootloaderCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, tr("Turns on verbose mode."))
Expand Down
19 changes: 1 addition & 18 deletions cli/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (

"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/commands/board"
"github.com/arduino/arduino-cli/commands/compile"
"github.com/arduino/arduino-cli/commands/upload"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
Expand Down Expand Up @@ -84,7 +83,7 @@ func NewCommand() *cobra.Command {

command.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
command.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return getBoards(toComplete), cobra.ShellCompDirectiveDefault
return arguments.GetInstalledBoards(toComplete), cobra.ShellCompDirectiveDefault
})
command.Flags().BoolVar(&showProperties, "show-properties", false, tr("Show all build properties used instead of compiling."))
command.Flags().BoolVar(&preprocess, "preprocess", false, tr("Print preprocessed code to stdout instead of compiling."))
Expand Down Expand Up @@ -276,19 +275,3 @@ func (r *compileResult) String() string {
// The output is already printed via os.Stdout/os.Stdin
return ""
}

func getBoards(toComplete string) []string {
// from listall.go TODO optimize
inst := instance.CreateAndInit()

list, _ := board.ListAll(context.Background(), &rpc.BoardListAllRequest{
Instance: inst,
SearchArgs: nil,
IncludeHiddenBoards: false,
})
var res []string
for _, i := range list.GetBoards() {
res = append(res, i.Fqbn)
}
return res
}
3 changes: 3 additions & 0 deletions cli/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func NewCommand() *cobra.Command {
}

debugCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
debugCommand.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstalledBoards(toComplete), cobra.ShellCompDirectiveDefault
})
port.AddToCommand(debugCommand)
debugCommand.Flags().StringVarP(&programmer, "programmer", "P", "", tr("Programmer to use for debugging"))
debugCommand.Flags().StringVar(&interpreter, "interpreter", "console", tr("Debug interpreter e.g.: %s", "console, mi, mi1, mi2, mi3"))
Expand Down
4 changes: 4 additions & 0 deletions cli/lib/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"sort"
"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/instance"
Expand All @@ -43,6 +44,9 @@ func initExamplesCommand() *cobra.Command {
Run: runExamplesCommand,
}
examplesCommand.Flags().StringVarP(&examplesFlags.fqbn, "fqbn", "b", "", tr("Show libraries for the specified board FQBN."))
examplesCommand.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstalledBoards(toComplete), cobra.ShellCompDirectiveDefault
})
return examplesCommand
}

Expand Down
3 changes: 3 additions & 0 deletions cli/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func NewCommand() *cobra.Command {
}

uploadCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
uploadCommand.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return arguments.GetInstalledBoards(toComplete), cobra.ShellCompDirectiveDefault
})
port.AddToCommand(uploadCommand)
uploadCommand.Flags().StringVarP(&importDir, "input-dir", "", "", tr("Directory containing binaries to upload."))
uploadCommand.Flags().StringVarP(&importFile, "input-file", "i", "", tr("Binary file to upload."))
Expand Down
Loading
0