aboutsummaryrefslogtreecommitdiffstats
path: root/commands/execenv/env.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/execenv/env.go')
-rw-r--r--commands/execenv/env.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/commands/execenv/env.go b/commands/execenv/env.go
index b383dde0..4be7c247 100644
--- a/commands/execenv/env.go
+++ b/commands/execenv/env.go
@@ -1,6 +1,7 @@
package execenv
import (
+ "encoding/json"
"fmt"
"io"
"os"
@@ -38,6 +39,7 @@ type Out interface {
Printf(format string, a ...interface{})
Print(a ...interface{})
Println(a ...interface{})
+ PrintJSON(v interface{}) error
// String returns what have been written in the output before, as a string.
// This only works in test scenario.
@@ -66,6 +68,15 @@ func (o out) Println(a ...interface{}) {
_, _ = fmt.Fprintln(o, a...)
}
+func (o out) PrintJSON(v interface{}) error {
+ raw, err := json.MarshalIndent(v, "", " ")
+ if err != nil {
+ return err
+ }
+ o.Println(string(raw))
+ return nil
+}
+
func (o out) String() string {
panic("only work with a test env")
}