From 15ebe1bef4e7198891e510b01dcea80b719e62a3 Mon Sep 17 00:00:00 2001 From: mig4 <42650719@auril.club> Date: Fri, 30 Jul 2021 12:45:03 +0100 Subject: [PATCH] Make list output to stdout List commands are producing JSON/YAML output and this allows piping it to the likes of jq/yq for further processing. --- command/heartbeat_cmd.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/command/heartbeat_cmd.go b/command/heartbeat_cmd.go index 1a16ec1..2bec086 100644 --- a/command/heartbeat_cmd.go +++ b/command/heartbeat_cmd.go @@ -2,6 +2,7 @@ package command import ( "errors" + "fmt" "github.com/opsgenie/opsgenie-go-sdk-v2/heartbeat" "github.com/opsgenie/opsgenie-go-sdk-v2/og" gcli "github.com/urfave/cli" @@ -190,21 +191,21 @@ func ListHeartbeatAction(c *gcli.Context) { outputFormat := strings.ToLower(c.String("output-format")) printMessage(DEBUG,"Heartbeats listed successfully, and will print as " + outputFormat) + var output string switch outputFormat { case "yaml": - output, err := resultToYAML(response.Heartbeats) + output, err = resultToYAML(response.Heartbeats) if err != nil { printMessage(ERROR,err.Error()) os.Exit(1) } - printMessage(INFO, output) default: isPretty := c.IsSet("pretty") - output, err := resultToJSON(response.Heartbeats, isPretty) + output, err = resultToJSON(response.Heartbeats, isPretty) if err != nil { printMessage(ERROR,err.Error()) os.Exit(1) } - printMessage(INFO, output) } + fmt.Println(output) }