equal
deleted
inserted
replaced
|
1 // Copyright © 2017 Mikael Berthe <mikael@lilotux.net> |
|
2 // |
|
3 // Licensed under the MIT license. |
|
4 // Please see the LICENSE file is this directory. |
|
5 |
|
6 package printer |
|
7 |
|
8 import ( |
|
9 "fmt" |
|
10 "io" |
|
11 ) |
|
12 |
|
13 // ResourcePrinter is an interface used to print objects. |
|
14 type ResourcePrinter interface { |
|
15 // PrintObj receives a runtime object, formats it and prints it to a writer. |
|
16 PrintObj(interface{}, io.Writer, string) error |
|
17 } |
|
18 |
|
19 // NewPrinter returns a ResourcePrinter for the specified kind of output. |
|
20 // It returns nil if the output is not supported. |
|
21 func NewPrinter(output, option string) (ResourcePrinter, error) { |
|
22 switch output { |
|
23 case "", "plain": |
|
24 return NewPrinterPlain(option) |
|
25 case "json": |
|
26 return NewPrinterJSON(option) |
|
27 case "yaml": |
|
28 return NewPrinterYAML(option) |
|
29 case "template": |
|
30 return NewPrinterTemplate(option) |
|
31 } |
|
32 return nil, fmt.Errorf("unhandled output format") |
|
33 } |