mirror of https://github.com/kubernetes/kops.git
Implement completion for "kops get instances"
This commit is contained in:
parent
337377c163
commit
1e4dee452e
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"k8s.io/kops/pkg/cloudinstances"
|
"k8s.io/kops/pkg/cloudinstances"
|
||||||
|
"k8s.io/kops/pkg/commands/commandutils"
|
||||||
"k8s.io/kubectl/pkg/util/i18n"
|
"k8s.io/kubectl/pkg/util/i18n"
|
||||||
"k8s.io/kubectl/pkg/util/templates"
|
"k8s.io/kubectl/pkg/util/templates"
|
||||||
|
|
||||||
|
|
@ -43,33 +44,24 @@ import (
|
||||||
"k8s.io/kops/upup/pkg/fi/cloudup"
|
"k8s.io/kops/upup/pkg/fi/cloudup"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewCmdGetInstances(f *util.Factory, out io.Writer, options *GetOptions) *cobra.Command {
|
var (
|
||||||
getInstancesShort := i18n.T(`Display cluster instances.`)
|
getInstancesExample = templates.Examples(i18n.T(`
|
||||||
|
|
||||||
getInstancesLong := templates.LongDesc(i18n.T(`
|
|
||||||
Display cluster instances.`))
|
|
||||||
|
|
||||||
getInstancesExample := templates.Examples(i18n.T(`
|
|
||||||
# Display all instances.
|
# Display all instances.
|
||||||
kops get instances
|
kops get instances
|
||||||
`))
|
`))
|
||||||
|
|
||||||
|
getInstancesShort = i18n.T(`Display cluster instances.`)
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewCmdGetInstances(f *util.Factory, out io.Writer, options *GetOptions) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "instances",
|
Use: "instances [CLUSTER]",
|
||||||
Short: getInstancesShort,
|
Short: getInstancesShort,
|
||||||
Long: getInstancesLong,
|
|
||||||
Example: getInstancesExample,
|
Example: getInstancesExample,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Args: rootCommand.clusterNameArgs(&options.ClusterName),
|
||||||
ctx := context.TODO()
|
ValidArgsFunction: commandutils.CompleteClusterName(&rootCommand, true, false),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if err := rootCommand.ProcessArgs(args); err != nil {
|
return RunGetInstances(context.TODO(), f, out, options)
|
||||||
exitWithError(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
err := RunGetInstances(ctx, f, out, options)
|
|
||||||
if err != nil {
|
|
||||||
exitWithError(err)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,18 +69,11 @@ func NewCmdGetInstances(f *util.Factory, out io.Writer, options *GetOptions) *co
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunGetInstances(ctx context.Context, f *util.Factory, out io.Writer, options *GetOptions) error {
|
func RunGetInstances(ctx context.Context, f *util.Factory, out io.Writer, options *GetOptions) error {
|
||||||
|
|
||||||
clientset, err := f.Clientset()
|
clientset, err := f.Clientset()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
clusterName := rootCommand.ClusterName(true)
|
|
||||||
options.ClusterName = clusterName
|
|
||||||
if clusterName == "" {
|
|
||||||
return fmt.Errorf("--name is required")
|
|
||||||
}
|
|
||||||
|
|
||||||
cluster, err := clientset.GetCluster(ctx, options.ClusterName)
|
cluster, err := clientset.GetCluster(ctx, options.ClusterName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,8 @@
|
||||||
|
|
||||||
Display cluster instances.
|
Display cluster instances.
|
||||||
|
|
||||||
### Synopsis
|
|
||||||
|
|
||||||
Display cluster instances.
|
|
||||||
|
|
||||||
```
|
```
|
||||||
kops get instances [flags]
|
kops get instances [CLUSTER] [flags]
|
||||||
```
|
```
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue