mirror of https://github.com/kubernetes/kops.git
Add shell completion for `--target`
This commit is contained in:
parent
ce0d8955ef
commit
5b62e73726
|
|
@ -207,7 +207,7 @@ func NewCmdCreateCluster(f *util.Factory, out io.Writer) *cobra.Command {
|
||||||
|
|
||||||
cmd.Flags().BoolVarP(&options.Yes, "yes", "y", options.Yes, "Specify --yes to immediately create the cluster")
|
cmd.Flags().BoolVarP(&options.Yes, "yes", "y", options.Yes, "Specify --yes to immediately create the cluster")
|
||||||
cmd.Flags().StringVar(&options.Target, "target", options.Target, fmt.Sprintf("Valid targets: %s, %s, %s. Set this flag to %s if you want kOps to generate terraform", cloudup.TargetDirect, cloudup.TargetTerraform, cloudup.TargetCloudformation, cloudup.TargetTerraform))
|
cmd.Flags().StringVar(&options.Target, "target", options.Target, fmt.Sprintf("Valid targets: %s, %s, %s. Set this flag to %s if you want kOps to generate terraform", cloudup.TargetDirect, cloudup.TargetTerraform, cloudup.TargetCloudformation, cloudup.TargetTerraform))
|
||||||
cmd.RegisterFlagCompletionFunc("target", completeTarget)
|
cmd.RegisterFlagCompletionFunc("target", completeCreateClusterTarget(options))
|
||||||
|
|
||||||
// Configuration / state location
|
// Configuration / state location
|
||||||
if featureflag.EnableSeparateConfigBase.Enabled() {
|
if featureflag.EnableSeparateConfigBase.Enabled() {
|
||||||
|
|
@ -937,6 +937,24 @@ func completeNetworking(options *CreateClusterOptions) func(cmd *cobra.Command,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func completeCreateClusterTarget(options *CreateClusterOptions) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
completions := []string{
|
||||||
|
cloudup.TargetDirect,
|
||||||
|
cloudup.TargetDryRun,
|
||||||
|
}
|
||||||
|
for _, cp := range cloudup.TerraformCloudProviders {
|
||||||
|
if options.CloudProvider == string(cp) {
|
||||||
|
completions = append(completions, cloudup.TargetTerraform)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if options.CloudProvider == string(api.CloudProviderAWS) {
|
||||||
|
completions = append(completions, cloudup.TargetCloudformation)
|
||||||
|
}
|
||||||
|
return completions, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func completeDNSZone(options *CreateClusterOptions) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
func completeDNSZone(options *CreateClusterOptions) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
commandutils.ConfigureKlogForCompletion()
|
commandutils.ConfigureKlogForCompletion()
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ func NewCmdUpdateCluster(f *util.Factory, out io.Writer) *cobra.Command {
|
||||||
|
|
||||||
cmd.Flags().BoolVarP(&options.Yes, "yes", "y", options.Yes, "Create cloud resources, without --yes update is in dry run mode")
|
cmd.Flags().BoolVarP(&options.Yes, "yes", "y", options.Yes, "Create cloud resources, without --yes update is in dry run mode")
|
||||||
cmd.Flags().StringVar(&options.Target, "target", options.Target, "Target - direct, terraform, cloudformation")
|
cmd.Flags().StringVar(&options.Target, "target", options.Target, "Target - direct, terraform, cloudformation")
|
||||||
cmd.RegisterFlagCompletionFunc("target", completeTarget)
|
cmd.RegisterFlagCompletionFunc("target", completeUpdateClusterTarget(options))
|
||||||
cmd.Flags().StringVar(&options.SSHPublicKey, "ssh-public-key", options.SSHPublicKey, "SSH public key to use (deprecated: use kops create secret instead)")
|
cmd.Flags().StringVar(&options.SSHPublicKey, "ssh-public-key", options.SSHPublicKey, "SSH public key to use (deprecated: use kops create secret instead)")
|
||||||
cmd.Flags().StringVar(&options.OutDir, "out", options.OutDir, "Path to write any local output")
|
cmd.Flags().StringVar(&options.OutDir, "out", options.OutDir, "Path to write any local output")
|
||||||
cmd.MarkFlagDirname("out")
|
cmd.MarkFlagDirname("out")
|
||||||
|
|
@ -468,8 +468,36 @@ func hasKubecfg(contextName string) (bool, error) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func completeTarget(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
func completeUpdateClusterTarget(options *UpdateClusterOptions) func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
return []string{cloudup.TargetDirect, cloudup.TargetDryRun, cloudup.TargetTerraform, cloudup.TargetCloudformation}, cobra.ShellCompDirectiveNoFileComp
|
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
|
||||||
|
commandutils.ConfigureKlogForCompletion()
|
||||||
|
ctx := context.TODO()
|
||||||
|
|
||||||
|
cluster, _, _, directive := GetClusterForCompletion(ctx, &rootCommand, nil)
|
||||||
|
if cluster == nil {
|
||||||
|
return []string{
|
||||||
|
cloudup.TargetDirect,
|
||||||
|
cloudup.TargetDryRun,
|
||||||
|
cloudup.TargetCloudformation,
|
||||||
|
cloudup.TargetTerraform,
|
||||||
|
}, directive
|
||||||
|
}
|
||||||
|
|
||||||
|
completions := []string{
|
||||||
|
cloudup.TargetDirect,
|
||||||
|
cloudup.TargetDryRun,
|
||||||
|
}
|
||||||
|
for _, cp := range cloudup.TerraformCloudProviders {
|
||||||
|
if cluster.Spec.CloudProvider == string(cp) {
|
||||||
|
completions = append(completions, cloudup.TargetTerraform)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if cluster.Spec.CloudProvider == string(kops.CloudProviderAWS) {
|
||||||
|
completions = append(completions, cloudup.TargetCloudformation)
|
||||||
|
}
|
||||||
|
return completions, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func completeLifecycleOverrides(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
func completeLifecycleOverrides(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
|
|
||||||
|
|
@ -83,6 +83,9 @@ const (
|
||||||
OldestSupportedKubernetesVersion = "1.17.0"
|
OldestSupportedKubernetesVersion = "1.17.0"
|
||||||
// OldestRecommendedKubernetesVersion is the oldest kubernetes version that is not deprecated in kOps.
|
// OldestRecommendedKubernetesVersion is the oldest kubernetes version that is not deprecated in kOps.
|
||||||
OldestRecommendedKubernetesVersion = "1.19.0"
|
OldestRecommendedKubernetesVersion = "1.19.0"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
// TerraformCloudProviders is the list of cloud providers with terraform target support
|
// TerraformCloudProviders is the list of cloud providers with terraform target support
|
||||||
TerraformCloudProviders = []kops.CloudProviderID{kops.CloudProviderAWS, kops.CloudProviderGCE, kops.CloudProviderALI}
|
TerraformCloudProviders = []kops.CloudProviderID{kops.CloudProviderAWS, kops.CloudProviderGCE, kops.CloudProviderALI}
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue