Skip to content

Commit 5ff678f

Browse files
committed
add completion for core install and core download
1 parent 5db5f48 commit 5ff678f

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

cli/arguments/completion.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,21 @@ func GetUninstallableCores(toComplete string) []string {
107107
}
108108
return res
109109
}
110+
111+
// GetInstallableCores is an helper function useful to autocomplete.
112+
// It returns a list of cores which can be installed/downloaded
113+
func GetInstallableCores(toComplete string) []string {
114+
inst := instance.CreateAndInit() // TODO optimize this: it does not make sense to create an instance everytime
115+
116+
platforms, _ := core.PlatformSearch(&rpc.PlatformSearchRequest{
117+
Instance: inst,
118+
SearchArgs: "",
119+
AllVersions: false,
120+
})
121+
var res []string
122+
// transform the data structure for the completion
123+
for _, i := range platforms.SearchOutput {
124+
res = append(res, i.GetId())
125+
}
126+
return res
127+
}

cli/core/download.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ func initDownloadCommand() *cobra.Command {
4141
" " + os.Args[0] + " core download arduino:samd@1.6.9 # " + tr("download a specific version (in this case 1.6.9)."),
4242
Args: cobra.MinimumNArgs(1),
4343
Run: runDownloadCommand,
44+
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
45+
return arguments.GetInstallableCores(toComplete), cobra.ShellCompDirectiveDefault
46+
},
4447
}
4548
return downloadCommand
4649
}

cli/core/install.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ func initInstallCommand() *cobra.Command {
4343
" " + os.Args[0] + " core install arduino:samd@1.6.9",
4444
Args: cobra.MinimumNArgs(1),
4545
Run: runInstallCommand,
46+
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
47+
return arguments.GetInstallableCores(toComplete), cobra.ShellCompDirectiveDefault
48+
},
4649
}
4750
AddPostInstallFlagsToCommand(installCommand)
4851
return installCommand

i18n/data/en.po

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ msgstr "Error creating sketch: %v"
653653
msgid "Error detecting boards: %v"
654654
msgstr "Error detecting boards: %v"
655655

656-
#: cli/core/download.go:68
656+
#: cli/core/download.go:71
657657
#: cli/lib/download.go:62
658658
msgid "Error downloading %[1]s: %[2]v"
659659
msgstr "Error downloading %[1]s: %[2]v"
@@ -725,7 +725,7 @@ msgstr "Error during Upload: %v"
725725
msgid "Error during build: %v"
726726
msgstr "Error during build: %v"
727727

728-
#: cli/core/install.go:106
728+
#: cli/core/install.go:109
729729
msgid "Error during install: %v"
730730
msgstr "Error during install: %v"
731731

@@ -1063,11 +1063,11 @@ msgstr "First message must contain debug request, not data"
10631063
msgid "Flags:"
10641064
msgstr "Flags:"
10651065

1066-
#: cli/core/install.go:59
1066+
#: cli/core/install.go:62
10671067
msgid "Force run of post-install scripts (if the CLI is not running interactively)."
10681068
msgstr "Force run of post-install scripts (if the CLI is not running interactively)."
10691069

1070-
#: cli/core/install.go:60
1070+
#: cli/core/install.go:63
10711071
msgid "Force skip of post-install scripts (if the CLI is running interactively)."
10721072
msgstr "Force skip of post-install scripts (if the CLI is running interactively)."
10731073

@@ -1216,8 +1216,8 @@ msgstr "Invalid URL"
12161216
msgid "Invalid additional URL: %v"
12171217
msgstr "Invalid additional URL: %v"
12181218

1219-
#: cli/core/download.go:55
1220-
#: cli/core/install.go:92
1219+
#: cli/core/download.go:58
1220+
#: cli/core/install.go:95
12211221
#: cli/core/uninstall.go:54
12221222
#: cli/core/upgrade.go:81
12231223
#: cli/lib/download.go:50
@@ -1984,7 +1984,7 @@ msgstr "The connected devices search timeout, raise it if your board doesn't sho
19841984
msgid "The custom config file (if not specified the default will be used)."
19851985
msgstr "The custom config file (if not specified the default will be used)."
19861986

1987-
#: cli/core/install.go:66
1987+
#: cli/core/install.go:69
19881988
msgid "The flags --run-post-install and --skip-post-install can't be both set at the same time."
19891989
msgstr "The flags --run-post-install and --skip-post-install can't be both set at the same time."
19901990

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)