Merge pull request #1008 from harshavardhana/remove_indent
Remove json indent for easing parsing
This commit is contained in:
@@ -31,7 +31,6 @@ func fatalIf(err *probe.Error) {
|
||||
}
|
||||
if globalJSONFlag {
|
||||
errorMessage := struct {
|
||||
// Error string `json:"error"`
|
||||
Cause error `json:"cause"`
|
||||
Type string `json:"type"`
|
||||
CallTrace []probe.TracePoint `json:"trace,omitempty"`
|
||||
@@ -44,7 +43,10 @@ func fatalIf(err *probe.Error) {
|
||||
if globalDebugFlag {
|
||||
errorMessage.CallTrace = err.CallTrace
|
||||
}
|
||||
json, _ := json.Marshal(errorMessage)
|
||||
json, err := json.Marshal(errorMessage)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
console.Println(string(json))
|
||||
os.Exit(1)
|
||||
}
|
||||
@@ -61,7 +63,6 @@ func errorIf(err *probe.Error) {
|
||||
}
|
||||
if globalJSONFlag {
|
||||
errorMessage := struct {
|
||||
// Error string `json:"error"`
|
||||
Cause error `json:"cause"`
|
||||
Type string `json:"type"`
|
||||
CallTrace []probe.TracePoint `json:"trace,omitempty"`
|
||||
@@ -74,12 +75,16 @@ func errorIf(err *probe.Error) {
|
||||
if globalDebugFlag {
|
||||
errorMessage.CallTrace = err.CallTrace
|
||||
}
|
||||
json, _ := json.Marshal(errorMessage)
|
||||
json, err := json.Marshal(errorMessage)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
console.Println(string(json))
|
||||
return
|
||||
}
|
||||
if !globalDebugFlag {
|
||||
console.Errorln(err.ToGoError())
|
||||
return
|
||||
}
|
||||
console.Errorln(err)
|
||||
}
|
||||
|
||||
@@ -53,7 +53,6 @@ type Theme struct {
|
||||
Dir *color.Color
|
||||
Command *color.Color
|
||||
SessionID *color.Color
|
||||
JSON *color.Color
|
||||
Bar *color.Color
|
||||
PrintC *color.Color
|
||||
Print *color.Color
|
||||
@@ -258,14 +257,6 @@ var (
|
||||
}
|
||||
return fmt.Sprintf(format, data...)
|
||||
}
|
||||
|
||||
// JSON helper to print json strings
|
||||
JSON = func(format string, data ...interface{}) string {
|
||||
if isatty.IsTerminal(os.Stdout.Fd()) {
|
||||
return themesDB[currThemeName].JSON.SprintfFunc()(format, data...)
|
||||
}
|
||||
return fmt.Sprintf(format, data...)
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -30,7 +30,6 @@ var MiniTheme = Theme{
|
||||
SessionID: (color.New(color.FgYellow, color.Bold)),
|
||||
Size: (color.New(color.FgYellow)),
|
||||
Time: (color.New(color.FgGreen)),
|
||||
JSON: (color.New(color.FgWhite, color.Italic)),
|
||||
Bar: (color.New(color.FgGreen, color.Bold)),
|
||||
PrintC: (color.New(color.FgGreen, color.Bold)),
|
||||
Print: (color.New()),
|
||||
@@ -48,7 +47,6 @@ var WhiteTheme = Theme{
|
||||
SessionID: (color.New(color.FgWhite, color.Bold)),
|
||||
Size: (color.New(color.FgWhite, color.Bold)),
|
||||
Time: (color.New(color.FgWhite, color.Bold)),
|
||||
JSON: (color.New(color.FgWhite, color.Bold, color.Italic)),
|
||||
Bar: (color.New(color.FgWhite, color.Bold)),
|
||||
PrintC: (color.New(color.FgWhite, color.Bold)),
|
||||
Print: (color.New()),
|
||||
@@ -66,7 +64,6 @@ var NoColorTheme = Theme{
|
||||
SessionID: new(color.Color),
|
||||
Size: new(color.Color),
|
||||
Time: new(color.Color),
|
||||
JSON: new(color.Color),
|
||||
Bar: new(color.Color),
|
||||
PrintC: new(color.Color),
|
||||
Print: new(color.Color),
|
||||
|
||||
+12
-12
@@ -52,11 +52,11 @@ func (s diffV1) String() string {
|
||||
diffMessage.FirstURL = s.firstURL
|
||||
diffMessage.SecondURL = s.secondURL
|
||||
diffMessage.Diff = s.diffType
|
||||
diffJSONBytes, err := json.MarshalIndent(diffMessage, "", "\t")
|
||||
diffJSONBytes, err := json.Marshal(diffMessage)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return console.JSON(string(diffJSONBytes) + "\n")
|
||||
return string(diffJSONBytes) + "\n"
|
||||
}
|
||||
|
||||
// SessionJSONMessage json container for session messages
|
||||
@@ -80,11 +80,11 @@ func (s sessionV2) String() string {
|
||||
CommandType: s.Header.CommandType,
|
||||
CommandArgs: s.Header.CommandArgs,
|
||||
}
|
||||
sessionJSONBytes, err := json.MarshalIndent(sessionMesage, "", "\t")
|
||||
sessionJSONBytes, err := json.Marshal(sessionMesage)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return console.JSON(string(sessionJSONBytes) + "\n")
|
||||
return string(sessionJSONBytes) + "\n"
|
||||
}
|
||||
|
||||
// ContentMessage container for content message structure
|
||||
@@ -108,11 +108,11 @@ func (c ContentMessage) String() string {
|
||||
}()
|
||||
return message + "\n"
|
||||
}
|
||||
jsonMessageBytes, err := json.MarshalIndent(c, "", "\t")
|
||||
jsonMessageBytes, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return console.JSON(string(jsonMessageBytes) + "\n")
|
||||
return string(jsonMessageBytes) + "\n"
|
||||
}
|
||||
|
||||
// CopyMessage container for file copy messages
|
||||
@@ -127,11 +127,11 @@ func (c CopyMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
return fmt.Sprintf("‘%s’ -> ‘%s’\n", c.Source, c.Target)
|
||||
}
|
||||
copyMessageBytes, err := json.MarshalIndent(c, "", "\t")
|
||||
copyMessageBytes, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return console.JSON(string(copyMessageBytes) + "\n")
|
||||
return string(copyMessageBytes) + "\n"
|
||||
}
|
||||
|
||||
// MirrorMessage container for file mirror messages
|
||||
@@ -146,11 +146,11 @@ func (s MirrorMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
return fmt.Sprintf("‘%s’ -> ‘%s’\n", s.Source, s.Targets)
|
||||
}
|
||||
mirrorMessageBytes, err := json.MarshalIndent(s, "", "\t")
|
||||
mirrorMessageBytes, err := json.Marshal(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return console.JSON(string(mirrorMessageBytes) + "\n")
|
||||
return string(mirrorMessageBytes) + "\n"
|
||||
}
|
||||
|
||||
// ShareMessage container for share messages
|
||||
@@ -164,12 +164,12 @@ func (s ShareMessage) String() string {
|
||||
if !globalJSONFlag {
|
||||
return fmt.Sprintf("Succesfully generated shared URL with expiry %s, please share: %s\n", s.Expires, s.PresignedURL)
|
||||
}
|
||||
shareMessageBytes, err := json.MarshalIndent(s, "", "\t")
|
||||
shareMessageBytes, err := json.Marshal(s)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// json encoding escapes ampersand into its unicode character which is not usable directly for share
|
||||
// and fails with cloud storage. convert them back so that they are usable
|
||||
shareMessageBytes = bytes.Replace(shareMessageBytes, []byte("\\u0026"), []byte("&"), -1)
|
||||
return console.JSON("%s\n", string(shareMessageBytes))
|
||||
return fmt.Sprintf("%s\n", string(shareMessageBytes))
|
||||
}
|
||||
|
||||
+6
-4
@@ -58,13 +58,15 @@ func mainVersion(ctxx *cli.Context) {
|
||||
Format string `json:"format"`
|
||||
}
|
||||
if globalJSONFlag {
|
||||
tB, err := json.MarshalIndent(struct {
|
||||
Version Version `json:"version"`
|
||||
}{Version: Version{t, "RFC3339Nano"}}, "", "\t")
|
||||
tB, err := json.Marshal(
|
||||
struct {
|
||||
Version Version `json:"version"`
|
||||
}{Version: Version{t, "RFC3339Nano"}},
|
||||
)
|
||||
if err != nil {
|
||||
console.Fatalln(probe.NewError(err))
|
||||
}
|
||||
console.Println(console.JSON(string(tB)))
|
||||
console.Println(string(tB))
|
||||
return
|
||||
}
|
||||
console.Println(t.Format(http.TimeFormat))
|
||||
|
||||
Reference in New Issue
Block a user