-
Notifications
You must be signed in to change notification settings - Fork 69
/
print.go
57 lines (46 loc) · 1.33 KB
/
print.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package output
import (
"fmt"
"github.com/newrelic/newrelic-cli/internal/utils"
)
// Print outputs the data in the expected format
func Print(data interface{}) (err error) {
if err = ensureGlobalOutput(); err != nil {
return err
}
switch globalOutput.format {
case FormatJSON:
err = globalOutput.json(data)
case FormatText:
err = globalOutput.text(data)
case FormatYAML:
err = globalOutput.yaml(data)
default:
err = globalOutput.json(data)
}
return err
}
// Printf renders output based on the format and data provided
func Printf(format string, a ...interface{}) {
utils.LogIfFatal(ensureGlobalOutput())
data := fmt.Sprintf(format, a...)
utils.LogIfFatal(globalOutput.text(data))
}
// JSON allows you to override the default output method and
// explicitly print JSON to the screen
func JSON(data interface{}) {
utils.LogIfFatal(ensureGlobalOutput())
utils.LogIfFatal(globalOutput.json(data))
}
// Text allows you to override the default output method and
// explicitly print text to the screen
func Text(data interface{}) {
utils.LogIfFatal(ensureGlobalOutput())
utils.LogIfFatal(globalOutput.text(data))
}
// YAML allows you to override the default output method and
// explicitly print YAML to the screen
func YAML(data interface{}) {
utils.LogIfFatal(ensureGlobalOutput())
utils.LogIfFatal(globalOutput.yaml(data))
}