MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / completeClusters

Function completeClusters

internal/cmd/plugin/plugin.go:175–206  ·  view source on GitHub ↗

completeClusters is mainly used inside the unit tests

(
	ctx context.Context,
	cli client.Client,
	namespace string,
	args []string,
	toComplete string,
)

Source from the content-addressed store, hash-verified

173
174// completeClusters is mainly used inside the unit tests
175func completeClusters(
176 ctx context.Context,
177 cli client.Client,
178 namespace string,
179 args []string,
180 toComplete string,
181) []string {
182 var clusters apiv1.ClusterList
183
184 // Since all our commands work on one cluster, if we already have one in the list
185 // we just return an empty set of strings
186 if len(args) == 1 {
187 return []string{}
188 }
189
190 // Get the cluster lists object if error we just return empty array string
191 if err := cli.List(ctx, &clusters, client.InNamespace(namespace)); err != nil {
192 // We can't list the clusters, so we cannot provide any completion.
193 // Unfortunately there's no way for us to provide an error message
194 // notifying the user of what is happening.
195 return []string{}
196 }
197
198 clustersNames := make([]string, 0, len(clusters.Items))
199 for _, cluster := range clusters.Items {
200 if len(toComplete) == 0 || strings.HasPrefix(cluster.Name, toComplete) {
201 clustersNames = append(clustersNames, cluster.Name)
202 }
203 }
204
205 return clustersNames
206}
207
208// CompleteClusters will complete the cluster name when necessary getting the list from the current namespace
209func CompleteClusters(ctx context.Context, args []string, toComplete string) []string {

Callers 2

plugin_test.goFile · 0.85
CompleteClustersFunction · 0.85

Calls 1

ListMethod · 0.45

Tested by

no test coverage detected