diff --git a/contrib/completions/bash/kubectl b/contrib/completions/bash/kubectl index 233a916c136..b834a86522b 100644 --- a/contrib/completions/bash/kubectl +++ b/contrib/completions/bash/kubectl @@ -844,6 +844,22 @@ _kubectl_label() must_have_one_flag=() must_have_one_noun=() + must_have_one_noun+=("componentstatus") + 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+=("podtemplate") + must_have_one_noun+=("replicationcontroller") + must_have_one_noun+=("resourcequota") + must_have_one_noun+=("secret") + must_have_one_noun+=("service") + must_have_one_noun+=("serviceaccount") + must_have_one_noun+=("thirdpartyresource") } _kubectl_annotate() diff --git a/pkg/kubectl/cmd/cmd_test.go b/pkg/kubectl/cmd/cmd_test.go index 5f95a00ca68..acf4fae94a1 100644 --- a/pkg/kubectl/cmd/cmd_test.go +++ b/pkg/kubectl/cmd/cmd_test.go @@ -112,6 +112,11 @@ func (t *testPrinter) PrintObj(obj runtime.Object, out io.Writer) error { return t.Err } +// TODO: implement HandledResources() +func (t *testPrinter) HandledResources() []string { + return []string{} +} + type testDescriber struct { Name, Namespace string Output string diff --git a/pkg/kubectl/cmd/label.go b/pkg/kubectl/cmd/label.go index 024498ae1bf..333416db8ca 100644 --- a/pkg/kubectl/cmd/label.go +++ b/pkg/kubectl/cmd/label.go @@ -65,6 +65,12 @@ $ kubectl label pods foo bar-` func NewCmdLabel(f *cmdutil.Factory, out io.Writer) *cobra.Command { options := &LabelOptions{} + validArgs := []string{} + p, err := f.Printer(nil, false, false, false, false, []string{}) + cmdutil.CheckErr(err) + if p != nil { + validArgs = p.HandledResources() + } cmd := &cobra.Command{ Use: "label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]", @@ -75,6 +81,7 @@ func NewCmdLabel(f *cmdutil.Factory, out io.Writer) *cobra.Command { err := RunLabel(f, out, cmd, args, options) cmdutil.CheckErr(err) }, + ValidArgs: validArgs, } cmdutil.AddPrinterFlags(cmd) cmd.Flags().Bool("overwrite", false, "If true, allow labels to be overwritten, otherwise reject label updates that overwrite existing labels.") diff --git a/pkg/kubectl/resource_printer.go b/pkg/kubectl/resource_printer.go index b192b039bb1..37f6a517252 100644 --- a/pkg/kubectl/resource_printer.go +++ b/pkg/kubectl/resource_printer.go @@ -102,6 +102,7 @@ func GetPrinter(format, formatArgument string) (ResourcePrinter, bool, error) { type ResourcePrinter interface { // Print receives a runtime object, formats it and prints it to a writer. PrintObj(runtime.Object, io.Writer) error + HandledResources() []string } // ResourcePrinterFunc is a function that can print objects @@ -112,6 +113,11 @@ func (fn ResourcePrinterFunc) PrintObj(obj runtime.Object, w io.Writer) error { return fn(obj, w) } +// TODO: implement HandledResources() +func (fn ResourcePrinterFunc) HandledResources() []string { + return []string{} +} + // VersionedPrinter takes runtime objects and ensures they are converted to a given API version // prior to being passed to a nested printer. type VersionedPrinter struct { @@ -150,6 +156,11 @@ func (p *VersionedPrinter) PrintObj(obj runtime.Object, w io.Writer) error { return fmt.Errorf("the object cannot be converted to any of the versions: %v", p.version) } +// TODO: implement HandledResources() +func (p *VersionedPrinter) HandledResources() []string { + return []string{} +} + // NamePrinter is an implementation of ResourcePrinter which outputs "resource/name" pair of an object. type NamePrinter struct { } @@ -200,6 +211,11 @@ func (p *NamePrinter) PrintObj(obj runtime.Object, w io.Writer) error { return nil } +// TODO: implement HandledResources() +func (p *NamePrinter) HandledResources() []string { + return []string{} +} + // JSONPrinter is an implementation of ResourcePrinter which outputs an object as JSON. type JSONPrinter struct { } @@ -217,6 +233,11 @@ func (p *JSONPrinter) PrintObj(obj runtime.Object, w io.Writer) error { return err } +// TODO: implement HandledResources() +func (p *JSONPrinter) HandledResources() []string { + return []string{} +} + // YAMLPrinter is an implementation of ResourcePrinter which outputs an object as YAML. // The input object is assumed to be in the internal version of an API and is converted // to the given version first. @@ -235,6 +256,11 @@ func (p *YAMLPrinter) PrintObj(obj runtime.Object, w io.Writer) error { return err } +// TODO: implement HandledResources() +func (p *YAMLPrinter) HandledResources() []string { + return []string{} +} + type handlerEntry struct { columns []string printFunc reflect.Value @@ -1243,6 +1269,11 @@ func (p *TemplatePrinter) PrintObj(obj runtime.Object, w io.Writer) error { return nil } +// TODO: implement HandledResources() +func (p *TemplatePrinter) HandledResources() []string { + return []string{} +} + // safeExecute tries to execute the template, but catches panics and returns an error // should the template engine panic. func (p *TemplatePrinter) safeExecute(w io.Writer, obj interface{}) error { @@ -1387,3 +1418,8 @@ func (j *JSONPathPrinter) PrintObj(obj runtime.Object, w io.Writer) error { } return nil } + +// TODO: implement HandledResources() +func (p *JSONPathPrinter) HandledResources() []string { + return []string{} +} diff --git a/pkg/kubectl/sorting_printer.go b/pkg/kubectl/sorting_printer.go index b28724a4a94..6b2cb7d687b 100644 --- a/pkg/kubectl/sorting_printer.go +++ b/pkg/kubectl/sorting_printer.go @@ -46,6 +46,11 @@ func (s *SortingPrinter) PrintObj(obj runtime.Object, out io.Writer) error { return s.Delegate.PrintObj(obj, out) } +// TODO: implement HandledResources() +func (p *SortingPrinter) HandledResources() []string { + return []string{} +} + func (s *SortingPrinter) sortObj(obj runtime.Object) error { objs, err := runtime.ExtractList(obj) if err != nil {