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:
@@ -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.
|
||||
|
||||
11
cmd/print.go
11
cmd/print.go
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user