Get printer from factory to retrieve handled resources

This commit is contained in:
Janet Kuo 2015-08-31 12:04:12 -07:00
parent 23740d9080
commit b673920ccf
5 changed files with 53 additions and 2 deletions

View File

@ -848,6 +848,7 @@ _kubectl_label()
must_have_one_noun+=("secret") must_have_one_noun+=("secret")
must_have_one_noun+=("service") must_have_one_noun+=("service")
must_have_one_noun+=("serviceaccount") must_have_one_noun+=("serviceaccount")
must_have_one_noun+=("thirdpartyresource")
} }
_kubectl_annotate() _kubectl_annotate()

View File

@ -112,6 +112,11 @@ func (t *testPrinter) PrintObj(obj runtime.Object, out io.Writer) error {
return t.Err return t.Err
} }
// TODO: implement HandledResources()
func (t *testPrinter) HandledResources() []string {
return []string{}
}
type testDescriber struct { type testDescriber struct {
Name, Namespace string Name, Namespace string
Output string Output string

View File

@ -64,8 +64,12 @@ $ kubectl label pods foo bar-`
func NewCmdLabel(f *cmdutil.Factory, out io.Writer) *cobra.Command { func NewCmdLabel(f *cmdutil.Factory, out io.Writer) *cobra.Command {
options := &LabelOptions{} options := &LabelOptions{}
p := kubectl.NewHumanReadablePrinter(false, false, false, false, []string{}) validArgs := []string{}
validArgs := p.HandledResources() p, err := f.Printer(nil, false, false, false, false, []string{})
cmdutil.CheckErr(err)
if p != nil {
validArgs = p.HandledResources()
}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]", Use: "label [--overwrite] (-f FILENAME | TYPE NAME) KEY_1=VAL_1 ... KEY_N=VAL_N [--resource-version=version]",

View File

@ -101,6 +101,7 @@ func GetPrinter(format, formatArgument string) (ResourcePrinter, bool, error) {
type ResourcePrinter interface { type ResourcePrinter interface {
// Print receives a runtime object, formats it and prints it to a writer. // Print receives a runtime object, formats it and prints it to a writer.
PrintObj(runtime.Object, io.Writer) error PrintObj(runtime.Object, io.Writer) error
HandledResources() []string
} }
// ResourcePrinterFunc is a function that can print objects // ResourcePrinterFunc is a function that can print objects
@ -111,6 +112,11 @@ func (fn ResourcePrinterFunc) PrintObj(obj runtime.Object, w io.Writer) error {
return fn(obj, w) 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 // VersionedPrinter takes runtime objects and ensures they are converted to a given API version
// prior to being passed to a nested printer. // prior to being passed to a nested printer.
type VersionedPrinter struct { type VersionedPrinter struct {
@ -149,6 +155,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) 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. // NamePrinter is an implementation of ResourcePrinter which outputs "resource/name" pair of an object.
type NamePrinter struct { type NamePrinter struct {
} }
@ -199,6 +210,11 @@ func (p *NamePrinter) PrintObj(obj runtime.Object, w io.Writer) error {
return nil return nil
} }
// TODO: implement HandledResources()
func (p *NamePrinter) HandledResources() []string {
return []string{}
}
// JSONPrinter is an implementation of ResourcePrinter which outputs an object as JSON. // JSONPrinter is an implementation of ResourcePrinter which outputs an object as JSON.
type JSONPrinter struct { type JSONPrinter struct {
} }
@ -216,6 +232,11 @@ func (p *JSONPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
return err return err
} }
// TODO: implement HandledResources()
func (p *JSONPrinter) HandledResources() []string {
return []string{}
}
// YAMLPrinter is an implementation of ResourcePrinter which outputs an object as YAML. // 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 // The input object is assumed to be in the internal version of an API and is converted
// to the given version first. // to the given version first.
@ -234,6 +255,11 @@ func (p *YAMLPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
return err return err
} }
// TODO: implement HandledResources()
func (p *YAMLPrinter) HandledResources() []string {
return []string{}
}
type handlerEntry struct { type handlerEntry struct {
columns []string columns []string
printFunc reflect.Value printFunc reflect.Value
@ -1214,6 +1240,11 @@ func (p *TemplatePrinter) PrintObj(obj runtime.Object, w io.Writer) error {
return nil 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 // safeExecute tries to execute the template, but catches panics and returns an error
// should the template engine panic. // should the template engine panic.
func (p *TemplatePrinter) safeExecute(w io.Writer, obj interface{}) error { func (p *TemplatePrinter) safeExecute(w io.Writer, obj interface{}) error {
@ -1352,3 +1383,8 @@ func (j *JSONPathPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
} }
return nil return nil
} }
// TODO: implement HandledResources()
func (p *JSONPathPrinter) HandledResources() []string {
return []string{}
}

View File

@ -46,6 +46,11 @@ func (s *SortingPrinter) PrintObj(obj runtime.Object, out io.Writer) error {
return s.Delegate.PrintObj(obj, out) return s.Delegate.PrintObj(obj, out)
} }
// TODO: implement HandledResources()
func (p *SortingPrinter) HandledResources() []string {
return []string{}
}
func (s *SortingPrinter) sortObj(obj runtime.Object) error { func (s *SortingPrinter) sortObj(obj runtime.Object) error {
objs, err := runtime.ExtractList(obj) objs, err := runtime.ExtractList(obj)
if err != nil { if err != nil {