From 5844dd0a6a08f496e6018c0bad0b38d82a8846fc Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Thu, 29 Dec 2022 12:49:12 +0100 Subject: commands: share JSON creation --- commands/user/user.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'commands/user/user.go') diff --git a/commands/user/user.go b/commands/user/user.go index 9a1e477c..a9a45726 100644 --- a/commands/user/user.go +++ b/commands/user/user.go @@ -1,14 +1,12 @@ package usercmd import ( - "encoding/json" "fmt" "github.com/spf13/cobra" - json2 "github.com/MichaelMure/git-bug/commands/cmdjson" - "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/commands/cmdjson" "github.com/MichaelMure/git-bug/commands/completion" "github.com/MichaelMure/git-bug/commands/execenv" "github.com/MichaelMure/git-bug/util/colors" @@ -78,12 +76,10 @@ func userDefaultFormatter(env *execenv.Env, users []*cache.IdentityExcerpt) erro } func userJsonFormatter(env *execenv.Env, users []*cache.IdentityExcerpt) error { - jsonUsers := make([]json2.Identity, len(users)) + jsonUsers := make([]cmdjson.Identity, len(users)) for i, user := range users { - jsonUsers[i] = json2.NewIdentityFromExcerpt(user) + jsonUsers[i] = cmdjson.NewIdentityFromExcerpt(user) } - jsonObject, _ := json.MarshalIndent(jsonUsers, "", " ") - env.Out.Printf("%s\n", jsonObject) - return nil + return env.Out.PrintJSON(jsonUsers) } -- cgit