Prints cleanup
This commit is contained in:
+6
-6
@@ -59,8 +59,8 @@ EXAMPLES:
|
||||
`,
|
||||
}
|
||||
|
||||
// AccessMessage is container for access command on bucket success and failure messages
|
||||
type AccessMessage struct {
|
||||
// accessMessage is container for access command on bucket success and failure messages
|
||||
type accessMessage struct {
|
||||
Operation string `json:"operation"`
|
||||
Status string `json:"status"`
|
||||
Bucket string `json:"bucket"`
|
||||
@@ -68,7 +68,7 @@ type AccessMessage struct {
|
||||
}
|
||||
|
||||
// String colorized access message
|
||||
func (s AccessMessage) String() string {
|
||||
func (s accessMessage) String() string {
|
||||
if s.Operation == "set" {
|
||||
return console.Colorize("Access", "Set access permission ‘"+string(s.Perms)+"’ updated successfully for ‘"+s.Bucket+"’")
|
||||
}
|
||||
@@ -80,7 +80,7 @@ func (s AccessMessage) String() string {
|
||||
}
|
||||
|
||||
// JSON jsonified access message
|
||||
func (s AccessMessage) JSON() string {
|
||||
func (s accessMessage) JSON() string {
|
||||
accessJSONBytes, err := json.Marshal(s)
|
||||
fatalIf(probe.NewError(err), "Unable to marshal into JSON.")
|
||||
|
||||
@@ -146,7 +146,7 @@ func mainAccess(ctx *cli.Context) {
|
||||
|
||||
fatalIf(doSetAccess(targetURL, perms).Trace(targetURL, string(perms)), "Unable to set access permission ‘"+string(perms)+"’ for ‘"+targetURL+"’.")
|
||||
|
||||
Prints("%s\n", AccessMessage{
|
||||
printMsg(accessMessage{
|
||||
Operation: "set",
|
||||
Status: "success",
|
||||
Bucket: targetURL,
|
||||
@@ -159,7 +159,7 @@ func mainAccess(ctx *cli.Context) {
|
||||
perms, err := doGetAccess(targetURL)
|
||||
fatalIf(err.Trace(targetURL), "Unable to get access permission for ‘"+targetURL+"’.")
|
||||
|
||||
Prints("%s\n", AccessMessage{
|
||||
printMsg(accessMessage{
|
||||
Operation: "get",
|
||||
Status: "success",
|
||||
Bucket: targetURL,
|
||||
|
||||
+7
-18
@@ -56,15 +56,15 @@ EXAMPLES:
|
||||
`,
|
||||
}
|
||||
|
||||
// AliasMessage container for content message structure
|
||||
type AliasMessage struct {
|
||||
// aliasMessage container for content message structure
|
||||
type aliasMessage struct {
|
||||
op string
|
||||
Alias string `json:"alias"`
|
||||
URL string `json:"url,omitempty"`
|
||||
}
|
||||
|
||||
// String colorized alias message
|
||||
func (a AliasMessage) String() string {
|
||||
func (a aliasMessage) String() string {
|
||||
if a.op == "list" {
|
||||
message := console.Colorize("Alias", fmt.Sprintf("[%s] <- ", a.Alias))
|
||||
message += console.Colorize("URL", fmt.Sprintf("%s", a.URL))
|
||||
@@ -81,7 +81,7 @@ func (a AliasMessage) String() string {
|
||||
}
|
||||
|
||||
// JSON jsonified alias message
|
||||
func (a AliasMessage) JSON() string {
|
||||
func (a aliasMessage) JSON() string {
|
||||
jsonMessageBytes, e := json.Marshal(a)
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
@@ -165,11 +165,7 @@ func listAliases() {
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV5)
|
||||
for k, v := range newConf.Aliases {
|
||||
Prints("%s\n", AliasMessage{
|
||||
op: "list",
|
||||
Alias: k,
|
||||
URL: v,
|
||||
})
|
||||
printMsg(aliasMessage{op: "list", Alias: k, URL: v})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,10 +196,7 @@ func removeAlias(alias string) {
|
||||
err = writeConfig(newConfig)
|
||||
fatalIf(err.Trace(alias), "Unable to save alias ‘"+alias+"’.")
|
||||
|
||||
Prints("%s\n", AliasMessage{
|
||||
op: "remove",
|
||||
Alias: alias,
|
||||
})
|
||||
printMsg(aliasMessage{op: "remove", Alias: alias})
|
||||
}
|
||||
|
||||
// addAlias - add new aliases
|
||||
@@ -236,9 +229,5 @@ func addAlias(alias, url string) {
|
||||
err = writeConfig(newConfig)
|
||||
fatalIf(err.Trace(alias, url), "Unable to save alias ‘"+alias+"’.")
|
||||
|
||||
Prints("%s\n", AliasMessage{
|
||||
op: "add",
|
||||
Alias: alias,
|
||||
URL: url,
|
||||
})
|
||||
printMsg(aliasMessage{op: "add", Alias: alias, URL: url})
|
||||
}
|
||||
|
||||
+7
-17
@@ -45,8 +45,8 @@ EXAMPLES:
|
||||
`,
|
||||
}
|
||||
|
||||
// HostMessage container for content message structure
|
||||
type HostMessage struct {
|
||||
// hostMessage container for content message structure
|
||||
type hostMessage struct {
|
||||
op string
|
||||
Host string `json:"host"`
|
||||
AccessKeyID string `json:"accessKeyId,omitempty"`
|
||||
@@ -55,7 +55,7 @@ type HostMessage struct {
|
||||
}
|
||||
|
||||
// String colorized host message
|
||||
func (a HostMessage) String() string {
|
||||
func (a hostMessage) String() string {
|
||||
if a.op == "list" {
|
||||
message := console.Colorize("Host", fmt.Sprintf("[%s] ", a.Host))
|
||||
if a.AccessKeyID != "" || a.SecretAccessKey != "" {
|
||||
@@ -76,7 +76,7 @@ func (a HostMessage) String() string {
|
||||
}
|
||||
|
||||
// JSON jsonified host message
|
||||
func (a HostMessage) JSON() string {
|
||||
func (a hostMessage) JSON() string {
|
||||
jsonMessageBytes, e := json.Marshal(a)
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
@@ -163,15 +163,8 @@ func listHosts() {
|
||||
// convert interface{} back to its original struct
|
||||
newConf := config.Data().(*configV5)
|
||||
for k, v := range newConf.Hosts {
|
||||
Prints("%s\n", HostMessage{
|
||||
op: "list",
|
||||
Host: k,
|
||||
AccessKeyID: v.AccessKeyID,
|
||||
SecretAccessKey: v.SecretAccessKey,
|
||||
API: v.API,
|
||||
})
|
||||
printMsg(hostMessage{op: "list", Host: k, AccessKeyID: v.AccessKeyID, SecretAccessKey: v.SecretAccessKey, API: v.API})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func removeHost(hostGlob string) {
|
||||
@@ -200,10 +193,7 @@ func removeHost(hostGlob string) {
|
||||
err = writeConfig(newConfig)
|
||||
fatalIf(err.Trace(hostGlob), "Unable to save host glob ‘"+hostGlob+"’.")
|
||||
|
||||
Prints("%s\n", HostMessage{
|
||||
op: "remove",
|
||||
Host: hostGlob,
|
||||
})
|
||||
printMsg(hostMessage{op: "remove", Host: hostGlob})
|
||||
}
|
||||
|
||||
// isValidSecretKey - validate secret key
|
||||
@@ -265,7 +255,7 @@ func addHost(hostGlob, accessKeyID, secretAccessKey, api string) {
|
||||
err = writeConfig(newConfig)
|
||||
fatalIf(err.Trace(hostGlob), "Unable to save host glob ‘"+hostGlob+"’.")
|
||||
|
||||
Prints("%s\n", HostMessage{
|
||||
printMsg(hostMessage{
|
||||
op: "add",
|
||||
Host: hostGlob,
|
||||
AccessKeyID: accessKeyID,
|
||||
|
||||
+5
-5
@@ -66,20 +66,20 @@ EXAMPLES:
|
||||
`,
|
||||
}
|
||||
|
||||
// CopyMessage container for file copy messages
|
||||
type CopyMessage struct {
|
||||
// copyMessage container for file copy messages
|
||||
type copyMessage struct {
|
||||
Source string `json:"source"`
|
||||
Target string `json:"target"`
|
||||
Length int64 `json:"length"`
|
||||
}
|
||||
|
||||
// String colorized copy message
|
||||
func (c CopyMessage) String() string {
|
||||
func (c copyMessage) String() string {
|
||||
return console.Colorize("Copy", fmt.Sprintf("‘%s’ -> ‘%s’", c.Source, c.Target))
|
||||
}
|
||||
|
||||
// JSON jsonified copy message
|
||||
func (c CopyMessage) JSON() string {
|
||||
func (c copyMessage) JSON() string {
|
||||
copyMessageBytes, err := json.Marshal(c)
|
||||
fatalIf(probe.NewError(err), "Failed to marshal copy message.")
|
||||
|
||||
@@ -115,7 +115,7 @@ func doCopy(cpURLs copyURLs, progressReader interface{}, cpQueue <-chan bool, wg
|
||||
|
||||
var newReader io.ReadCloser
|
||||
if globalQuietFlag || globalJSONFlag {
|
||||
Prints("%s\n", CopyMessage{
|
||||
printMsg(copyMessage{
|
||||
Source: cpURLs.SourceContent.Name,
|
||||
Target: cpURLs.TargetContent.Name,
|
||||
Length: cpURLs.SourceContent.Size,
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ func mainDiff(ctx *cli.Context) {
|
||||
for diff := range doDiff(newFirstURL, secondURL, isURLRecursive(firstURL)) {
|
||||
fatalIf(diff.Error.Trace(newFirstURL, secondURL), "Failed to diff ‘"+firstURL+"’ and ‘"+secondURL+"’.")
|
||||
|
||||
Prints("%s\n", diff)
|
||||
printMsg(diff)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ func doList(clnt client.Client, recursive, multipleArgs bool) *probe.Error {
|
||||
if multipleArgs && parentContent.Type.IsDir() {
|
||||
contentCh.Content.Name = filepath.Join(parentContent.Name, strings.TrimPrefix(contentCh.Content.Name, parentContent.Name))
|
||||
}
|
||||
Prints("%s\n", parseContent(contentCh.Content))
|
||||
printMsg(parseContent(contentCh.Content))
|
||||
}
|
||||
if err != nil {
|
||||
return err.Trace()
|
||||
@@ -190,7 +190,7 @@ func doListIncomplete(clnt client.Client, recursive, multipleArgs bool) *probe.E
|
||||
if multipleArgs && parentContent.Type.IsDir() {
|
||||
contentCh.Content.Name = filepath.Join(parentContent.Name, strings.TrimPrefix(contentCh.Content.Name, parentContent.Name))
|
||||
}
|
||||
Prints("%s\n", parseContent(contentCh.Content))
|
||||
printMsg(parseContent(contentCh.Content))
|
||||
}
|
||||
if err != nil {
|
||||
return err.Trace()
|
||||
|
||||
+12
-21
@@ -49,19 +49,19 @@ EXAMPLES:
|
||||
`,
|
||||
}
|
||||
|
||||
// MakeBucketMessage is container for make bucket success and failure messages
|
||||
type MakeBucketMessage struct {
|
||||
// makeBucketMessage is container for make bucket success and failure messages
|
||||
type makeBucketMessage struct {
|
||||
Status string `json:"status"`
|
||||
Bucket string `json:"bucket"`
|
||||
}
|
||||
|
||||
// String colorized make bucket message
|
||||
func (s MakeBucketMessage) String() string {
|
||||
func (s makeBucketMessage) String() string {
|
||||
return console.Colorize("MakeBucket", "Bucket created successfully ‘"+s.Bucket+"’")
|
||||
}
|
||||
|
||||
// JSON jsonified make bucket message
|
||||
func (s MakeBucketMessage) JSON() string {
|
||||
func (s makeBucketMessage) JSON() string {
|
||||
makeBucketJSONBytes, err := json.Marshal(s)
|
||||
fatalIf(probe.NewError(err), "Unable to marshal into JSON.")
|
||||
|
||||
@@ -105,23 +105,14 @@ func mainMakeBucket(ctx *cli.Context) {
|
||||
for _, arg := range ctx.Args() {
|
||||
targetURL := getAliasURL(arg, config.Aliases)
|
||||
|
||||
fatalIf(doMakeBucket(targetURL).Trace(targetURL), "Unable to make bucket ‘"+targetURL+"’.")
|
||||
Prints("%s\n", MakeBucketMessage{
|
||||
Status: "success",
|
||||
Bucket: targetURL,
|
||||
})
|
||||
}
|
||||
}
|
||||
// Instantiate client for URL.
|
||||
clnt, err := url2Client(targetURL)
|
||||
fatalIf(err.Trace(targetURL), "Invalid target target ‘"+targetURL+"’.")
|
||||
|
||||
// doMakeBucket -
|
||||
func doMakeBucket(targetURL string) *probe.Error {
|
||||
clnt, err := url2Client(targetURL)
|
||||
if err != nil {
|
||||
return err.Trace(targetURL)
|
||||
// Make bucket.
|
||||
fatalIf(clnt.MakeBucket().Trace(), "Unable to make bucket ‘"+targetURL+"’.")
|
||||
|
||||
// Successfully created a bucket.
|
||||
printMsg(makeBucketMessage{Status: "success", Bucket: targetURL})
|
||||
}
|
||||
err = clnt.MakeBucket()
|
||||
if err != nil {
|
||||
return err.Trace(targetURL)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
+14
-8
@@ -24,17 +24,23 @@ import (
|
||||
)
|
||||
|
||||
func (s *TestSuite) TestMbAndAccess(c *C) {
|
||||
perr := doMakeBucket(server.URL + "/bucket")
|
||||
c.Assert(perr, IsNil)
|
||||
|
||||
perr = doSetAccess(server.URL+"/bucket", "public-read-write")
|
||||
c.Assert(perr, IsNil)
|
||||
// Instantiate client for URL.
|
||||
clnt, err := url2Client(server.URL + "/bucket")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
perr = doSetAccess(server.URL+"/bucket", "invalid")
|
||||
c.Assert(perr, Not(IsNil))
|
||||
// Make bucket.
|
||||
err = clnt.MakeBucket()
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
perm, perr := doGetAccess(server.URL + "/bucket")
|
||||
c.Assert(perr, IsNil)
|
||||
err = doSetAccess(server.URL+"/bucket", "public-read-write")
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
err = doSetAccess(server.URL+"/bucket", "invalid")
|
||||
c.Assert(err, Not(IsNil))
|
||||
|
||||
perm, err := doGetAccess(server.URL + "/bucket")
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(perm.isPrivate(), Equals, true)
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -62,19 +62,19 @@ EXAMPLES:
|
||||
`,
|
||||
}
|
||||
|
||||
// MirrorMessage container for file mirror messages
|
||||
type MirrorMessage struct {
|
||||
// mirrorMessage container for file mirror messages
|
||||
type mirrorMessage struct {
|
||||
Source string `json:"source"`
|
||||
Targets []string `json:"targets"`
|
||||
}
|
||||
|
||||
// String colorized mirror message
|
||||
func (m MirrorMessage) String() string {
|
||||
func (m mirrorMessage) String() string {
|
||||
return console.Colorize("Mirror", fmt.Sprintf("‘%s’ -> ‘%s’", m.Source, m.Targets))
|
||||
}
|
||||
|
||||
// JSON jsonified mirror message
|
||||
func (m MirrorMessage) JSON() string {
|
||||
func (m mirrorMessage) JSON() string {
|
||||
mirrorMessageBytes, e := json.Marshal(m)
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
@@ -115,7 +115,7 @@ func doMirror(sURLs mirrorURLs, progressReader interface{}, mirrorQueueCh <-chan
|
||||
|
||||
var newReader io.ReadCloser
|
||||
if globalQuietFlag || globalJSONFlag {
|
||||
Prints("%s\n", MirrorMessage{
|
||||
printMsg(mirrorMessage{
|
||||
Source: sURLs.SourceContent.Name,
|
||||
Targets: targetURLs,
|
||||
})
|
||||
|
||||
@@ -18,17 +18,17 @@ package main
|
||||
|
||||
import "github.com/minio/mc/pkg/console"
|
||||
|
||||
// Message interface for all structured messages implementing JSON(), String() methods
|
||||
type Message interface {
|
||||
// message interface for all structured messages implementing JSON(), String() methods.
|
||||
type message interface {
|
||||
JSON() string
|
||||
String() string
|
||||
}
|
||||
|
||||
// Prints print wrapper for Message interface, implementing both JSON() and String() methods
|
||||
func Prints(format string, message Message) {
|
||||
// printMsg prints message string or JSON structure depending on the type of output console.
|
||||
func printMsg(msg message) {
|
||||
if !globalJSONFlag {
|
||||
console.Printf(format, message.String())
|
||||
return
|
||||
console.Println(msg.String())
|
||||
} else {
|
||||
console.Println(msg.JSON())
|
||||
}
|
||||
console.Printf(format, message.JSON())
|
||||
}
|
||||
|
||||
+1
-1
@@ -287,7 +287,7 @@ func rmPrinterFuncGenerate() rmPrinterFunc {
|
||||
}
|
||||
return func(msg rmMessage) {
|
||||
if globalJSONFlag || globalQuietFlag {
|
||||
Prints("%s\n", msg)
|
||||
printMsg(msg)
|
||||
return
|
||||
}
|
||||
scanBar(msg.Name)
|
||||
|
||||
+7
-13
@@ -75,24 +75,24 @@ func listSessions() *probe.Error {
|
||||
// sort sessions based on time
|
||||
sort.Sort(bySessionWhen(bySessions))
|
||||
for _, session := range bySessions {
|
||||
Prints("%s\n", session)
|
||||
printMsg(session)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearSessionMessage container for clearing session messages
|
||||
type ClearSessionMessage struct {
|
||||
// clearSessionMessage container for clearing session messages
|
||||
type clearSessionMessage struct {
|
||||
Status string `json:"success"`
|
||||
SessionID string `json:"sessionId"`
|
||||
}
|
||||
|
||||
// String colorized clear session message
|
||||
func (c ClearSessionMessage) String() string {
|
||||
func (c clearSessionMessage) String() string {
|
||||
return console.Colorize("ClearSession", "Session ‘"+c.SessionID+"’ cleared successfully")
|
||||
}
|
||||
|
||||
// JSON jsonified clear session message
|
||||
func (c ClearSessionMessage) JSON() string {
|
||||
func (c clearSessionMessage) JSON() string {
|
||||
clearSessionJSONBytes, err := json.Marshal(c)
|
||||
fatalIf(probe.NewError(err), "Unable to marshal into JSON.")
|
||||
|
||||
@@ -107,10 +107,7 @@ func clearSession(sid string) {
|
||||
|
||||
fatalIf(session.Delete().Trace(sid), "Unable to load session ‘"+sid+"’.")
|
||||
|
||||
Prints("%s\n", ClearSessionMessage{
|
||||
Status: "success",
|
||||
SessionID: sid,
|
||||
})
|
||||
printMsg(clearSessionMessage{Status: "success", SessionID: sid})
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -124,10 +121,7 @@ func clearSession(sid string) {
|
||||
|
||||
if session != nil {
|
||||
fatalIf(session.Delete().Trace(sid), "Unable to load session ‘"+sid+"’.")
|
||||
Prints("%s\n", ClearSessionMessage{
|
||||
Status: "success",
|
||||
SessionID: sid,
|
||||
})
|
||||
printMsg(clearSessionMessage{Status: "success", SessionID: sid})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ func doShareDownloadURL(targetURL string, recursive bool, expires time.Duration)
|
||||
Date: shareDate,
|
||||
Message: shareMessageV3,
|
||||
})
|
||||
Prints("%s\n", shareMessage)
|
||||
printMsg(shareMessage)
|
||||
}
|
||||
saveSharedURLsV3(sURLs)
|
||||
return nil
|
||||
|
||||
@@ -130,7 +130,7 @@ func doShareUploadURL(targetURL string, recursive bool, expires time.Duration, c
|
||||
Date: shareDate,
|
||||
Message: shareMessageV3,
|
||||
})
|
||||
Prints("%s\n", shareMessage)
|
||||
printMsg(shareMessage)
|
||||
saveSharedURLsV3(sURLs)
|
||||
return nil
|
||||
}
|
||||
|
||||
+2
-2
@@ -177,7 +177,7 @@ func getExperimentalUpdate() {
|
||||
if latest.After(current) {
|
||||
updateMessage.Update = true
|
||||
}
|
||||
Prints("%s\n", updateMessage)
|
||||
printMsg(updateMessage)
|
||||
}
|
||||
|
||||
func getReleaseUpdate() {
|
||||
@@ -219,5 +219,5 @@ func getReleaseUpdate() {
|
||||
if latest.After(current) {
|
||||
updateMessage.Update = true
|
||||
}
|
||||
Prints("%s\n", updateMessage)
|
||||
printMsg(updateMessage)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user