|
6 | 6 | "os" |
7 | 7 |
|
8 | 8 | "github.com/AlecAivazis/survey/v2/terminal" |
| 9 | + "github.com/redhat-developer/app-services-cli/pkg/cloudprovider/cloudproviderutil" |
9 | 10 | "github.com/redhat-developer/app-services-cli/pkg/cmd/factory" |
10 | 11 | "github.com/redhat-developer/app-services-cli/pkg/connection" |
11 | 12 | "github.com/spf13/cobra" |
@@ -106,7 +107,7 @@ func FilterValidConsumerGroupIDs(f *factory.Factory, toComplete string) (validID |
106 | 107 | } |
107 | 108 |
|
108 | 109 | // FilterValidKafkaNames filters Kafkas by name from the API and returns the names |
109 | | -// This is used in the cobra.ValidArgsFunction for dynamic completion of topic names |
| 110 | +// This is used in the cobra.ValidArgsFunction for dynamic completion of Kafka instance names |
110 | 111 | func FilterValidKafkas(f *factory.Factory, toComplete string) (validNames []string, directive cobra.ShellCompDirective) { |
111 | 112 | validNames = []string{} |
112 | 113 | directive = cobra.ShellCompDirectiveNoSpace |
@@ -134,3 +135,25 @@ func FilterValidKafkas(f *factory.Factory, toComplete string) (validNames []stri |
134 | 135 |
|
135 | 136 | return validNames, directive |
136 | 137 | } |
| 138 | + |
| 139 | +// FetchCloudProviders returns the list of supported cloud providers for creating a Kafka instance |
| 140 | +// This is used in the cmd.RegisterFlagCompletionFunc for dynamic completion of --provider |
| 141 | +func FetchCloudProviders(f *factory.Factory) (validProviders []string, directive cobra.ShellCompDirective) { |
| 142 | + validProviders = []string{} |
| 143 | + directive = cobra.ShellCompDirectiveNoSpace |
| 144 | + |
| 145 | + conn, err := f.Connection(connection.DefaultConfigSkipMasAuth) |
| 146 | + if err != nil { |
| 147 | + return validProviders, directive |
| 148 | + } |
| 149 | + |
| 150 | + cloudProviderResponse, _, err := conn.API().Kafka().GetCloudProviders(context.Background()).Execute() |
| 151 | + if err != nil { |
| 152 | + return validProviders, directive |
| 153 | + } |
| 154 | + |
| 155 | + cloudProviders := cloudProviderResponse.GetItems() |
| 156 | + validProviders = cloudproviderutil.GetEnabledNames(cloudProviders) |
| 157 | + |
| 158 | + return validProviders, directive |
| 159 | +} |
0 commit comments