Move coloring to their own main* functions
This commit is contained in:
@@ -17,7 +17,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/probe"
|
||||
)
|
||||
|
||||
@@ -79,6 +81,12 @@ func mainList(ctx *cli.Context) {
|
||||
} else if !ctx.Args().Present() || ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "ls", 1) // last argument is exit code
|
||||
}
|
||||
console.SetCustomTheme(map[string]*color.Color{
|
||||
"File": color.New(color.FgWhite),
|
||||
"Dir": color.New(color.FgCyan, color.Bold),
|
||||
"Size": color.New(color.FgYellow),
|
||||
"Time": color.New(color.FgGreen),
|
||||
})
|
||||
|
||||
config := mustGetMcConfig()
|
||||
for _, arg := range args {
|
||||
|
||||
+7
-13
@@ -43,19 +43,13 @@ var IsError = false
|
||||
|
||||
// Theme default map
|
||||
var Theme = map[string]*color.Color{
|
||||
"Debug": color.New(color.FgWhite, color.Faint, color.Italic),
|
||||
"Fatal": color.New(color.FgRed, color.Italic, color.Bold),
|
||||
"Error": color.New(color.FgYellow, color.Italic),
|
||||
"Info": color.New(color.FgGreen, color.Bold),
|
||||
"File": color.New(color.FgWhite),
|
||||
"Dir": color.New(color.FgCyan, color.Bold),
|
||||
"Command": color.New(color.FgWhite, color.Bold),
|
||||
"SessionID": color.New(color.FgYellow, color.Bold),
|
||||
"Size": color.New(color.FgYellow),
|
||||
"Time": color.New(color.FgGreen),
|
||||
"Bar": color.New(color.FgGreen, color.Bold),
|
||||
"Print": color.New(),
|
||||
"PrintC": color.New(color.FgGreen, color.Bold),
|
||||
"Debug": color.New(color.FgWhite, color.Faint, color.Italic),
|
||||
"Fatal": color.New(color.FgRed, color.Italic, color.Bold),
|
||||
"Error": color.New(color.FgYellow, color.Italic),
|
||||
"Info": color.New(color.FgGreen, color.Bold),
|
||||
"Bar": color.New(color.FgGreen, color.Bold),
|
||||
"Print": color.New(),
|
||||
"PrintC": color.New(color.FgGreen, color.Bold),
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/probe"
|
||||
@@ -122,6 +123,12 @@ func mainSession(ctx *cli.Context) {
|
||||
if !isSessionDirExists() {
|
||||
fatalIf(createSessionDir().Trace(), "Unable to create session directory.")
|
||||
}
|
||||
console.SetCustomTheme(map[string]*color.Color{
|
||||
"Command": color.New(color.FgWhite, color.Bold),
|
||||
"SessionID": color.New(color.FgYellow, color.Bold),
|
||||
"SessionTime": color.New(color.FgGreen),
|
||||
})
|
||||
|
||||
switch strings.TrimSpace(ctx.Args().First()) {
|
||||
// list resumable sessions
|
||||
case "list":
|
||||
|
||||
+6
-6
@@ -56,8 +56,8 @@ type sessionV2Header struct {
|
||||
TotalObjects int `json:"total-objects"`
|
||||
}
|
||||
|
||||
// SessionJSONMessage json container for session messages
|
||||
type SessionJSONMessage struct {
|
||||
// SessionMessage container for session messages
|
||||
type SessionMessage struct {
|
||||
SessionID string `json:"sessionid"`
|
||||
Time time.Time `json:"time"`
|
||||
CommandType string `json:"command-type"`
|
||||
@@ -76,20 +76,20 @@ type sessionV2 struct {
|
||||
func (s sessionV2) String() string {
|
||||
if !globalJSONFlag {
|
||||
message := console.Colorize("SessionID", fmt.Sprintf("%s -> ", s.SessionID))
|
||||
message = message + console.Colorize("Time", fmt.Sprintf("[%s]", s.Header.When.Local().Format(printDate)))
|
||||
message = message + console.Colorize("SessionTime", fmt.Sprintf("[%s]", s.Header.When.Local().Format(printDate)))
|
||||
message = message + console.Colorize("Command", fmt.Sprintf(" %s %s", s.Header.CommandType, strings.Join(s.Header.CommandArgs, " ")))
|
||||
return message
|
||||
}
|
||||
sessionMesage := SessionJSONMessage{
|
||||
sessionMesage := SessionMessage{
|
||||
SessionID: s.SessionID,
|
||||
Time: s.Header.When.Local(),
|
||||
CommandType: s.Header.CommandType,
|
||||
CommandArgs: s.Header.CommandArgs,
|
||||
}
|
||||
sessionJSONBytes, e := json.Marshal(sessionMesage)
|
||||
sessionBytes, e := json.Marshal(sessionMesage)
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(sessionJSONBytes)
|
||||
return string(sessionBytes)
|
||||
}
|
||||
|
||||
// newSessionV2 provides a new session
|
||||
|
||||
Reference in New Issue
Block a user