Update bashcompletion codes for kubectl annotate

This commit is contained in:
Kenjiro Nakayama 2016-04-03 19:13:51 +09:00
parent 910b6bce33
commit 84e3ee8ec4
5 changed files with 70 additions and 15 deletions

View File

@ -313,7 +313,8 @@ __kubectl_require_pod_and_container()
__custom_func() { __custom_func() {
case ${last_command} in case ${last_command} in
kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop | kubectl_edit | kubectl_patch) kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop | kubectl_edit | kubectl_patch |\
kubectl_annotate)
__kubectl_get_resource __kubectl_get_resource
return return
;; ;;
@ -2782,7 +2783,42 @@ _kubectl_annotate()
must_have_one_flag=() must_have_one_flag=()
must_have_one_noun=() must_have_one_noun=()
must_have_one_noun+=("componentstatuse")
must_have_one_noun+=("event")
must_have_one_noun+=("horizontalpodautoscaler")
must_have_one_noun+=("limitrange")
must_have_one_noun+=("node")
must_have_one_noun+=("persistentvolume")
must_have_one_noun+=("persistentvolumeclaim")
must_have_one_noun+=("pod")
must_have_one_noun+=("replicationcontroller")
must_have_one_noun+=("resourcequota")
must_have_one_noun+=("secret")
must_have_one_noun+=("service")
noun_aliases=() noun_aliases=()
noun_aliases+=("componentstatuses")
noun_aliases+=("cs")
noun_aliases+=("ev")
noun_aliases+=("events")
noun_aliases+=("horizontalpodautoscalers")
noun_aliases+=("hpa")
noun_aliases+=("limitranges")
noun_aliases+=("limits")
noun_aliases+=("no")
noun_aliases+=("nodes")
noun_aliases+=("persistentvolumeclaims")
noun_aliases+=("persistentvolumes")
noun_aliases+=("po")
noun_aliases+=("pods")
noun_aliases+=("pv")
noun_aliases+=("pvc")
noun_aliases+=("quota")
noun_aliases+=("rc")
noun_aliases+=("replicationcontrollers")
noun_aliases+=("resourcequotas")
noun_aliases+=("secrets")
noun_aliases+=("services")
noun_aliases+=("svc")
} }
_kubectl_config_view() _kubectl_config_view()

View File

@ -22,10 +22,11 @@ If \-\-overwrite is true, then existing annotations can be overwritten, otherwis
If \-\-resource\-version is specified, then updates will use this resource version, otherwise the existing resource\-version will be used. If \-\-resource\-version is specified, then updates will use this resource version, otherwise the existing resource\-version will be used.
.PP .PP
Possible resources include (case insensitive): pods (po), services (svc), Possible resources include (case insensitive):
replicationcontrollers (rc), nodes (no), events (ev), componentstatuses (cs), pod (po), service (svc), replicationcontroller (rc),
limitranges (limits), persistentvolumes (pv), persistentvolumeclaims (pvc), node (no), event (ev), componentstatuse (cs),
horizontalpodautoscalers (hpa), resourcequotas (quota) or secrets. limitrange (limits), persistentvolume (pv), persistentvolumeclaim (pvc),
horizontalpodautoscaler (hpa), resourcequota (quota), secret
.SH OPTIONS .SH OPTIONS

View File

@ -46,10 +46,12 @@ It is intended to store non-identifying auxiliary data, especially data manipula
If --overwrite is true, then existing annotations can be overwritten, otherwise attempting to overwrite an annotation will result in an error. If --overwrite is true, then existing annotations can be overwritten, otherwise attempting to overwrite an annotation will result in an error.
If --resource-version is specified, then updates will use this resource version, otherwise the existing resource-version will be used. If --resource-version is specified, then updates will use this resource version, otherwise the existing resource-version will be used.
Possible resources include (case insensitive): pods (po), services (svc), Possible resources include (case insensitive):
replicationcontrollers (rc), nodes (no), events (ev), componentstatuses (cs), pod (po), service (svc), replicationcontroller (rc),
limitranges (limits), persistentvolumes (pv), persistentvolumeclaims (pvc), node (no), event (ev), componentstatuse (cs),
horizontalpodautoscalers (hpa), resourcequotas (quota) or secrets. limitrange (limits), persistentvolume (pv), persistentvolumeclaim (pvc),
horizontalpodautoscaler (hpa), resourcequota (quota), secret
``` ```
kubectl annotate [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version] kubectl annotate [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]
@ -130,7 +132,7 @@ kubectl annotate pods foo description-
* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager * [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager
###### Auto generated by spf13/cobra on 30-Mar-2016 ###### Auto generated by spf13/cobra on 10-Apr-2016
<!-- BEGIN MUNGE: GENERATED_ANALYTICS --> <!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_annotate.md?pixel)]() [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_annotate.md?pixel)]()

View File

@ -21,6 +21,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"regexp"
"strings" "strings"
"github.com/golang/glog" "github.com/golang/glog"
@ -58,6 +59,13 @@ type AnnotateOptions struct {
} }
const ( const (
annotate_resources = `
pod (po), service (svc), replicationcontroller (rc),
node (no), event (ev), componentstatuse (cs),
limitrange (limits), persistentvolume (pv), persistentvolumeclaim (pvc),
horizontalpodautoscaler (hpa), resourcequota (quota), secret
`
annotate_long = `Update the annotations on one or more resources. annotate_long = `Update the annotations on one or more resources.
An annotation is a key/value pair that can hold larger (compared to a label), and possibly not human-readable, data. An annotation is a key/value pair that can hold larger (compared to a label), and possibly not human-readable, data.
@ -65,10 +73,8 @@ It is intended to store non-identifying auxiliary data, especially data manipula
If --overwrite is true, then existing annotations can be overwritten, otherwise attempting to overwrite an annotation will result in an error. If --overwrite is true, then existing annotations can be overwritten, otherwise attempting to overwrite an annotation will result in an error.
If --resource-version is specified, then updates will use this resource version, otherwise the existing resource-version will be used. If --resource-version is specified, then updates will use this resource version, otherwise the existing resource-version will be used.
Possible resources include (case insensitive): pods (po), services (svc), Possible resources include (case insensitive):` + annotate_resources
replicationcontrollers (rc), nodes (no), events (ev), componentstatuses (cs),
limitranges (limits), persistentvolumes (pv), persistentvolumeclaims (pvc),
horizontalpodautoscalers (hpa), resourcequotas (quota) or secrets.`
annotate_example = `# Update pod 'foo' with the annotation 'description' and the value 'my frontend'. annotate_example = `# Update pod 'foo' with the annotation 'description' and the value 'my frontend'.
# If the same annotation is set multiple times, only the last value will be applied # If the same annotation is set multiple times, only the last value will be applied
kubectl annotate pods foo description='my frontend' kubectl annotate pods foo description='my frontend'
@ -93,6 +99,13 @@ kubectl annotate pods foo description-`
func NewCmdAnnotate(f *cmdutil.Factory, out io.Writer) *cobra.Command { func NewCmdAnnotate(f *cmdutil.Factory, out io.Writer) *cobra.Command {
options := &AnnotateOptions{} options := &AnnotateOptions{}
validArgs, argAliases := []string{}, []string{}
resources := regexp.MustCompile(`\s*,`).Split(annotate_resources, -1)
for _, r := range resources {
validArgs = append(validArgs, strings.Fields(r)[0])
argAliases = kubectl.ResourceAliases(validArgs)
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "annotate [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]", Use: "annotate [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]",
Short: "Update the annotations on a resource", Short: "Update the annotations on a resource",
@ -109,6 +122,8 @@ func NewCmdAnnotate(f *cmdutil.Factory, out io.Writer) *cobra.Command {
cmdutil.CheckErr(err) cmdutil.CheckErr(err)
} }
}, },
ValidArgs: validArgs,
ArgAliases: argAliases,
} }
cmdutil.AddPrinterFlags(cmd) cmdutil.AddPrinterFlags(cmd)
cmdutil.AddInclude3rdPartyFlags(cmd) cmdutil.AddInclude3rdPartyFlags(cmd)

View File

@ -124,7 +124,8 @@ __kubectl_require_pod_and_container()
__custom_func() { __custom_func() {
case ${last_command} in case ${last_command} in
kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop | kubectl_edit | kubectl_patch) kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop | kubectl_edit | kubectl_patch |\
kubectl_annotate)
__kubectl_get_resource __kubectl_get_resource
return return
;; ;;