1
0
mirror of https://github.com/minio/mc.git synced 2026-01-04 02:44:40 +03:00

Add single line json output (#3739)

This commit is contained in:
Klaus Post
2021-06-11 23:40:16 +02:00
committed by GitHub
parent 27d0ea67cb
commit 7c0ab1b2d5
2 changed files with 14 additions and 1 deletions

View File

@@ -57,6 +57,7 @@ const (
var (
globalQuiet = false // Quiet flag set via command line
globalJSON = false // Json flag set via command line
globalJSONLine = false // Print json as single line.
globalDebug = false // Debug flag set via command line
globalNoColor = false // No Color flag set via command line
globalInsecure = false // Insecure flag set via command line
@@ -76,8 +77,9 @@ var (
func setGlobals(quiet, debug, json, noColor, insecure bool) {
globalQuiet = globalQuiet || quiet
globalDebug = globalDebug || debug
globalJSONLine = !isTerminal() && json
globalJSON = globalJSON || json
globalNoColor = globalNoColor || noColor
globalNoColor = globalNoColor || noColor || globalJSONLine
globalInsecure = globalInsecure || insecure
// Disable colorified messages if requested.

View File

@@ -18,6 +18,10 @@
package cmd
import (
"bytes"
"encoding/json"
"strings"
"github.com/minio/pkg/console"
)
@@ -34,6 +38,13 @@ func printMsg(msg message) {
msgStr = msg.String()
} else {
msgStr = msg.JSON()
if globalJSONLine && strings.ContainsRune(msgStr, '\n') {
// Reformat.
var dst bytes.Buffer
if err := json.Compact(&dst, []byte(msgStr)); err == nil {
msgStr = dst.String()
}
}
}
console.Println(msgStr)
}