Fix completion of instancegroups when cluster argument provided

This commit is contained in:
John Gardiner Myers 2021-07-05 21:13:35 -07:00
parent 13bfa283cf
commit dbf4f23654
6 changed files with 11 additions and 7 deletions

View File

@ -270,7 +270,7 @@ func completeCreateKeyset(options *CreateKeypairOptions, args []string, toComple
commandutils.ConfigureKlogForCompletion()
ctx := context.TODO()
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, &rootCommand, "")
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, &rootCommand, nil)
if cluster == nil {
return completions, directive
}

View File

@ -161,7 +161,7 @@ func completeDistrustKeyset(options *DistrustKeypairOptions, args []string, toCo
commandutils.ConfigureKlogForCompletion()
ctx := context.TODO()
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, &rootCommand, "")
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, &rootCommand, nil)
if cluster == nil {
return completions, directive
}

View File

@ -197,7 +197,7 @@ func completeGetKeypairs(options *GetKeypairsOptions, args []string, toComplete
commandutils.ConfigureKlogForCompletion()
ctx := context.TODO()
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, &rootCommand, "")
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, &rootCommand, nil)
if cluster == nil {
return completions, directive
}

View File

@ -167,7 +167,7 @@ func completePromoteKeyset(options *PromoteKeypairOptions, args []string, toComp
commandutils.ConfigureKlogForCompletion()
ctx := context.TODO()
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, &rootCommand, "")
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, &rootCommand, nil)
if cluster == nil {
return completions, directive
}

View File

@ -434,7 +434,7 @@ func completeInstanceGroup(options *RollingUpdateOptions) func(cmd *cobra.Comman
commandutils.ConfigureKlogForCompletion()
ctx := context.TODO()
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, &rootCommand, options.ClusterName)
cluster, clientSet, completions, directive := GetClusterForCompletion(ctx, &rootCommand, args)
if cluster == nil {
return completions, directive
}

View File

@ -317,8 +317,12 @@ func GetCluster(ctx context.Context, factory commandutils.Factory, clusterName s
return cluster, nil
}
func GetClusterForCompletion(ctx context.Context, factory commandutils.Factory, clusterName string) (cluster *kopsapi.Cluster, clientSet simple.Clientset, completions []string, directive cobra.ShellCompDirective) {
if clusterName == "" {
func GetClusterForCompletion(ctx context.Context, factory commandutils.Factory, clusterArgs []string) (cluster *kopsapi.Cluster, clientSet simple.Clientset, completions []string, directive cobra.ShellCompDirective) {
clusterName := ""
if len(clusterArgs) > 0 {
clusterName = clusterArgs[0]
} else {
clusterName = rootCommand.ClusterName(false)
}