mirror of
https://github.com/minio/mc.git
synced 2025-11-13 12:22:45 +03:00
Move to structure printing everywhere, fix incorrect iodine usage at few places
This commit is contained in:
@@ -74,7 +74,7 @@ func runConfigCmd(ctx *cli.Context) {
|
||||
if err != nil {
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: msg,
|
||||
Error: err,
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
}
|
||||
console.Infos(InfoMessage{
|
||||
@@ -89,12 +89,10 @@ func saveConfig(arg string, aliases []string) error {
|
||||
if isMcConfigExist() {
|
||||
return iodine.New(errConfigExists{}, nil)
|
||||
}
|
||||
|
||||
config, err := newConfig()
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
}
|
||||
|
||||
err = writeConfig(config)
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
|
||||
17
cmd-cp.go
17
cmd-cp.go
@@ -95,7 +95,10 @@ func doCopySession(cURLs cpURLs, bar *barSend, s *sessionV1) error {
|
||||
var newReader io.Reader
|
||||
switch globalQuietFlag {
|
||||
case true:
|
||||
console.Infoln(fmt.Sprintf("‘%s’ -> ‘%s’", cURLs.SourceContent.Name, cURLs.TargetContent.Name))
|
||||
console.Infos(CopyMessage{
|
||||
Source: cURLs.SourceContent.Name,
|
||||
Target: cURLs.TargetContent.Name,
|
||||
})
|
||||
newReader = yielder.NewReader(reader)
|
||||
default:
|
||||
// set up progress
|
||||
@@ -226,13 +229,19 @@ func runCopyCmd(ctx *cli.Context) {
|
||||
}
|
||||
if !isSessionDirExists() {
|
||||
if err := createSessionDir(); err != nil {
|
||||
console.Fatalln(iodine.ToError(err))
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: "Failed with",
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
s, err := newSession()
|
||||
if err != nil {
|
||||
console.Fatalln(iodine.ToError(err))
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: "Failed with",
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
}
|
||||
s.CommandType = "cp"
|
||||
|
||||
@@ -262,7 +271,7 @@ func runCopyCmd(ctx *cli.Context) {
|
||||
if err := saveSession(s); err != nil {
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: "Failed with",
|
||||
Error: iodine.ToError(err),
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
}
|
||||
console.Infos(InfoMessage{
|
||||
|
||||
14
cmd-diff.go
14
cmd-diff.go
@@ -68,7 +68,7 @@ func runDiffCmd(ctx *cli.Context) {
|
||||
if err != nil {
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: fmt.Sprintf("Unable to read config file ‘%s’", mustGetMcConfigPath()),
|
||||
Error: err,
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -81,12 +81,12 @@ func runDiffCmd(ctx *cli.Context) {
|
||||
case errUnsupportedScheme:
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: fmt.Sprintf("Unknown type of URL ‘%s’", firstURL),
|
||||
Error: err,
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
default:
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: fmt.Sprintf("Unable to parse argument ‘%s’", firstURL),
|
||||
Error: err,
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -96,19 +96,19 @@ func runDiffCmd(ctx *cli.Context) {
|
||||
case errUnsupportedScheme:
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: fmt.Sprintf("Unknown type of URL ‘%s’", secondURL),
|
||||
Error: err,
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
default:
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: fmt.Sprintf("Unable to parse argument ‘%s’", secondURL),
|
||||
Error: err,
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
}
|
||||
}
|
||||
if isURLRecursive(secondURL) {
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: "Second URL cannot be recursive, diff command is unidirectional",
|
||||
Error: errInvalidArgument{},
|
||||
Error: iodine.New(errInvalidArgument{}, nil),
|
||||
})
|
||||
}
|
||||
newFirstURL := stripRecursiveURL(firstURL)
|
||||
@@ -116,7 +116,7 @@ func runDiffCmd(ctx *cli.Context) {
|
||||
if diff.err != nil {
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: diff.message,
|
||||
Error: diff.err,
|
||||
Error: iodine.New(diff.err, nil),
|
||||
})
|
||||
}
|
||||
console.Infos(InfoMessage{
|
||||
|
||||
@@ -119,7 +119,7 @@ func runListCmd(ctx *cli.Context) {
|
||||
if err != nil {
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: fmt.Sprintf("Failed to list ‘%s’", targetURL),
|
||||
Error: iodine.New(err, nil),
|
||||
Error: iodine.New(err, map[string]string{"Target": targetURL}),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -133,7 +133,7 @@ func doListCmd(targetURL string, recursive bool) error {
|
||||
}
|
||||
err = doList(clnt, recursive)
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
return iodine.New(err, map[string]string{"Target": targetURL})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func listSessions(sdir string) error {
|
||||
if err != nil {
|
||||
return iodine.New(err, nil)
|
||||
}
|
||||
console.Println(s)
|
||||
console.Prints(s)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -140,7 +140,7 @@ func sessionExecute(bar barSend, s *sessionV1) {
|
||||
if err := saveSession(s); err != nil {
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: "Failed with",
|
||||
Error: iodine.ToError(err),
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
}
|
||||
os.Exit(0)
|
||||
@@ -158,7 +158,7 @@ func sessionExecute(bar barSend, s *sessionV1) {
|
||||
if err := saveSession(s); err != nil {
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: "Failed with",
|
||||
Error: iodine.ToError(err),
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
}
|
||||
// this os.Exit is needed really to exit in-case of "os.Interrupt"
|
||||
|
||||
12
cmd-sync.go
12
cmd-sync.go
@@ -222,13 +222,19 @@ func runSyncCmd(ctx *cli.Context) {
|
||||
|
||||
if !isSessionDirExists() {
|
||||
if err := createSessionDir(); err != nil {
|
||||
console.Fatalln(iodine.ToError(err))
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: "Failed with",
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
s, err := newSession()
|
||||
if err != nil {
|
||||
console.Fatalln(iodine.ToError(err))
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: "Failed with",
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
}
|
||||
s.CommandType = "sync"
|
||||
|
||||
@@ -258,7 +264,7 @@ func runSyncCmd(ctx *cli.Context) {
|
||||
if err := saveSession(s); err != nil {
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: "Failed wtih",
|
||||
Error: iodine.ToError(err),
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
}
|
||||
console.Infos(InfoMessage{
|
||||
|
||||
@@ -18,7 +18,6 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"time"
|
||||
@@ -93,7 +92,7 @@ https://dl.minio.io:9000 for continuous updates`
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
fmt.Println(msg)
|
||||
console.Prints(InfoMessage{Message: msg})
|
||||
return "", nil
|
||||
}
|
||||
return "You are already running the most recent version of ‘mc’", nil
|
||||
@@ -120,6 +119,6 @@ func runUpdateCmd(ctx *cli.Context) {
|
||||
}
|
||||
// no msg do not print one
|
||||
if msg != "" {
|
||||
console.Infoln(msg)
|
||||
console.Infos(InfoMessage{Message: msg})
|
||||
}
|
||||
}
|
||||
|
||||
14
ls.go
14
ls.go
@@ -77,20 +77,26 @@ func doList(clnt client.Client, recursive bool) error {
|
||||
var err error
|
||||
for contentCh := range clnt.List(recursive) {
|
||||
if contentCh.Err != nil {
|
||||
switch e := iodine.ToError(contentCh.Err).(type) {
|
||||
switch err := iodine.ToError(contentCh.Err).(type) {
|
||||
// handle this specifically for filesystem
|
||||
case client.ISBrokenSymlink:
|
||||
console.Errorln(e)
|
||||
console.Errors(ErrorMessage{
|
||||
Message: "Failed with",
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
continue
|
||||
}
|
||||
if os.IsNotExist(iodine.ToError(contentCh.Err)) || os.IsPermission(iodine.ToError(contentCh.Err)) {
|
||||
console.Errorln(iodine.ToError(contentCh.Err))
|
||||
console.Errors(ErrorMessage{
|
||||
Message: "Failed with",
|
||||
Error: iodine.New(contentCh.Err, nil),
|
||||
})
|
||||
continue
|
||||
}
|
||||
err = contentCh.Err
|
||||
break
|
||||
}
|
||||
console.Println(parseContent(contentCh.Content))
|
||||
console.Prints(parseContent(contentCh.Content))
|
||||
}
|
||||
if err != nil {
|
||||
return iodine.New(err, map[string]string{"Target": clnt.URL().String()})
|
||||
|
||||
8
main.go
8
main.go
@@ -35,7 +35,7 @@ func checkConfig() {
|
||||
if err != nil {
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: "Unable to determine current user",
|
||||
Error: err,
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ func checkConfig() {
|
||||
if err != nil {
|
||||
console.Fatals(ErrorMessage{
|
||||
Message: fmt.Sprintf("Unable to read config file: %s", mustGetMcConfigPath()),
|
||||
Error: err,
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -126,7 +126,7 @@ func main() {
|
||||
err := iodine.New(errInvalidTheme{Theme: themeName}, nil)
|
||||
console.Errors(ErrorMessage{
|
||||
Message: fmt.Sprintf("Please choose from this list: %s.", console.GetThemeNames()),
|
||||
Error: err,
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
return err
|
||||
default:
|
||||
@@ -134,7 +134,7 @@ func main() {
|
||||
if err != nil {
|
||||
console.Errors(ErrorMessage{
|
||||
Message: fmt.Sprintf("Failed to set theme ‘%s’.", themeName),
|
||||
Error: err,
|
||||
Error: iodine.New(err, nil),
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ var (
|
||||
Prints = func(data ...interface{}) {
|
||||
for i := 0; i < len(data); i++ {
|
||||
if NoJSONPrint {
|
||||
println(themesDB[currThemeName].Info, data[i])
|
||||
println(themesDB[currThemeName].Print, data[i])
|
||||
return
|
||||
}
|
||||
infoBytes, _ := json.Marshal(&data[i])
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio/pkg/iodine"
|
||||
)
|
||||
@@ -71,3 +73,13 @@ type InfoMessage struct {
|
||||
func (i InfoMessage) String() string {
|
||||
return i.Message
|
||||
}
|
||||
|
||||
type CopyMessage struct {
|
||||
Message string `json:"message"`
|
||||
Source string `json:"source"`
|
||||
Target string `json:"target"`
|
||||
}
|
||||
|
||||
func (c CopyMessage) String() string {
|
||||
return fmt.Sprintf("‘%s’ -> ‘%s’", c.Source, c.Target)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user