fix: template flag completion (#1670)

Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
Matej Vasek 2023-04-07 20:25:20 +02:00 committed by GitHub
parent 29cfd3e6ba
commit 18d8398ac2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 9 deletions

View File

@ -45,19 +45,31 @@ func CompleteRuntimeList(cmd *cobra.Command, args []string, toComplete string, c
}
func CompleteTemplateList(cmd *cobra.Command, args []string, toComplete string, client *fn.Client) (matches []string, directive cobra.ShellCompDirective) {
repositories, err := client.Repositories().All()
directive = cobra.ShellCompDirectiveError
lang, err := cmd.Flags().GetString("language")
if err != nil {
fmt.Fprintf(os.Stderr, "error listing repositories for use in template flag completion: %v", err)
fmt.Fprintf(os.Stderr, "cannot list templates: %v", err)
return
}
for _, repository := range repositories {
templates, err := client.Templates().List(repository.Name)
if err != nil {
fmt.Fprintf(os.Stderr, "error listing template for use in template flag completion: %v", err)
if lang == "" {
fmt.Fprintln(os.Stderr, "cannot list templates: language not specified")
return
}
matches = append(matches, templates...)
templates, err := client.Templates().List(lang)
if err != nil {
fmt.Fprintf(os.Stderr, "cannot list templates: %v", err)
return
}
directive = cobra.ShellCompDirectiveDefault
for _, t := range templates {
if strings.HasPrefix(t, toComplete) {
matches = append(matches, t)
}
}
return
}