diff --git a/cmd-cp.go b/cmd-cp.go index 1793ac89..fdac8438 100644 --- a/cmd-cp.go +++ b/cmd-cp.go @@ -90,7 +90,7 @@ func doCopy(cpURLs copyURLs, bar *barSend, cpQueue chan bool, wg *sync.WaitGroup var newReader io.ReadCloser if globalQuietFlag || globalJSONFlag { - console.Infoln(CopyMessage{ + console.PrintC(CopyMessage{ Source: cpURLs.SourceContent.Name, Target: cpURLs.TargetContent.Name, Length: cpURLs.SourceContent.Size, diff --git a/cmd-session.go b/cmd-session.go index b52ec987..23a68314 100644 --- a/cmd-session.go +++ b/cmd-session.go @@ -62,7 +62,7 @@ func listSessions() error { if err != nil { return NewIodine(iodine.New(err, nil)) } - console.Prints(s) + console.Print(s) } return nil } diff --git a/cmd-sync.go b/cmd-sync.go index aacc5d07..b93e0996 100644 --- a/cmd-sync.go +++ b/cmd-sync.go @@ -93,7 +93,7 @@ func doSync(sURLs syncURLs, bar *barSend, syncQueue chan bool, wg *sync.WaitGrou var newReader io.ReadCloser if globalQuietFlag || globalJSONFlag { - console.Infoln(SyncMessage{ + console.PrintC(SyncMessage{ Source: sURLs.SourceContent.Name, Targets: targetURLs, }) diff --git a/ls.go b/ls.go index 89f53dbe..2452e2fe 100644 --- a/ls.go +++ b/ls.go @@ -89,7 +89,7 @@ func doList(clnt client.Client, recursive bool) error { err = contentCh.Err break } - console.Prints(parseContent(contentCh.Content)) + console.Print(parseContent(contentCh.Content)) } if err != nil { return NewIodine(iodine.New(err, map[string]string{"Target": clnt.URL().String()})) diff --git a/pb.go b/pb.go index 6fb4074a..e832e979 100644 --- a/pb.go +++ b/pb.go @@ -158,7 +158,8 @@ func newCpBar() barSend { if runtime.GOOS == "windows" { bar.Format("[=> ]") } else { - bar.Format("┃▒▓░┃") + bar.Format("┃▓█░┃") + // bar.Format("█▓▒░█") } for msg := range cmdCh { switch msg.Cmd { diff --git a/pkg/console/console.go b/pkg/console/console.go index 5c9c93cc..9c97a446 100644 --- a/pkg/console/console.go +++ b/pkg/console/console.go @@ -100,11 +100,6 @@ var ( println(themesDB[currThemeName].Print, data...) } - // Prints prints a structured message with a newline - Prints = func(data ...interface{}) { - println(themesDB[currThemeName].Print, data...) - return - } // Fatal print a error message and exit Fatal = func(data ...interface{}) { defer os.Exit(1) @@ -196,6 +191,8 @@ var ( Command = themesDB[currThemeName].Command.SprintfFunc() // SessionID helper to print sessionid theme SessionID = themesDB[currThemeName].SessionID.SprintfFunc() + // JSON helper to print json strings + JSON = themesDB[currThemeName].JSON.SprintfFunc() ) var ( diff --git a/print-structs.go b/print-structs.go index 5f3b9c47..5a17b985 100644 --- a/print-structs.go +++ b/print-structs.go @@ -20,12 +20,44 @@ package main import ( "encoding/json" "fmt" + "strings" "github.com/minio/mc/pkg/console" ) +// SessionJSONMessage json container for session messages +type SessionJSONMessage struct { + Version string `json:"version"` + SessionID string `json:"sessionid"` + Time string `json:"time"` + CommandType string `json:"command-type"` + CommandArgs []string `json:"command-args"` +} + +func (s sessionV2) String() string { + if !globalJSONFlag { + message := console.SessionID("%s -> ", s.SessionID) + message = message + console.Time("[%s]", s.Header.When.Local().Format(printDate)) + message = message + console.Command(" %s %s", s.Header.CommandType, strings.Join(s.Header.CommandArgs, " ")) + return message + "\n" + } + sessionMesage := SessionJSONMessage{ + Version: s.Header.Version, + SessionID: s.SessionID, + Time: s.Header.When.Local().Format(printDate), + CommandType: s.Header.CommandType, + CommandArgs: s.Header.CommandArgs, + } + sessionJSONBytes, err := json.MarshalIndent(sessionMesage, "", "\t") + if err != nil { + panic(err) + } + return console.JSON(string(sessionJSONBytes) + "\n") +} + // Content container for content message structure type Content struct { + Version string `json:"version"` Filetype string `json:"type"` Time string `json:"last-modified"` Size string `json:"size"` @@ -43,36 +75,40 @@ func (c Content) String() string { } return message + console.File("%s", c.Name) }() - return message + return message + "\n" } - cBytes, err := json.Marshal(c) + c.Version = "1.0.0" + jsonMessageBytes, err := json.MarshalIndent(c, "", "\t") if err != nil { panic(err) } - return string(cBytes) + return console.JSON(string(jsonMessageBytes) + "\n") } // CopyMessage container for file copy messages type CopyMessage struct { - Source string `json:"source"` - Target string `json:"target"` - Length int64 `json:"length"` + Version string `json:"version"` + Source string `json:"source"` + Target string `json:"target"` + Length int64 `json:"length"` } // String string printer for copy message func (c CopyMessage) String() string { if !globalJSONFlag { - return fmt.Sprintf("‘%s’ -> ‘%s’", c.Source, c.Target) + return fmt.Sprintf("‘%s’ -> ‘%s’\n", c.Source, c.Target) } - cBytes, err := json.Marshal(c) + c.Version = "1.0.0" + copyMessageBytes, err := json.MarshalIndent(c, "", "\t") if err != nil { panic(err) } - return string(cBytes) + return console.JSON(string(copyMessageBytes) + "\n") } // SyncMessage container for file sync messages, inherits CopyMessage type SyncMessage struct { + Version string `json:"version"` Source string `json:"source"` Targets []string `json:"targets"` Length int64 `json:"length"` @@ -81,11 +117,12 @@ type SyncMessage struct { // String string printer for sync message func (s SyncMessage) String() string { if !globalJSONFlag { - return fmt.Sprintf("‘%s’ -> ‘%s’", s.Source, s.Targets) + return fmt.Sprintf("‘%s’ -> ‘%s’\n", s.Source, s.Targets) } - sBytes, err := json.Marshal(s) + s.Version = "1.0.0" + syncMessageBytes, err := json.MarshalIndent(s, "", "\t") if err != nil { panic(err) } - return string(sBytes) + return console.JSON(string(syncMessageBytes) + "\n") } diff --git a/session-v2.go b/session-v2.go index 6d6a336a..cad9af99 100644 --- a/session-v2.go +++ b/session-v2.go @@ -21,7 +21,6 @@ package main import ( "io" "os" - "strings" "sync" "time" @@ -83,19 +82,12 @@ func newSessionV2() *sessionV2 { return s } -func (s *sessionV2) String() string { - message := console.SessionID("%s -> ", s.SessionID) - message = message + console.Time("[%s]", s.Header.When.Local().Format(printDate)) - message = message + console.Command(" %s %s", s.Header.CommandType, strings.Join(s.Header.CommandArgs, " ")) - return message -} - -func (s *sessionV2) Info() { +func (s sessionV2) Info() { console.Infoln("Session terminated. To resume session type ‘mc session resume " + s.SessionID + "’") } // NewDataReader provides reader interface to session data file. -func (s *sessionV2) HasData() bool { +func (s sessionV2) HasData() bool { if s.Header.LastCopied == "" { return false }