Skip to content

Commit 43d267e

Browse files
committed
remove the toComplete parameter from all the completion functions
as of now this parameter is useless because if a string is typed in the terminal it cannot be swapped with a different one. For example if I write `arduino-cli compile -b avr<TAB><TAB>` the completion function returns all elements starting with `arduino:avr...`. So the completions are not showed because they cannot be swapped with a string that starts differently. The only shell which seems to support this seems to be zsh
1 parent 856868e commit 43d267e

18 files changed

+31
-31
lines changed

Diff for: cli/arguments/completion.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
// GetInstalledBoards is an helper function useful to autocomplete.
1616
// It returns a list of fqbn
1717
// it's taken from cli/board/listall.go
18-
func GetInstalledBoards(toComplete string) []string {
18+
func GetInstalledBoards() []string {
1919
inst := instance.CreateAndInit() // TODO optimize this: it does not make sense to create an instance everytime
2020

2121
list, _ := board.ListAll(context.Background(), &rpc.BoardListAllRequest{
@@ -33,7 +33,7 @@ func GetInstalledBoards(toComplete string) []string {
3333

3434
// GetInstalledProtocols is an helper function useful to autocomplete.
3535
// It returns a list of protocols available based on the installed boards
36-
func GetInstalledProtocols(toComplete string) []string {
36+
func GetInstalledProtocols() []string {
3737
inst := instance.CreateAndInit() // TODO optimize this: it does not make sense to create an instance everytime
3838
pm := commands.GetPackageManager(inst.Id)
3939
boards := pm.InstalledBoards()
@@ -60,7 +60,7 @@ func GetInstalledProtocols(toComplete string) []string {
6060

6161
// GetInstalledProgrammers is an helper function useful to autocomplete.
6262
// It returns a list of programmers available based on the installed boards
63-
func GetInstalledProgrammers(toComplete string) []string {
63+
func GetInstalledProgrammers() []string {
6464
inst := instance.CreateAndInit() // TODO optimize this: it does not make sense to create an instance everytime
6565
pm := commands.GetPackageManager(inst.Id)
6666

@@ -91,7 +91,7 @@ func GetInstalledProgrammers(toComplete string) []string {
9191

9292
// GetUninstallableCores is an helper function useful to autocomplete.
9393
// It returns a list of cores which can be uninstalled
94-
func GetUninstallableCores(toComplete string) []string {
94+
func GetUninstallableCores() []string {
9595
inst := instance.CreateAndInit() // TODO optimize this: it does not make sense to create an instance everytime
9696

9797
platforms, _ := core.GetPlatforms(&rpc.PlatformListRequest{
@@ -109,7 +109,7 @@ func GetUninstallableCores(toComplete string) []string {
109109

110110
// GetInstallableCores is an helper function useful to autocomplete.
111111
// It returns a list of cores which can be installed/downloaded
112-
func GetInstallableCores(toComplete string) []string {
112+
func GetInstallableCores() []string {
113113
inst := instance.CreateAndInit() // TODO optimize this: it does not make sense to create an instance everytime
114114

115115
platforms, _ := core.PlatformSearch(&rpc.PlatformSearchRequest{
@@ -127,7 +127,7 @@ func GetInstallableCores(toComplete string) []string {
127127

128128
// GetUninstallableLibs is an helper function useful to autocomplete.
129129
// It returns a list of libs which can be uninstalled
130-
func GetUninstallableLibs(toComplete string) []string {
130+
func GetUninstallableLibs() []string {
131131
inst := instance.CreateAndInit() // TODO optimize this: it does not make sense to create an instance everytime
132132
libs, _ := lib.LibraryList(context.Background(), &rpc.LibraryListRequest{
133133
Instance: inst,
@@ -146,7 +146,7 @@ func GetUninstallableLibs(toComplete string) []string {
146146

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

152152
libs, _ := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchRequest{
@@ -164,7 +164,7 @@ func GetInstallableLibs(toComplete string) []string {
164164
// GetConnectedBoards is an helper function useful to autocomplete.
165165
// It returns a list of boards which are currently connected
166166
// Obviously it does not suggests network ports because of the timeout
167-
func GetConnectedBoards(toComplete string) []string {
167+
func GetConnectedBoards() []string {
168168
inst := instance.CreateAndInit() // TODO optimize this: it does not make sense to create an instance everytime
169169

170170
list, _ := board.List(&rpc.BoardListRequest{

Diff for: cli/arguments/port.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ type Port struct {
4343
func (p *Port) AddToCommand(cmd *cobra.Command) {
4444
cmd.Flags().StringVarP(&p.address, "port", "p", "", tr("Upload port address, e.g.: COM3 or /dev/ttyACM2"))
4545
cmd.RegisterFlagCompletionFunc("port", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
46-
return GetConnectedBoards(toComplete), cobra.ShellCompDirectiveDefault
46+
return GetConnectedBoards(), cobra.ShellCompDirectiveDefault
4747
})
4848
cmd.Flags().StringVarP(&p.protocol, "protocol", "l", "", tr("Upload port protocol, e.g: serial"))
4949
cmd.RegisterFlagCompletionFunc("protocol", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
50-
return GetInstalledProtocols(toComplete), cobra.ShellCompDirectiveDefault
50+
return GetInstalledProtocols(), cobra.ShellCompDirectiveDefault
5151
})
5252
cmd.Flags().DurationVar(&p.timeout, "discovery-timeout", 5*time.Second, tr("Max time to wait for port discovery, e.g.: 30s, 1m"))
5353
}

Diff for: cli/board/details.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func initDetailsCommand() *cobra.Command {
5050
detailsCommand.Flags().BoolVarP(&showFullDetails, "full", "f", false, tr("Show full board details"))
5151
detailsCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
5252
detailsCommand.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
53-
return arguments.GetInstalledBoards(toComplete), cobra.ShellCompDirectiveDefault
53+
return arguments.GetInstalledBoards(), cobra.ShellCompDirectiveDefault
5454
})
5555
detailsCommand.Flags().BoolVarP(&listProgrammers, "list-programmers", "", false, tr("Show list of available programmers"))
5656
// detailsCommand.MarkFlagRequired("fqbn") // enable once `board details <fqbn>` is removed

Diff for: cli/burnbootloader/burnbootloader.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ func NewCommand() *cobra.Command {
5252

5353
burnBootloaderCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
5454
burnBootloaderCommand.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
55-
return arguments.GetInstalledBoards(toComplete), cobra.ShellCompDirectiveDefault
55+
return arguments.GetInstalledBoards(), cobra.ShellCompDirectiveDefault
5656
})
5757
port.AddToCommand(burnBootloaderCommand)
5858
burnBootloaderCommand.Flags().BoolVarP(&verify, "verify", "t", false, tr("Verify uploaded binary after the upload."))
5959
burnBootloaderCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, tr("Turns on verbose mode."))
6060
burnBootloaderCommand.Flags().StringVarP(&programmer, "programmer", "P", "", tr("Use the specified programmer to upload."))
6161
burnBootloaderCommand.RegisterFlagCompletionFunc("programmer", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
62-
return arguments.GetInstalledProgrammers(toComplete), cobra.ShellCompDirectiveDefault
62+
return arguments.GetInstalledProgrammers(), cobra.ShellCompDirectiveDefault
6363
})
6464
burnBootloaderCommand.Flags().BoolVar(&dryRun, "dry-run", false, tr("Do not perform the actual upload, just log out actions"))
6565
burnBootloaderCommand.Flags().MarkHidden("dry-run")

Diff for: cli/compile/compile.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func NewCommand() *cobra.Command {
8383

8484
command.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
8585
command.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
86-
return arguments.GetInstalledBoards(toComplete), cobra.ShellCompDirectiveDefault
86+
return arguments.GetInstalledBoards(), cobra.ShellCompDirectiveDefault
8787
})
8888
command.Flags().BoolVar(&showProperties, "show-properties", false, tr("Show all build properties used instead of compiling."))
8989
command.Flags().BoolVar(&preprocess, "preprocess", false, tr("Print preprocessed code to stdout instead of compiling."))
@@ -110,7 +110,7 @@ func NewCommand() *cobra.Command {
110110
command.Flags().BoolVar(&optimizeForDebug, "optimize-for-debug", false, tr("Optional, optimize compile output for debugging, rather than for release."))
111111
command.Flags().StringVarP(&programmer, "programmer", "P", "", tr("Optional, use the specified programmer to upload."))
112112
command.RegisterFlagCompletionFunc("programmer", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
113-
return arguments.GetInstalledProgrammers(toComplete), cobra.ShellCompDirectiveDefault
113+
return arguments.GetInstalledProgrammers(), cobra.ShellCompDirectiveDefault
114114
})
115115
command.Flags().BoolVar(&compilationDatabaseOnly, "only-compilation-database", false, tr("Just produce the compilation database, without actually compiling."))
116116
command.Flags().BoolVar(&clean, "clean", false, tr("Optional, cleanup the build folder and do not use any cached build."))

Diff for: cli/config/add.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func initAddCommand() *cobra.Command {
3636
Args: cobra.MinimumNArgs(2),
3737
Run: runAddCommand,
3838
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
39-
return GetConfigurationKeys(toComplete), cobra.ShellCompDirectiveDefault
39+
return GetConfigurationKeys(), cobra.ShellCompDirectiveDefault
4040
},
4141
}
4242
return addCommand

Diff for: cli/config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func NewCommand() *cobra.Command {
4646

4747
// GetConfigurationKeys is an helper function useful to autocomplete.
4848
// It returns a list of configuration keys which can be changed
49-
func GetConfigurationKeys(toComplete string) []string {
49+
func GetConfigurationKeys() []string {
5050
var res []string
5151
keys := configuration.Settings.AllKeys()
5252
for _, key := range keys {

Diff for: cli/config/remove.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func initRemoveCommand() *cobra.Command {
3636
Args: cobra.MinimumNArgs(2),
3737
Run: runRemoveCommand,
3838
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
39-
return GetConfigurationKeys(toComplete), cobra.ShellCompDirectiveDefault
39+
return GetConfigurationKeys(), cobra.ShellCompDirectiveDefault
4040
},
4141
}
4242
return addCommand

Diff for: cli/core/download.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func initDownloadCommand() *cobra.Command {
4242
Args: cobra.MinimumNArgs(1),
4343
Run: runDownloadCommand,
4444
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
45-
return arguments.GetInstallableCores(toComplete), cobra.ShellCompDirectiveDefault
45+
return arguments.GetInstallableCores(), cobra.ShellCompDirectiveDefault
4646
},
4747
}
4848
return downloadCommand

Diff for: cli/core/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func initInstallCommand() *cobra.Command {
4444
Args: cobra.MinimumNArgs(1),
4545
Run: runInstallCommand,
4646
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
47-
return arguments.GetInstallableCores(toComplete), cobra.ShellCompDirectiveDefault
47+
return arguments.GetInstallableCores(), cobra.ShellCompDirectiveDefault
4848
},
4949
}
5050
AddPostInstallFlagsToCommand(installCommand)

Diff for: cli/core/uninstall.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func initUninstallCommand() *cobra.Command {
4040
Args: cobra.MinimumNArgs(1),
4141
Run: runUninstallCommand,
4242
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
43-
return arguments.GetUninstallableCores(toComplete), cobra.ShellCompDirectiveDefault
43+
return arguments.GetUninstallableCores(), cobra.ShellCompDirectiveDefault
4444
},
4545
}
4646
}

Diff for: cli/debug/debug.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ func NewCommand() *cobra.Command {
6060

6161
debugCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
6262
debugCommand.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
63-
return arguments.GetInstalledBoards(toComplete), cobra.ShellCompDirectiveDefault
63+
return arguments.GetInstalledBoards(), cobra.ShellCompDirectiveDefault
6464
})
6565
port.AddToCommand(debugCommand)
6666
debugCommand.Flags().StringVarP(&programmer, "programmer", "P", "", tr("Programmer to use for debugging"))
6767
debugCommand.RegisterFlagCompletionFunc("programmer", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
68-
return arguments.GetInstalledProgrammers(toComplete), cobra.ShellCompDirectiveDefault
68+
return arguments.GetInstalledProgrammers(), cobra.ShellCompDirectiveDefault
6969
})
7070
debugCommand.Flags().StringVar(&interpreter, "interpreter", "console", tr("Debug interpreter e.g.: %s", "console, mi, mi1, mi2, mi3"))
7171
debugCommand.Flags().StringVarP(&importDir, "input-dir", "", "", tr("Directory containing binaries for debug."))

Diff for: cli/lib/check_deps.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func initDepsCommand() *cobra.Command {
4141
Args: cobra.ExactArgs(1),
4242
Run: runDepsCommand,
4343
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
44-
return arguments.GetUninstallableLibs(toComplete), cobra.ShellCompDirectiveDefault
44+
return arguments.GetUninstallableLibs(), cobra.ShellCompDirectiveDefault
4545
},
4646
}
4747
return depsCommand

Diff for: cli/lib/download.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func initDownloadCommand() *cobra.Command {
4141
Args: cobra.MinimumNArgs(1),
4242
Run: runDownloadCommand,
4343
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
44-
return arguments.GetInstallableLibs(toComplete), cobra.ShellCompDirectiveDefault
44+
return arguments.GetInstallableLibs(), cobra.ShellCompDirectiveDefault
4545
},
4646
}
4747
return downloadCommand

Diff for: cli/lib/examples.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ func initExamplesCommand() *cobra.Command {
4343
Args: cobra.MaximumNArgs(1),
4444
Run: runExamplesCommand,
4545
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
46-
return arguments.GetUninstallableLibs(toComplete), cobra.ShellCompDirectiveDefault
46+
return arguments.GetUninstallableLibs(), cobra.ShellCompDirectiveDefault
4747
},
4848
}
4949
examplesCommand.Flags().StringVarP(&examplesFlags.fqbn, "fqbn", "b", "", tr("Show libraries for the specified board FQBN."))
5050
examplesCommand.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
51-
return arguments.GetInstalledBoards(toComplete), cobra.ShellCompDirectiveDefault
51+
return arguments.GetInstalledBoards(), cobra.ShellCompDirectiveDefault
5252
})
5353
return examplesCommand
5454
}

Diff for: cli/lib/install.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func initInstallCommand() *cobra.Command {
4848
Args: cobra.MinimumNArgs(1),
4949
Run: runInstallCommand,
5050
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
51-
return arguments.GetInstallableLibs(toComplete), cobra.ShellCompDirectiveDefault
51+
return arguments.GetInstallableLibs(), cobra.ShellCompDirectiveDefault
5252
},
5353
}
5454
installCommand.Flags().BoolVar(&installFlags.noDeps, "no-deps", false, tr("Do not install dependencies."))

Diff for: cli/lib/uninstall.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func initUninstallCommand() *cobra.Command {
4040
Args: cobra.MinimumNArgs(1),
4141
Run: runUninstallCommand,
4242
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
43-
return arguments.GetUninstallableLibs(toComplete), cobra.ShellCompDirectiveDefault
43+
return arguments.GetUninstallableLibs(), cobra.ShellCompDirectiveDefault
4444
},
4545
}
4646
return uninstallCommand

Diff for: cli/upload/upload.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func NewCommand() *cobra.Command {
5656

5757
uploadCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", tr("Fully Qualified Board Name, e.g.: arduino:avr:uno"))
5858
uploadCommand.RegisterFlagCompletionFunc("fqbn", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
59-
return arguments.GetInstalledBoards(toComplete), cobra.ShellCompDirectiveDefault
59+
return arguments.GetInstalledBoards(), cobra.ShellCompDirectiveDefault
6060
})
6161
port.AddToCommand(uploadCommand)
6262
uploadCommand.Flags().StringVarP(&importDir, "input-dir", "", "", tr("Directory containing binaries to upload."))
@@ -65,7 +65,7 @@ func NewCommand() *cobra.Command {
6565
uploadCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, tr("Optional, turns on verbose mode."))
6666
uploadCommand.Flags().StringVarP(&programmer, "programmer", "P", "", tr("Optional, use the specified programmer to upload."))
6767
uploadCommand.RegisterFlagCompletionFunc("programmer", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
68-
return arguments.GetInstalledProgrammers(toComplete), cobra.ShellCompDirectiveDefault
68+
return arguments.GetInstalledProgrammers(), cobra.ShellCompDirectiveDefault
6969
})
7070
uploadCommand.Flags().BoolVar(&dryRun, "dry-run", false, tr("Do not perform the actual upload, just log out actions"))
7171
uploadCommand.Flags().MarkHidden("dry-run")

0 commit comments

Comments
 (0)