Display the config in correct format when json flag is used (#2544)

Fixes #2530
This commit is contained in:
kannappanr
2018-09-19 11:48:21 -07:00
committed by GitHub
parent 044a95b6cf
commit c9f33698fc
+6 -4
View File
@@ -18,6 +18,7 @@ package cmd
import (
"encoding/json"
"strings"
"github.com/minio/cli"
"github.com/minio/mc/pkg/probe"
@@ -48,7 +49,7 @@ EXAMPLES:
// configGetMessage container to hold locks information.
type configGetMessage struct {
Status string `json:"status"`
Config []byte `json:"config"`
Config string `json:"config"`
}
// String colorized service status message.
@@ -59,10 +60,11 @@ func (u configGetMessage) String() string {
// JSON jsonified service status Message message.
func (u configGetMessage) JSON() string {
u.Status = "success"
statusJSONBytes, e := json.Marshal(u)
statusJSONBytes, e := json.MarshalIndent(u, "", "\t")
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
return string(statusJSONBytes)
// Remove \n and \t from u.Config which holds the config data
return strings.NewReplacer(`\n`, "", `\t`, "").Replace(string(statusJSONBytes))
}
// checkAdminConfigGetSyntax - validate all the passed arguments
@@ -89,7 +91,7 @@ func mainAdminConfigGet(ctx *cli.Context) error {
fatalIf(probe.NewError(e), "Cannot get server configuration file.")
// Print
printMsg(configGetMessage{Config: c})
printMsg(configGetMessage{Config: string(c)})
return nil
}