use colorjson for all other mc outputs (#2683)
- Update to MarshalIndent instead of Marshal - Allow unmarshalling
This commit is contained in:
committed by
kannappanr
parent
19e14db50a
commit
c75abbb3f9
@@ -17,12 +17,14 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/cheggaaa/pb"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
// accounter keeps tabs of ongoing data transfer information.
|
||||
@@ -78,9 +80,18 @@ func (a *accounter) writer() {
|
||||
|
||||
// accountStat cantainer for current stats captured.
|
||||
type accountStat struct {
|
||||
Total int64
|
||||
Transferred int64
|
||||
Speed float64
|
||||
Status string `json:"status"`
|
||||
Total int64 `json:"total"`
|
||||
Transferred int64 `json:"transferred"`
|
||||
Speed float64 `json:"speed"`
|
||||
}
|
||||
|
||||
func (c accountStat) JSON() string {
|
||||
c.Status = "success"
|
||||
accountMessageBytes, e := json.MarshalIndent(c, "", " ")
|
||||
fatalIf(probe.NewError(e), "Failed to marshal account stat.")
|
||||
|
||||
return string(accountMessageBytes)
|
||||
}
|
||||
|
||||
func (c accountStat) String() string {
|
||||
|
||||
+16
-10
@@ -17,10 +17,8 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
@@ -48,23 +46,25 @@ EXAMPLES:
|
||||
|
||||
// configGetMessage container to hold locks information.
|
||||
type configGetMessage struct {
|
||||
Status string `json:"status"`
|
||||
Config string `json:"config"`
|
||||
Status string `json:"status"`
|
||||
Config map[string]interface{} `json:"config"`
|
||||
}
|
||||
|
||||
// String colorized service status message.
|
||||
func (u configGetMessage) String() string {
|
||||
return string(u.Config)
|
||||
config, e := json.MarshalIndent(u.Config, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(config)
|
||||
}
|
||||
|
||||
// JSON jsonified service status Message message.
|
||||
func (u configGetMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
statusJSONBytes, e := json.MarshalIndent(u, "", "\t")
|
||||
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
// Remove \n and \t from u.Config which holds the config data
|
||||
return strings.NewReplacer(`\n`, "", `\t`, "").Replace(string(statusJSONBytes))
|
||||
return string(statusJSONBytes)
|
||||
}
|
||||
|
||||
// checkAdminConfigGetSyntax - validate all the passed arguments
|
||||
@@ -90,8 +90,14 @@ func mainAdminConfigGet(ctx *cli.Context) error {
|
||||
c, e := client.GetConfig()
|
||||
fatalIf(probe.NewError(e), "Cannot get server configuration file.")
|
||||
|
||||
config := map[string]interface{}{}
|
||||
e = json.Unmarshal(c, &config)
|
||||
fatalIf(probe.NewError(e), "Cannot unmarshal server configuration file.")
|
||||
|
||||
// Print
|
||||
printMsg(configGetMessage{Config: string(c)})
|
||||
printMsg(configGetMessage{
|
||||
Config: config,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -76,7 +76,7 @@ func (u configSetMessage) JSON() string {
|
||||
} else {
|
||||
u.Status = "error"
|
||||
}
|
||||
statusJSONBytes, e := json.Marshal(u)
|
||||
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(statusJSONBytes)
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
@@ -28,6 +27,7 @@ import (
|
||||
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/fatih/color"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
@@ -299,7 +299,7 @@ func (ui *uiData) printItemsJSON(s *madmin.HealTaskStatus) (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jsonBytes, err := json.Marshal(r)
|
||||
jsonBytes, err := json.MarshalIndent(r, "", " ")
|
||||
fatalIf(probe.NewError(err), "Unable to marshal to JSON.")
|
||||
console.Println(string(jsonBytes))
|
||||
}
|
||||
@@ -329,7 +329,7 @@ func (ui *uiData) printStatsJSON(s *madmin.HealTaskStatus) {
|
||||
summary.Size = ui.BytesScanned
|
||||
summary.ElapsedTime = int64(ui.HealDuration.Round(time.Second).Seconds())
|
||||
|
||||
jBytes, err := json.Marshal(summary)
|
||||
jBytes, err := json.MarshalIndent(summary, "", " ")
|
||||
fatalIf(probe.NewError(err), "Unable to marshal to JSON.")
|
||||
console.Println(string(jBytes))
|
||||
}
|
||||
|
||||
+3
-3
@@ -17,11 +17,11 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
@@ -104,7 +104,7 @@ func (s stopHealMessage) String() string {
|
||||
|
||||
// JSON jsonified stop heal message.
|
||||
func (s stopHealMessage) JSON() string {
|
||||
stopHealJSONBytes, e := json.Marshal(s)
|
||||
stopHealJSONBytes, e := json.MarshalIndent(s, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(stopHealJSONBytes)
|
||||
@@ -169,7 +169,7 @@ func mainAdminHeal(ctx *cli.Context) error {
|
||||
res, e := ui.DisplayAndFollowHealStatus(aliasedURL)
|
||||
if e != nil {
|
||||
if res.FailureDetail != "" {
|
||||
data, _ := json.Marshal(res)
|
||||
data, _ := json.MarshalIndent(res, "", " ")
|
||||
traceStr := string(data)
|
||||
errorIf(probe.NewError(e).Trace(aliasedURL, traceStr), "Unable to display heal status.")
|
||||
} else {
|
||||
|
||||
+2
-2
@@ -17,7 +17,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
@@ -25,6 +24,7 @@ import (
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
@@ -170,7 +170,7 @@ func (u infoMessage) String() (msg string) {
|
||||
// JSON jsonified service status Message message.
|
||||
func (u infoMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
statusJSONBytes, e := json.Marshal(u)
|
||||
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(statusJSONBytes)
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -89,7 +89,7 @@ func (u userPolicyMessage) String() string {
|
||||
|
||||
func (u userPolicyMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
jsonMessageBytes, e := json.Marshal(u)
|
||||
jsonMessageBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(jsonMessageBytes)
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
@@ -62,7 +62,7 @@ func (s serviceRestartCommand) String() string {
|
||||
|
||||
// JSON jsonified service restart command message.
|
||||
func (s serviceRestartCommand) JSON() string {
|
||||
serviceRestartJSONBytes, e := json.Marshal(s)
|
||||
serviceRestartJSONBytes, e := json.MarshalIndent(s, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(serviceRestartJSONBytes)
|
||||
@@ -85,7 +85,7 @@ func (s serviceRestartMessage) String() string {
|
||||
|
||||
// JSON jsonified service restart message.
|
||||
func (s serviceRestartMessage) JSON() string {
|
||||
serviceRestartJSONBytes, e := json.Marshal(s)
|
||||
serviceRestartJSONBytes, e := json.MarshalIndent(s, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(serviceRestartJSONBytes)
|
||||
|
||||
@@ -17,13 +17,13 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -83,7 +83,7 @@ func (u serviceStatusMessage) JSON() string {
|
||||
u.Status = "failure"
|
||||
}
|
||||
|
||||
statusJSONBytes, e := json.Marshal(u)
|
||||
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(statusJSONBytes)
|
||||
|
||||
@@ -17,10 +17,9 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
@@ -61,7 +60,7 @@ func (s serviceStopMessage) String() string {
|
||||
|
||||
// JSON jsonified make bucket message.
|
||||
func (s serviceStopMessage) JSON() string {
|
||||
serviceStopJSONBytes, e := json.Marshal(s)
|
||||
serviceStopJSONBytes, e := json.MarshalIndent(s, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(serviceStopJSONBytes)
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
@@ -90,7 +90,7 @@ func (u lockMessage) String() string {
|
||||
// JSON jsonified top oldest locks message.
|
||||
func (u lockMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
statusJSONBytes, e := json.Marshal(u)
|
||||
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
return string(statusJSONBytes)
|
||||
}
|
||||
|
||||
@@ -17,10 +17,9 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -97,7 +96,7 @@ func (u userMessage) String() string {
|
||||
|
||||
func (u userMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
jsonMessageBytes, e := json.Marshal(u)
|
||||
jsonMessageBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(jsonMessageBytes)
|
||||
|
||||
+2
-2
@@ -20,7 +20,6 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"hash/fnv"
|
||||
"io"
|
||||
"net"
|
||||
@@ -34,6 +33,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/httptracer"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
minio "github.com/minio/minio-go"
|
||||
@@ -983,7 +983,7 @@ func (c *s3Client) SetAccess(bucketPolicy string, isJSON bool) *probe.Error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
policyB, e := json.Marshal(p)
|
||||
policyB, e := json.MarshalIndent(p, "", " ")
|
||||
if e != nil {
|
||||
return probe.NewError(e)
|
||||
}
|
||||
|
||||
+2
-3
@@ -17,9 +17,8 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -86,7 +85,7 @@ func (h hostMessage) String() string {
|
||||
// JSON jsonified host message
|
||||
func (h hostMessage) JSON() string {
|
||||
h.Status = "success"
|
||||
jsonMessageBytes, e := json.Marshal(h)
|
||||
jsonMessageBytes, e := json.MarshalIndent(h, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(jsonMessageBytes)
|
||||
|
||||
+4
-3
@@ -128,7 +128,7 @@ func (c copyMessage) String() string {
|
||||
// JSON jsonified copy message
|
||||
func (c copyMessage) JSON() string {
|
||||
c.Status = "success"
|
||||
copyMessageBytes, e := json.Marshal(c)
|
||||
copyMessageBytes, e := json.MarshalIndent(c, "", " ")
|
||||
fatalIf(probe.NewError(e), "Failed to marshal copy message.")
|
||||
|
||||
return string(copyMessageBytes)
|
||||
@@ -347,7 +347,8 @@ func doCopySession(session *sessionV8, encKeyDB map[string][]prefixSSEPair) erro
|
||||
}
|
||||
|
||||
var cpURLs URLs
|
||||
// Unmarshal copyURLs from each line.
|
||||
// Unmarshal copyURLs from each line. This expects each line to be
|
||||
// an entire JSON object.
|
||||
if e := json.Unmarshal([]byte(urlScanner.Text()), &cpURLs); e != nil {
|
||||
errorIf(probe.NewError(e), "Unable to unmarshal %s", urlScanner.Text())
|
||||
continue
|
||||
@@ -431,7 +432,7 @@ loop:
|
||||
}
|
||||
} else {
|
||||
if accntReader, ok := pg.(*accounter); ok {
|
||||
console.Println(console.Colorize("Copy", accntReader.Stat().String()))
|
||||
printMsg(accntReader.Stat())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -17,12 +17,12 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -102,7 +102,7 @@ func (d diffMessage) String() string {
|
||||
// JSON jsonified diff message
|
||||
func (d diffMessage) JSON() string {
|
||||
d.Status = "success"
|
||||
diffJSONBytes, e := json.Marshal(d)
|
||||
diffJSONBytes, e := json.MarshalIndent(d, "", " ")
|
||||
fatalIf(probe.NewError(e),
|
||||
"Unable to marshal diff message `"+d.FirstURL+"`, `"+d.SecondURL+"` and `"+string(d.Diff)+"`.")
|
||||
return string(diffJSONBytes)
|
||||
|
||||
+5
-5
@@ -17,12 +17,12 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -64,13 +64,13 @@ func fatal(err *probe.Error, msg string, data ...interface{}) {
|
||||
if globalDebug {
|
||||
errorMsg.CallTrace = err.CallTrace
|
||||
}
|
||||
json, e := json.Marshal(struct {
|
||||
json, e := json.MarshalIndent(struct {
|
||||
Status string `json:"status"`
|
||||
Error errorMessage `json:"error"`
|
||||
}{
|
||||
Status: "error",
|
||||
Error: errorMsg,
|
||||
})
|
||||
}, "", " ")
|
||||
if e != nil {
|
||||
console.Fatalln(probe.NewError(e))
|
||||
}
|
||||
@@ -135,13 +135,13 @@ func errorIf(err *probe.Error, msg string, data ...interface{}) {
|
||||
if globalDebug {
|
||||
errorMsg.CallTrace = err.CallTrace
|
||||
}
|
||||
json, e := json.Marshal(struct {
|
||||
json, e := json.MarshalIndent(struct {
|
||||
Status string `json:"status"`
|
||||
Error errorMessage `json:"error"`
|
||||
}{
|
||||
Status: "error",
|
||||
Error: errorMsg,
|
||||
})
|
||||
}, "", " ")
|
||||
if e != nil {
|
||||
console.Fatalln(probe.NewError(e))
|
||||
}
|
||||
|
||||
+2
-2
@@ -17,11 +17,11 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -88,7 +88,7 @@ type eventAddMessage struct {
|
||||
// JSON jsonified update message.
|
||||
func (u eventAddMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
eventAddMessageJSONBytes, e := json.Marshal(u)
|
||||
eventAddMessageJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
return string(eventAddMessageJSONBytes)
|
||||
}
|
||||
|
||||
+2
-2
@@ -17,11 +17,11 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -74,7 +74,7 @@ type eventListMessage struct {
|
||||
|
||||
func (u eventListMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
eventListMessageJSONBytes, e := json.Marshal(u)
|
||||
eventListMessageJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
return string(eventListMessageJSONBytes)
|
||||
}
|
||||
|
||||
+2
-2
@@ -17,11 +17,11 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -79,7 +79,7 @@ type eventRemoveMessage struct {
|
||||
// JSON jsonified remove message.
|
||||
func (u eventRemoveMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
eventRemoveMessageJSONBytes, e := json.Marshal(u)
|
||||
eventRemoveMessageJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
return string(eventRemoveMessageJSONBytes)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -25,6 +24,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -60,7 +60,7 @@ func (c contentMessage) String() string {
|
||||
// JSON jsonified content message.
|
||||
func (c contentMessage) JSON() string {
|
||||
c.Status = "success"
|
||||
jsonMessageBytes, e := json.Marshal(c)
|
||||
jsonMessageBytes, e := json.MarshalIndent(c, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(jsonMessageBytes)
|
||||
|
||||
+2
-3
@@ -17,10 +17,9 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -88,7 +87,7 @@ func (s makeBucketMessage) String() string {
|
||||
|
||||
// JSON jsonified make bucket message.
|
||||
func (s makeBucketMessage) JSON() string {
|
||||
makeBucketJSONBytes, e := json.Marshal(s)
|
||||
makeBucketJSONBytes, e := json.MarshalIndent(s, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(makeBucketJSONBytes)
|
||||
|
||||
+2
-2
@@ -18,7 +18,6 @@ package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
@@ -30,6 +29,7 @@ import (
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -210,7 +210,7 @@ func (m mirrorMessage) String() string {
|
||||
// JSON jsonified mirror message
|
||||
func (m mirrorMessage) JSON() string {
|
||||
m.Status = "success"
|
||||
mirrorMessageBytes, e := json.Marshal(m)
|
||||
mirrorMessageBytes, e := json.MarshalIndent(m, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(mirrorMessageBytes)
|
||||
|
||||
+4
-4
@@ -18,7 +18,6 @@ package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -27,6 +26,7 @@ import (
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -106,7 +106,7 @@ func (s policyRules) String() string {
|
||||
|
||||
// JSON jsonified policy message.
|
||||
func (s policyRules) JSON() string {
|
||||
policyJSONBytes, e := json.Marshal(s)
|
||||
policyJSONBytes, e := json.MarshalIndent(s, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
return string(policyJSONBytes)
|
||||
}
|
||||
@@ -139,7 +139,7 @@ func (s policyMessage) String() string {
|
||||
|
||||
// JSON jsonified policy message.
|
||||
func (s policyMessage) JSON() string {
|
||||
policyJSONBytes, e := json.Marshal(s)
|
||||
policyJSONBytes, e := json.MarshalIndent(s, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(policyJSONBytes)
|
||||
@@ -158,7 +158,7 @@ func (s policyLinksMessage) String() string {
|
||||
|
||||
// JSON jsonified policy message.
|
||||
func (s policyLinksMessage) JSON() string {
|
||||
policyJSONBytes, e := json.Marshal(s)
|
||||
policyJSONBytes, e := json.MarshalIndent(s, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(policyJSONBytes)
|
||||
|
||||
+2
-2
@@ -18,7 +18,6 @@ package cmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -27,6 +26,7 @@ import (
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -134,7 +134,7 @@ func (r rmMessage) String() string {
|
||||
|
||||
// JSON'ified message for scripting.
|
||||
func (r rmMessage) JSON() string {
|
||||
msgBytes, e := json.Marshal(r)
|
||||
msgBytes, e := json.MarshalIndent(r, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
return string(msgBytes)
|
||||
}
|
||||
|
||||
@@ -17,10 +17,9 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -82,7 +81,7 @@ func (c clearSessionMessage) String() string {
|
||||
|
||||
// JSON jsonified clear session message.
|
||||
func (c clearSessionMessage) JSON() string {
|
||||
clearSessionJSONBytes, e := json.Marshal(c)
|
||||
clearSessionJSONBytes, e := json.MarshalIndent(c, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(clearSessionJSONBytes)
|
||||
|
||||
+2
-2
@@ -19,7 +19,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -28,6 +27,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio/pkg/quick"
|
||||
@@ -98,7 +98,7 @@ func (s sessionV8) JSON() string {
|
||||
CommandArgs: s.Header.CommandArgs,
|
||||
}
|
||||
sessionMsg.Status = "success"
|
||||
sessionBytes, e := json.Marshal(sessionMsg)
|
||||
sessionBytes, e := json.MarshalIndent(sessionMsg, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(sessionBytes)
|
||||
|
||||
+2
-2
@@ -18,7 +18,6 @@ package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -27,6 +26,7 @@ import (
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -79,7 +79,7 @@ func (s shareMesssage) String() string {
|
||||
// JSON - JSONified message for scripting.
|
||||
func (s shareMesssage) JSON() string {
|
||||
s.Status = "success"
|
||||
shareMessageBytes, e := json.Marshal(s)
|
||||
shareMessageBytes, e := json.MarshalIndent(s, "", " ")
|
||||
fatalIf(probe.NewError(e), "Failed to marshal into JSON.")
|
||||
|
||||
// JSON encoding escapes ampersand into its unicode character
|
||||
|
||||
+2
-2
@@ -17,13 +17,13 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -82,7 +82,7 @@ func printStat(stat statMessage) {
|
||||
// JSON jsonified content message.
|
||||
func (c statMessage) JSON() string {
|
||||
c.Status = "success"
|
||||
jsonMessageBytes, e := json.Marshal(c)
|
||||
jsonMessageBytes, e := json.MarshalIndent(c, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(jsonMessageBytes)
|
||||
|
||||
+2
-2
@@ -19,7 +19,6 @@ package cmd
|
||||
import (
|
||||
"crypto"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -33,6 +32,7 @@ import (
|
||||
"github.com/inconshreveable/go-update"
|
||||
isatty "github.com/mattn/go-isatty"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
_ "github.com/minio/sha256-simd" // Needed for sha256 hash verifier.
|
||||
"github.com/segmentio/go-prompt"
|
||||
@@ -450,7 +450,7 @@ func (s updateMessage) String() string {
|
||||
|
||||
// JSON jsonified make bucket message.
|
||||
func (s updateMessage) JSON() string {
|
||||
updateJSONBytes, e := json.Marshal(s)
|
||||
updateJSONBytes, e := json.MarshalIndent(s, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(updateJSONBytes)
|
||||
|
||||
+2
-2
@@ -17,11 +17,11 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -78,7 +78,7 @@ func (v versionMessage) String() string {
|
||||
// JSON'ified message for scripting.
|
||||
func (v versionMessage) JSON() string {
|
||||
v.Status = "success"
|
||||
msgBytes, e := json.Marshal(v)
|
||||
msgBytes, e := json.MarshalIndent(v, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
return string(msgBytes)
|
||||
}
|
||||
|
||||
+2
-2
@@ -17,7 +17,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -27,6 +26,7 @@ import (
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/mc/pkg/colorjson"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
@@ -111,7 +111,7 @@ type watchMessage struct {
|
||||
|
||||
func (u watchMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
watchMessageJSONBytes, e := json.Marshal(u)
|
||||
watchMessageJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
return string(watchMessageJSONBytes)
|
||||
}
|
||||
|
||||
+11
-1
@@ -106,7 +106,17 @@ import (
|
||||
// character U+FFFD.
|
||||
//
|
||||
func Unmarshal(data []byte, v interface{}) error {
|
||||
panic("unmarshalling is not supported by colorjson")
|
||||
// Check for well-formedness.
|
||||
// Avoids filling out half a data structure
|
||||
// before discovering a JSON syntax error.
|
||||
var d decodeState
|
||||
err := checkValid(data, &d.scan)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.init(data)
|
||||
return d.unmarshal(v)
|
||||
}
|
||||
|
||||
// Unmarshaler is the interface implemented by types
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -36,6 +37,7 @@ import (
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
)
|
||||
|
||||
@@ -194,6 +196,9 @@ func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !isatty.IsTerminal(os.Stdout.Fd()) {
|
||||
return b, err
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
err = Indent(&buf, b, prefix, indent)
|
||||
if err != nil {
|
||||
@@ -622,7 +627,7 @@ func stringEncoder(e *encodeState, v reflect.Value, opts encOpts) {
|
||||
return
|
||||
}
|
||||
if opts.quoted {
|
||||
sb, err := Marshal(console.Colorize(jsonString, v.String()))
|
||||
sb, err := Marshal(v.String())
|
||||
if err != nil {
|
||||
e.error(err)
|
||||
}
|
||||
@@ -882,7 +887,7 @@ type reflectWithString struct {
|
||||
|
||||
func (w *reflectWithString) resolve() error {
|
||||
if w.v.Kind() == reflect.String {
|
||||
w.s = console.Colorize(jsonString, w.v.String())
|
||||
w.s = w.v.String()
|
||||
return nil
|
||||
}
|
||||
if tm, ok := w.v.Interface().(encoding.TextMarshaler); ok {
|
||||
@@ -892,10 +897,10 @@ func (w *reflectWithString) resolve() error {
|
||||
}
|
||||
switch w.v.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
w.s = console.Colorize(jsonNum, strconv.FormatInt(w.v.Int(), 10))
|
||||
w.s = strconv.FormatInt(w.v.Int(), 10)
|
||||
return nil
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
w.s = console.Colorize(jsonNum, strconv.FormatUint(w.v.Uint(), 10))
|
||||
w.s = strconv.FormatUint(w.v.Uint(), 10)
|
||||
return nil
|
||||
}
|
||||
panic("unexpected map key type")
|
||||
|
||||
Reference in New Issue
Block a user