mirror of
https://github.com/minio/mc.git
synced 2025-11-14 23:42:27 +03:00
Prefix error messages with mc: part of #286
This commit is contained in:
@@ -352,7 +352,7 @@ func saveConfigCmd(ctx *cli.Context) {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("mc: Unable to identify config file path")
|
||||
}
|
||||
console.Infoln("Configuration written to " + configPath + ". Please update your access credentials.")
|
||||
console.Infoln("mc: Configuration written to " + configPath + ". Please update your access credentials.")
|
||||
}
|
||||
|
||||
// doConfigCmd is the handler for "mc config" sub-command.
|
||||
@@ -362,7 +362,7 @@ func doConfigCmd(ctx *cli.Context) {
|
||||
case ctx.Bool("completion") == true:
|
||||
var b bytes.Buffer
|
||||
if os.Getenv("SHELL") != "/bin/bash" {
|
||||
console.Fatalln("Unsupported shell for bash completion detected.. exiting")
|
||||
console.Fatalln("mc: Unsupported shell for bash completion detected.. exiting")
|
||||
}
|
||||
b.WriteString(mcBashCompletion)
|
||||
f, err := getMcBashCompletionFilename()
|
||||
@@ -374,12 +374,12 @@ func doConfigCmd(ctx *cli.Context) {
|
||||
defer fl.Close()
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to create bash completion file")
|
||||
console.Fatalln("mc: Unable to create bash completion file")
|
||||
}
|
||||
_, err = fl.Write(b.Bytes())
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to write bash completion file")
|
||||
console.Fatalln("mc: Unable to write to bash completion file")
|
||||
}
|
||||
msg := "\nConfiguration written to " + f
|
||||
msg = msg + "\n\n$ source ${HOME}/.mc/mc.bash_completion\n"
|
||||
|
||||
10
cmd-cp.go
10
cmd-cp.go
@@ -84,7 +84,7 @@ func doCopyCmd(ctx *cli.Context) {
|
||||
urlParsers, err := parseURLs(ctx)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to parse URL")
|
||||
console.Fatalln("mc: Unable to parse URL")
|
||||
}
|
||||
sourceURLParser := urlParsers[0] // First arg is source
|
||||
targetURLsParser := urlParsers[1:] // 1 or more targets
|
||||
@@ -92,13 +92,13 @@ func doCopyCmd(ctx *cli.Context) {
|
||||
reader, length, hexMd5, err := getSourceReader(sourceURLParser)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to read source")
|
||||
console.Fatalln("mc: Unable to read source")
|
||||
}
|
||||
|
||||
writeClosers, err := getTargetWriters(targetURLsParser, hexMd5, length)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to open targets for writing")
|
||||
console.Fatalln("mc: Unable to open targets for writing")
|
||||
}
|
||||
|
||||
var writers []io.Writer
|
||||
@@ -125,11 +125,11 @@ func doCopyCmd(ctx *cli.Context) {
|
||||
err := writer.Close()
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Errorln("Unable to close writer, object may not of written properly.")
|
||||
console.Errorln("mc: Unable to close writer, object may not of written properly.")
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to write to target")
|
||||
console.Fatalln("mc: Unable to write to target")
|
||||
}
|
||||
}
|
||||
|
||||
10
cmd-ls.go
10
cmd-ls.go
@@ -63,18 +63,18 @@ func doListCmd(ctx *cli.Context) {
|
||||
config, err := getMcConfig()
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to get config")
|
||||
console.Fatalln("mc: Unable to get config")
|
||||
}
|
||||
for _, arg := range ctx.Args() {
|
||||
targetURLParser, err := parseURL(arg, config.Aliases)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to parse URL")
|
||||
console.Fatalln("mc: Unable to parse URL")
|
||||
}
|
||||
client, err := getNewClient(targetURLParser, globalDebugFlag)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to initiate new client")
|
||||
console.Fatalln("mc: Unable to initiate new client")
|
||||
}
|
||||
|
||||
// ListBuckets() will not be called for fsClient() as its not needed.
|
||||
@@ -82,14 +82,14 @@ func doListCmd(ctx *cli.Context) {
|
||||
buckets, err := client.ListBuckets()
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to list buckets for", targetURLParser.String())
|
||||
console.Fatalln("mc: Unable to list buckets for ", targetURLParser.String())
|
||||
}
|
||||
printBuckets(buckets)
|
||||
} else {
|
||||
items, err = client.ListObjects(targetURLParser.bucketName, targetURLParser.objectName)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to list objects for", targetURLParser.String())
|
||||
console.Fatalln("mc: Unable to list objects for ", targetURLParser.String())
|
||||
}
|
||||
printObjects(items)
|
||||
}
|
||||
|
||||
@@ -32,13 +32,13 @@ func doMakeBucketCmd(ctx *cli.Context) {
|
||||
config, err := getMcConfig()
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to get config")
|
||||
console.Fatalln("mc: Unable to read config")
|
||||
}
|
||||
for _, arg := range ctx.Args() {
|
||||
targetURLParser, err := parseURL(arg, config.Aliases)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to parse URL:", arg)
|
||||
console.Fatalln("mc: Unable to parse URL: ", arg)
|
||||
}
|
||||
// this is handled differently since http based URLs cannot have
|
||||
// nested directories as buckets, buckets are a unique alphanumeric
|
||||
@@ -46,13 +46,13 @@ func doMakeBucketCmd(ctx *cli.Context) {
|
||||
if targetURLParser.urlType != urlFile {
|
||||
if !client.IsValidBucketName(targetURLParser.bucketName) {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalf("Invalid bucket name: %s", targetURLParser.bucketName)
|
||||
console.Fatalf("mc: Invalid bucket name: %s", targetURLParser.bucketName)
|
||||
}
|
||||
}
|
||||
clnt, err := getNewClient(targetURLParser, globalDebugFlag)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalf("Unable to create new client to: %s", targetURLParser.String())
|
||||
console.Fatalf("mc: Unable to create new client to: %s", targetURLParser.String())
|
||||
}
|
||||
err = clnt.PutBucket(targetURLParser.bucketName)
|
||||
if err != nil {
|
||||
|
||||
@@ -62,7 +62,7 @@ func doCopyCmdRecursive(ctx *cli.Context) {
|
||||
urlParsers, err := parseURLs(ctx)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln(err)
|
||||
console.Fatalf("mc: unable to parse urls: %s\n", err)
|
||||
}
|
||||
sourceURLParser := urlParsers[0] // First arg is source
|
||||
targetURLParser := urlParsers[1] // 1 target for now - TODO(y4m4): 2 or more targets
|
||||
@@ -70,24 +70,24 @@ func doCopyCmdRecursive(ctx *cli.Context) {
|
||||
sourceClnt, err := getNewClient(sourceURLParser, globalDebugFlag)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln(err)
|
||||
console.Fatalf("mc: unable to get source: %s\n", err)
|
||||
}
|
||||
sourceObjectList, err := getSourceObjectList(sourceClnt, sourceURLParser)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln(err)
|
||||
console.Fatalf("mc: unable to list source objects: %s\n", err)
|
||||
}
|
||||
// do not exit, continue even for failures
|
||||
for _, sourceObject := range sourceObjectList {
|
||||
reader, length, md5hex, err := sourceClnt.Get(sourceURLParser.bucketName, sourceObject.Key)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Errorln(err)
|
||||
console.Errorf("mc: unable to read source: %s\n", err)
|
||||
}
|
||||
writeCloser, err := getRecursiveTargetWriter(targetURLParser, sourceObject.Key, md5hex, length)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Errorln(err)
|
||||
console.Errorf("mc: unable to read target: %s\n", err)
|
||||
}
|
||||
var writers []io.Writer
|
||||
writers = append(writers, writeCloser)
|
||||
@@ -107,14 +107,14 @@ func doCopyCmdRecursive(ctx *cli.Context) {
|
||||
_, err = io.CopyN(multiWriter, reader, length)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Errorln("Unable to write to target")
|
||||
console.Errorln("mc: Unable to write to target")
|
||||
}
|
||||
|
||||
// close writers
|
||||
err = writeCloser.Close()
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Errorln("Unable to close writer, object may not of written properly.")
|
||||
console.Errorln("mc: Unable to close writer, object may not of written properly.")
|
||||
}
|
||||
}
|
||||
return
|
||||
|
||||
@@ -54,28 +54,28 @@ func doUpdateCmd(ctx *cli.Context) {
|
||||
req, err := getReq(mcUpdateURL)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to update:", mcUpdateURL)
|
||||
console.Fatalln("mc: Unable to update:", mcUpdateURL)
|
||||
}
|
||||
res, err := http.DefaultTransport.RoundTrip(req)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to retrieve:", mcUpdateURL)
|
||||
console.Fatalln("mc: Unable to retrieve:", mcUpdateURL)
|
||||
}
|
||||
if res.StatusCode != http.StatusOK {
|
||||
msg := fmt.Sprint("Received invalid HTTP status: ", res.StatusCode)
|
||||
log.Debug.Println(iodine.New(errors.New(msg), nil))
|
||||
console.Fatalln(msg)
|
||||
console.Fatalln("mc: " + msg)
|
||||
}
|
||||
ures := updateResults{}
|
||||
err = json.NewDecoder(res.Body).Decode(&ures)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to parse JSON:", mcUpdateURL)
|
||||
console.Fatalln("mc: Unable to parse JSON:", mcUpdateURL)
|
||||
}
|
||||
latest, err := time.Parse(time.RFC3339Nano, ures.LatestBuild)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to parse update time:", ures.LatestBuild)
|
||||
console.Fatalln("mc: Unable to parse update time:", ures.LatestBuild)
|
||||
}
|
||||
if latest.After(ctx.App.Compiled) {
|
||||
// FIXME : find some proper versioning scheme here
|
||||
|
||||
@@ -18,6 +18,14 @@ package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type errInvalidTheme struct {
|
||||
theme string
|
||||
}
|
||||
|
||||
func (e errInvalidTheme) Error() string {
|
||||
return "invalid theme: " + e.theme
|
||||
}
|
||||
|
||||
type errInvalidArgument struct{}
|
||||
|
||||
func (e errInvalidArgument) Error() string {
|
||||
|
||||
10
main.go
10
main.go
@@ -37,7 +37,7 @@ func checkConfig() {
|
||||
_, err := user.Current()
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalln("Unable to obtain user's home directory")
|
||||
console.Fatalln("mc: Unable to obtain user's home directory")
|
||||
}
|
||||
|
||||
if !isMcConfigExist() {
|
||||
@@ -49,13 +49,13 @@ func checkConfig() {
|
||||
config, err := getMcConfig()
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalf("Unable to read config file: %s\n", mustGetMcConfigPath())
|
||||
console.Fatalf("mc: Unable to read config file: %s\n", mustGetMcConfigPath())
|
||||
}
|
||||
|
||||
err = checkMcConfig(config)
|
||||
if err != nil {
|
||||
log.Debug.Println(iodine.New(err, nil))
|
||||
console.Fatalf("Error in config file: %s\n", mustGetMcConfigPath())
|
||||
console.Fatalf("mc: Error in config file: %s\n", mustGetMcConfigPath())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func main() {
|
||||
if theme != "" {
|
||||
err := console.SetTheme(theme)
|
||||
if err != nil {
|
||||
console.Fatalf("Unable to set theme [%s]\n", theme)
|
||||
console.Fatalf("mc: Unable to set theme [%s]\n", theme)
|
||||
}
|
||||
}
|
||||
checkConfig()
|
||||
@@ -114,7 +114,7 @@ func main() {
|
||||
}
|
||||
app.After = func(ctx *cli.Context) error {
|
||||
if !isMcConfigExist() && ctx.Command.Name != "config" {
|
||||
console.Fatalln("Error: mc is not configured. Please run \"mc config\".")
|
||||
console.Fatalln("mc: error ``mc`` is not configured. Please run \"mc config\".")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -23,6 +23,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio-io/minio/pkg/iodine"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -101,7 +102,8 @@ func isValidTheme(themeName string) bool {
|
||||
// SetTheme sets a color theme
|
||||
func SetTheme(themeName string) error {
|
||||
if !isValidTheme(themeName) {
|
||||
return errors.New("Invalid theme")
|
||||
msg := fmt.Sprintf("invalid theme: %s", themeName)
|
||||
return iodine.New(errors.New(msg), nil)
|
||||
}
|
||||
currentTheme = themeName
|
||||
mutex.Lock()
|
||||
|
||||
Reference in New Issue
Block a user