Skip to content

Commit 3e2de29

Browse files
committed
enhance the completion for config add and config remove
1 parent 61c1a9f commit 3e2de29

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

cli/config/add.go

Lines changed: 1 addition & 1 deletion
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 configuration.Settings.AllKeys(), cobra.ShellCompDirectiveDefault
39+
return GetConfigurationKeys(toComplete), cobra.ShellCompDirectiveDefault
4040
},
4141
}
4242
return addCommand

cli/config/config.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ package config
1717

1818
import (
1919
"os"
20+
"reflect"
2021

22+
"github.com/arduino/arduino-cli/configuration"
2123
"github.com/arduino/arduino-cli/i18n"
2224
"github.com/spf13/cobra"
2325
)
@@ -41,3 +43,17 @@ func NewCommand() *cobra.Command {
4143

4244
return configCommand
4345
}
46+
47+
// GetConfigurationKeys is an helper function useful to autocomplete.
48+
// It returns a list of configuration keys which can be changed
49+
func GetConfigurationKeys(toComplete string) []string {
50+
var res []string
51+
keys := configuration.Settings.AllKeys()
52+
for _, key := range keys {
53+
kind, _ := typeOf(key)
54+
if kind == reflect.Slice {
55+
res = append(res, key)
56+
}
57+
}
58+
return res
59+
}

cli/config/remove.go

Lines changed: 1 addition & 1 deletion
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 configuration.Settings.AllKeys(), cobra.ShellCompDirectiveDefault
39+
return GetConfigurationKeys(toComplete), cobra.ShellCompDirectiveDefault
4040
},
4141
}
4242
return addCommand

i18n/data/en.po

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ msgstr "Arduino cache commands."
176176
msgid "Arduino commands about libraries."
177177
msgstr "Arduino commands about libraries."
178178

179-
#: cli/config/config.go:31
179+
#: cli/config/config.go:33
180180
msgid "Arduino configuration commands."
181181
msgstr "Arduino configuration commands."
182182

i18n/rice-box.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)