diff options
author | Michael Muré <batolettre@gmail.com> | 2022-12-29 13:17:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-29 13:17:23 +0100 |
commit | c8ad1576b1472cb5723def810dfbcc30b40c70b7 (patch) | |
tree | e0a22258e29c12bec617b18298bea6bb377aede6 /commands/execenv/env.go | |
parent | 211a038c6057c5cfdcbf4c7d4cc8b4e93d8dc8db (diff) | |
parent | 5844dd0a6a08f496e6018c0bad0b38d82a8846fc (diff) | |
download | git-bug-c8ad1576b1472cb5723def810dfbcc30b40c70b7.tar.gz |
Merge pull request #966 from MichaelMure/cmdjson
commands: share JSON creation
Diffstat (limited to 'commands/execenv/env.go')
-rw-r--r-- | commands/execenv/env.go | 11 |
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") } |