@@ -86,8 +86,12 @@ func (fb *Feedback) Printf(format string, v ...interface{}) {
86
86
}
87
87
88
88
// Print behaves like fmt.Print but writes on the out writer and adds a newline.
89
- func (fb * Feedback ) Print (v ... interface {}) {
90
- fmt .Fprintln (fb .out , v ... )
89
+ func (fb * Feedback ) Print (v interface {}) {
90
+ if fb .format == JSON {
91
+ fb .PrintJSON (v )
92
+ } else {
93
+ fmt .Fprintln (fb .out , v )
94
+ }
91
95
}
92
96
93
97
// Errorf behaves like fmt.Printf but writes on the error writer and adds a
@@ -109,18 +113,16 @@ func (fb *Feedback) PrintJSON(v interface{}) {
109
113
if d , err := json .MarshalIndent (v , "" , " " ); err != nil {
110
114
fb .Errorf ("Error during JSON encoding of the output: %v" , err )
111
115
} else {
112
- fb . Print ( string (d ))
116
+ fmt . Fprint ( fb . out , string (d ))
113
117
}
114
118
}
115
119
116
- // PrintResult is a convenient wrapper...
120
+ // PrintResult is a convenient wrapper to provide feedback for complex data,
121
+ // where the contents can't be just serialized to JSON but requires more
122
+ // structure.
117
123
func (fb * Feedback ) PrintResult (res Result ) {
118
124
if fb .format == JSON {
119
- if d , err := json .MarshalIndent (res .Data (), "" , " " ); err != nil {
120
- fb .Errorf ("Error during JSON encoding of the output: %v" , err )
121
- } else {
122
- fb .Print (string (d ))
123
- }
125
+ fb .PrintJSON (res .Data ())
124
126
} else {
125
127
fb .Print (fmt .Sprintf ("%s" , res ))
126
128
}
0 commit comments