@@ -86,8 +86,12 @@ func (fb *Feedback) Printf(format string, v ...interface{}) {
8686}
8787
8888// 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+ }
9195}
9296
9397// Errorf behaves like fmt.Printf but writes on the error writer and adds a
@@ -109,18 +113,16 @@ func (fb *Feedback) PrintJSON(v interface{}) {
109113 if d , err := json .MarshalIndent (v , "" , " " ); err != nil {
110114 fb .Errorf ("Error during JSON encoding of the output: %v" , err )
111115 } else {
112- fb . Print ( string (d ))
116+ fmt . Fprint ( fb . out , string (d ))
113117 }
114118}
115119
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.
117123func (fb * Feedback ) PrintResult (res Result ) {
118124 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 ())
124126 } else {
125127 fb .Print (fmt .Sprintf ("%s" , res ))
126128 }
0 commit comments