forked from TrueCloudLab/frostfs-node
Anton Nikiforov
8ee590794f
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com> Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
23 lines
520 B
Go
23 lines
520 B
Go
package common
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// PrettyPrintJSON prints m as an indented JSON to the cmd output.
|
|
func PrettyPrintJSON(cmd *cobra.Command, m json.Marshaler, entity string) {
|
|
data, err := m.MarshalJSON()
|
|
if err != nil {
|
|
PrintVerbose(cmd, "Can't convert %s to json: %w", entity, err)
|
|
return
|
|
}
|
|
buf := new(bytes.Buffer)
|
|
if err := json.Indent(buf, data, "", " "); err != nil {
|
|
PrintVerbose(cmd, "Can't pretty print json: %w", err)
|
|
return
|
|
}
|
|
cmd.Println(buf)
|
|
}
|