diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index ee6ed2d901..ba55baf1b1 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -391,7 +391,7 @@ }, { "ImportPath": "github.com/spf13/cobra", - "Rev": "c0da825198c75814463e1b3018e42e438b771a5b" + "Rev": "9cb5e8502924a8ff1cce18a9348b61995d7b4fde" }, { "ImportPath": "github.com/spf13/pflag", diff --git a/Godeps/_workspace/src/github.com/spf13/cobra/bash_completions.go b/Godeps/_workspace/src/github.com/spf13/cobra/bash_completions.go index 1c5640745f..dee95b31ca 100644 --- a/Godeps/_workspace/src/github.com/spf13/cobra/bash_completions.go +++ b/Godeps/_workspace/src/github.com/spf13/cobra/bash_completions.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "os" + "sort" "strings" "github.com/spf13/pflag" @@ -282,6 +283,7 @@ func writeRequiredFlag(cmd *Command, out *bytes.Buffer) { func writeRequiredNoun(cmd *Command, out *bytes.Buffer) { fmt.Fprintf(out, " must_have_one_noun=()\n") + sort.Sort(sort.StringSlice(cmd.ValidArgs)) for _, value := range cmd.ValidArgs { fmt.Fprintf(out, " must_have_one_noun+=(%q)\n", value) } diff --git a/contrib/completions/bash/kubectl b/contrib/completions/bash/kubectl index 372a663ed9..d9bc47c772 100644 --- a/contrib/completions/bash/kubectl +++ b/contrib/completions/bash/kubectl @@ -242,6 +242,19 @@ _kubectl_get() must_have_one_flag=() must_have_one_noun=() + must_have_one_noun+=("endpoints") + must_have_one_noun+=("event") + must_have_one_noun+=("limitrange") + must_have_one_noun+=("namespace") + 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") + must_have_one_noun+=("status") } _kubectl_describe() diff --git a/pkg/kubectl/cmd/get.go b/pkg/kubectl/cmd/get.go index 8abd7880d9..72519966eb 100644 --- a/pkg/kubectl/cmd/get.go +++ b/pkg/kubectl/cmd/get.go @@ -60,6 +60,9 @@ $ kubectl get rc/web service/frontend pods/web-pod-13je7` // NewCmdGet creates a command object for the generic "get" action, which // retrieves one or more resources from a server. func NewCmdGet(f *cmdutil.Factory, out io.Writer) *cobra.Command { + p := kubectl.NewHumanReadablePrinter(false) + validArgs := p.HandledResources() + cmd := &cobra.Command{ Use: "get [(-o|--output=)json|yaml|template|...] (RESOURCE [NAME] | RESOURCE/NAME ...)", Short: "Display one or many resources", @@ -69,6 +72,7 @@ func NewCmdGet(f *cmdutil.Factory, out io.Writer) *cobra.Command { err := RunGet(f, out, cmd, args) cmdutil.CheckErr(err) }, + ValidArgs: validArgs, } cmdutil.AddPrinterFlags(cmd) cmd.Flags().StringP("selector", "l", "", "Selector (label query) to filter on") diff --git a/pkg/kubectl/resource_printer.go b/pkg/kubectl/resource_printer.go index 4e9f6f6ec0..e3f393c241 100644 --- a/pkg/kubectl/resource_printer.go +++ b/pkg/kubectl/resource_printer.go @@ -227,6 +227,22 @@ func (h *HumanReadablePrinter) validatePrintHandlerFunc(printFunc reflect.Value) return nil } +func (h *HumanReadablePrinter) HandledResources() []string { + keys := make([]string, 0) + + for k := range h.handlerMap { + // k.String looks like "*api.PodList" and we want just "pod" + api := strings.Split(k.String(), ".") + resource := api[len(api)-1] + if strings.HasSuffix(resource, "List") { + continue + } + resource = strings.ToLower(resource) + keys = append(keys, resource) + } + return keys +} + var podColumns = []string{"POD", "IP", "CONTAINER(S)", "IMAGE(S)", "HOST", "LABELS", "STATUS", "CREATED"} var replicationControllerColumns = []string{"CONTROLLER", "CONTAINER(S)", "IMAGE(S)", "SELECTOR", "REPLICAS"} var serviceColumns = []string{"NAME", "LABELS", "SELECTOR", "IP", "PORT(S)"}