author | Mikael Berthe <mikael@lilotux.net> |
Sun, 28 May 2017 10:36:07 +0200 | |
changeset 157 | 908a433f02c0 |
parent 110 | 57843255fd1a |
permissions | -rw-r--r-- |
0 | 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 |
||
83
57afac822019
Use a map for ResourcePrinter options
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
13 |
// Options contains options used when creating a ResourcePrinter |
57afac822019
Use a map for ResourcePrinter options
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
14 |
type Options map[string]string |
57afac822019
Use a map for ResourcePrinter options
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
15 |
|
110 | 16 |
type commonPrinter struct { |
17 |
w io.Writer |
|
18 |
} |
|
19 |
||
0 | 20 |
// ResourcePrinter is an interface used to print objects. |
21 |
type ResourcePrinter interface { |
|
22 |
// PrintObj receives a runtime object, formats it and prints it to a writer. |
|
23 |
PrintObj(interface{}, io.Writer, string) error |
|
24 |
} |
|
25 |
||
26 |
// NewPrinter returns a ResourcePrinter for the specified kind of output. |
|
27 |
// It returns nil if the output is not supported. |
|
83
57afac822019
Use a map for ResourcePrinter options
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
28 |
func NewPrinter(output string, options Options) (ResourcePrinter, error) { |
0 | 29 |
switch output { |
30 |
case "", "plain": |
|
83
57afac822019
Use a map for ResourcePrinter options
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
31 |
return NewPrinterPlain(options) |
0 | 32 |
case "json": |
83
57afac822019
Use a map for ResourcePrinter options
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
33 |
return NewPrinterJSON(options) |
0 | 34 |
case "yaml": |
83
57afac822019
Use a map for ResourcePrinter options
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
35 |
return NewPrinterYAML(options) |
0 | 36 |
case "template": |
83
57afac822019
Use a map for ResourcePrinter options
Mikael Berthe <mikael@lilotux.net>
parents:
0
diff
changeset
|
37 |
return NewPrinterTemplate(options) |
85 | 38 |
case "theme": |
39 |
return NewPrinterTheme(options) |
|
0 | 40 |
} |
41 |
return nil, fmt.Errorf("unhandled output format") |
|
42 |
} |