From 9e6c01622312594050efcaf2da8c86b0c43ac86d Mon Sep 17 00:00:00 2001 From: Christian Frichot Date: Tue, 22 Sep 2020 19:50:40 +0800 Subject: [PATCH] Add JSON formatted output for authenticate password cli command (#402) --- internal/cmd/commands/authenticate/password.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/cmd/commands/authenticate/password.go b/internal/cmd/commands/authenticate/password.go index 33cb03234..cf13dd646 100644 --- a/internal/cmd/commands/authenticate/password.go +++ b/internal/cmd/commands/authenticate/password.go @@ -145,6 +145,14 @@ func (c *PasswordCommand) Run(args []string) int { fmt.Sprintf(" Token: %s", token.Token), fmt.Sprintf(" User ID: %s", token.UserId), })) + + case "json": + jsonOut, err := base.JsonFormatter{}.Format(result) + if err != nil { + c.UI.Error(fmt.Errorf("Error formatting as JSON: %w", err).Error()) + return 1 + } + c.UI.Output(string(jsonOut)) } tokenName := "default"