printer/printer.go
changeset 83 57afac822019
parent 0 5abace724584
child 85 a4464c0b0c36
equal deleted inserted replaced
82:9ac2281c07d7 83:57afac822019
     8 import (
     8 import (
     9 	"fmt"
     9 	"fmt"
    10 	"io"
    10 	"io"
    11 )
    11 )
    12 
    12 
       
    13 // Options contains options used when creating a ResourcePrinter
       
    14 type Options map[string]string
       
    15 
    13 // ResourcePrinter is an interface used to print objects.
    16 // ResourcePrinter is an interface used to print objects.
    14 type ResourcePrinter interface {
    17 type ResourcePrinter interface {
    15 	// PrintObj receives a runtime object, formats it and prints it to a writer.
    18 	// PrintObj receives a runtime object, formats it and prints it to a writer.
    16 	PrintObj(interface{}, io.Writer, string) error
    19 	PrintObj(interface{}, io.Writer, string) error
    17 }
    20 }
    18 
    21 
    19 // NewPrinter returns a ResourcePrinter for the specified kind of output.
    22 // NewPrinter returns a ResourcePrinter for the specified kind of output.
    20 // It returns nil if the output is not supported.
    23 // It returns nil if the output is not supported.
    21 func NewPrinter(output, option string) (ResourcePrinter, error) {
    24 func NewPrinter(output string, options Options) (ResourcePrinter, error) {
    22 	switch output {
    25 	switch output {
    23 	case "", "plain":
    26 	case "", "plain":
    24 		return NewPrinterPlain(option)
    27 		return NewPrinterPlain(options)
    25 	case "json":
    28 	case "json":
    26 		return NewPrinterJSON(option)
    29 		return NewPrinterJSON(options)
    27 	case "yaml":
    30 	case "yaml":
    28 		return NewPrinterYAML(option)
    31 		return NewPrinterYAML(options)
    29 	case "template":
    32 	case "template":
    30 		return NewPrinterTemplate(option)
    33 		return NewPrinterTemplate(options)
    31 	}
    34 	}
    32 	return nil, fmt.Errorf("unhandled output format")
    35 	return nil, fmt.Errorf("unhandled output format")
    33 }
    36 }