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+=("service")
must_have_one_noun+=("serviceaccount")
must_have_one_noun+=("thirdpartyresource")
}
_kubectl_annotate()

View File

@ -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

View File

@ -64,8 +64,12 @@ $ kubectl label pods foo bar-`
func NewCmdLabel(f *cmdutil.Factory, out io.Writer) *cobra.Command {
options := &LabelOptions{}
p := kubectl.NewHumanReadablePrinter(false, false, false, false, []string{})
validArgs := p.HandledResources()
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]",

View File

@ -101,6 +101,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
@ -111,6 +112,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 {
@ -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)
}
// 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 {
}
@ -199,6 +210,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 {
}
@ -216,6 +232,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.
@ -234,6 +255,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
@ -1214,6 +1240,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 {
@ -1352,3 +1383,8 @@ func (j *JSONPathPrinter) PrintObj(obj runtime.Object, w io.Writer) error {
}
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)
}
// 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 {