From 46bf1af56c6fb925b35080a897d01b27bfec0603 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 30 Jun 2015 10:26:48 -0700 Subject: [PATCH] Treating --json as quiet mode for cp and sync operations --- cmd-cp.go | 3 ++- cmd-sync.go | 7 +++---- print-structs.go | 22 +++++++++++++--------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/cmd-cp.go b/cmd-cp.go index ace24658..9112e20e 100644 --- a/cmd-cp.go +++ b/cmd-cp.go @@ -93,11 +93,12 @@ func doCopySession(cURLs cpURLs, bar *barSend, s *sessionV1) error { defer reader.Close() var newReader io.Reader - switch globalQuietFlag { + switch globalQuietFlag || globalJSONFlag { case true: console.Infos(CopyMessage{ Source: cURLs.SourceContent.Name, Target: cURLs.TargetContent.Name, + Length: cURLs.SourceContent.Size, }) newReader = yielder.NewReader(reader) default: diff --git a/cmd-sync.go b/cmd-sync.go index 994a94f2..0d77ebb5 100644 --- a/cmd-sync.go +++ b/cmd-sync.go @@ -23,7 +23,6 @@ import ( "os" "os/signal" "runtime" - "strings" "sync" "github.com/minio/cli" @@ -108,11 +107,11 @@ func doSyncSession(sURLs syncURLs, bar *barSend, syncQueue chan bool, ssCh chan } var newReader io.Reader - switch globalQuietFlag { + switch globalQuietFlag || globalJSONFlag { case true: console.Infos(SyncMessage{ - Source: sURLs.SourceContent.Name, - Target: strings.Join(targetURLs, " "), + Source: sURLs.SourceContent.Name, + Targets: targetURLs, }) newReader = yielder.NewReader(reader) default: diff --git a/print-structs.go b/print-structs.go index f8fda1c8..de47a27a 100644 --- a/print-structs.go +++ b/print-structs.go @@ -26,7 +26,7 @@ import ( // ErrorMessage container for error reason encapsulation type ErrorMessage struct { - Message string `json:"message"` + Message string `json:"-"` Error error `json:"error"` } @@ -37,10 +37,10 @@ func (e ErrorMessage) String() string { switch e.Error.(type) { case iodine.Error: reason := iodine.ToError(e.Error).Error() - message = e.Message + ", " + reason + message = reason default: reason := e.Error.Error() - message = e.Message + ", " + reason + message = reason } } return message @@ -69,7 +69,7 @@ func (c Content) String() string { // InfoMessage container for informational messages type InfoMessage struct { - Message string `json:"message"` + Message string `json:"info"` } // String string printer for informational message @@ -79,9 +79,9 @@ func (i InfoMessage) String() string { // CopyMessage container for file copy messages type CopyMessage struct { - Message string `json:"message"` - Source string `json:"source"` - Target string `json:"target"` + Source string `json:"source"` + Target string `json:"target"` + Length int64 `json:"length"` } // String string printer for copy message @@ -90,9 +90,13 @@ func (c CopyMessage) String() string { } // SyncMessage container for file sync messages, inherits CopyMessage -type SyncMessage CopyMessage +type SyncMessage struct { + Source string `json:"source"` + Targets []string `json:"targets"` + Length int64 `json:"length"` +} // String string printer for sync message func (s SyncMessage) String() string { - return fmt.Sprintf("‘%s’ -> ‘%s’", s.Source, s.Target) + return fmt.Sprintf("‘%s’ -> ‘%s’", s.Source, s.Targets) }