mirror of
https://github.com/minio/mc.git
synced 2025-11-13 12:22:45 +03:00
Implement console.Fatals, Errors, Infos, Prints for structure input and printing
This commit is contained in:
@@ -32,14 +32,14 @@ func runAccessCmd(ctx *cli.Context) {
|
|||||||
cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code
|
cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code
|
||||||
}
|
}
|
||||||
if !isMcConfigExist() {
|
if !isMcConfigExist() {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: "Please run \"mc config generate\"",
|
Message: "Please run \"mc config generate\"",
|
||||||
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
|
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
config, err := getMcConfig()
|
config, err := getMcConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: "loading config file failed",
|
Message: "loading config file failed",
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
@@ -47,14 +47,14 @@ func runAccessCmd(ctx *cli.Context) {
|
|||||||
targetURLConfigMap := make(map[string]*hostConfig)
|
targetURLConfigMap := make(map[string]*hostConfig)
|
||||||
targetURLs, err := getExpandedURLs(ctx.Args(), config.Aliases)
|
targetURLs, err := getExpandedURLs(ctx.Args(), config.Aliases)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: "Unknown type of URL ",
|
Message: "Unknown type of URL ",
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
acl := bucketACL(ctx.Args().First())
|
acl := bucketACL(ctx.Args().First())
|
||||||
if !acl.isValidBucketACL() {
|
if !acl.isValidBucketACL() {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: "Valid types are [private, public, readonly].",
|
Message: "Valid types are [private, public, readonly].",
|
||||||
Error: iodine.New(errors.New("Invalid ACL Type ‘"+acl.String()+"’"), nil),
|
Error: iodine.New(errors.New("Invalid ACL Type ‘"+acl.String()+"’"), nil),
|
||||||
})
|
})
|
||||||
@@ -63,7 +63,7 @@ func runAccessCmd(ctx *cli.Context) {
|
|||||||
for _, targetURL := range targetURLs {
|
for _, targetURL := range targetURLs {
|
||||||
targetConfig, err := getHostConfig(targetURL)
|
targetConfig, err := getHostConfig(targetURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: "Unable to read configuration for host " + "‘" + targetURL + "’",
|
Message: "Unable to read configuration for host " + "‘" + targetURL + "’",
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
@@ -73,7 +73,7 @@ func runAccessCmd(ctx *cli.Context) {
|
|||||||
for targetURL, targetConfig := range targetURLConfigMap {
|
for targetURL, targetConfig := range targetURLConfigMap {
|
||||||
errorMsg, err := doUpdateAccessCmd(targetURL, acl.String(), targetConfig)
|
errorMsg, err := doUpdateAccessCmd(targetURL, acl.String(), targetConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Errorln(ErrorMessage{
|
console.Errors(ErrorMessage{
|
||||||
Message: errorMsg,
|
Message: errorMsg,
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
|
|||||||
10
cmd-cat.go
10
cmd-cat.go
@@ -32,14 +32,14 @@ func runCatCmd(ctx *cli.Context) {
|
|||||||
cli.ShowCommandHelpAndExit(ctx, "cat", 1) // last argument is exit code
|
cli.ShowCommandHelpAndExit(ctx, "cat", 1) // last argument is exit code
|
||||||
}
|
}
|
||||||
if !isMcConfigExist() {
|
if !isMcConfigExist() {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: "Please run \"mc config generate\"",
|
Message: "Please run \"mc config generate\"",
|
||||||
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
|
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
config, err := getMcConfig()
|
config, err := getMcConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unable to read config file ‘%s’", mustGetMcConfigPath()),
|
Message: fmt.Sprintf("Unable to read config file ‘%s’", mustGetMcConfigPath()),
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
@@ -48,7 +48,7 @@ func runCatCmd(ctx *cli.Context) {
|
|||||||
// Convert arguments to URLs: expand alias, fix format...
|
// Convert arguments to URLs: expand alias, fix format...
|
||||||
urls, err := getExpandedURLs(ctx.Args(), config.Aliases)
|
urls, err := getExpandedURLs(ctx.Args(), config.Aliases)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unknown type of URL ‘%s’", urls),
|
Message: fmt.Sprintf("Unknown type of URL ‘%s’", urls),
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
@@ -57,14 +57,14 @@ func runCatCmd(ctx *cli.Context) {
|
|||||||
sourceURLs := urls
|
sourceURLs := urls
|
||||||
sourceURLConfigMap, err := getHostConfigs(sourceURLs)
|
sourceURLConfigMap, err := getHostConfigs(sourceURLs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unable to read host configuration for ‘%s’ from config file ‘%s’", sourceURLs, mustGetMcConfigPath()),
|
Message: fmt.Sprintf("Unable to read host configuration for ‘%s’ from config file ‘%s’", sourceURLs, mustGetMcConfigPath()),
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
humanReadable, err := doCatCmd(sourceURLConfigMap)
|
humanReadable, err := doCatCmd(sourceURLConfigMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: humanReadable,
|
Message: humanReadable,
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -34,14 +34,14 @@ func runConfigCmd(ctx *cli.Context) {
|
|||||||
arg := ctx.Args().First()
|
arg := ctx.Args().First()
|
||||||
tailArgs := ctx.Args().Tail()
|
tailArgs := ctx.Args().Tail()
|
||||||
if len(tailArgs) > 2 {
|
if len(tailArgs) > 2 {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: "Incorrect number of arguments, please use \"mc config help\"",
|
Message: "Incorrect number of arguments, please use \"mc config help\"",
|
||||||
Error: iodine.New(errInvalidArgument{}, nil),
|
Error: iodine.New(errInvalidArgument{}, nil),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
msg, err := doConfig(arg, tailArgs)
|
msg, err := doConfig(arg, tailArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: msg,
|
Message: msg,
|
||||||
Error: err,
|
Error: err,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ func runCopyCmd(ctx *cli.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !isMcConfigExist() {
|
if !isMcConfigExist() {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: "Please run \"mc config generate\"",
|
Message: "Please run \"mc config generate\"",
|
||||||
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
|
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
|
||||||
})
|
})
|
||||||
@@ -134,7 +134,7 @@ func runCopyCmd(ctx *cli.Context) {
|
|||||||
// extract URLs.
|
// extract URLs.
|
||||||
URLs, err := args2URLs(ctx.Args())
|
URLs, err := args2URLs(ctx.Args())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unknown URL types: ‘%s’", URLs),
|
Message: fmt.Sprintf("Unknown URL types: ‘%s’", URLs),
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
@@ -153,7 +153,7 @@ func runCopyCmd(ctx *cli.Context) {
|
|||||||
|
|
||||||
for err := range doCopyCmd(sourceURLs, targetURL, bar) {
|
for err := range doCopyCmd(sourceURLs, targetURL, bar) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Errorln(ErrorMessage{
|
console.Errors(ErrorMessage{
|
||||||
Message: "Failed with",
|
Message: "Failed with",
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
|
|||||||
18
cmd-diff.go
18
cmd-diff.go
@@ -31,14 +31,14 @@ func runDiffCmd(ctx *cli.Context) {
|
|||||||
cli.ShowCommandHelpAndExit(ctx, "diff", 1) // last argument is exit code
|
cli.ShowCommandHelpAndExit(ctx, "diff", 1) // last argument is exit code
|
||||||
}
|
}
|
||||||
if !isMcConfigExist() {
|
if !isMcConfigExist() {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: "Please run \"mc config generate\"",
|
Message: "Please run \"mc config generate\"",
|
||||||
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
|
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
config, err := getMcConfig()
|
config, err := getMcConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unable to read config file ‘%s’", mustGetMcConfigPath()),
|
Message: fmt.Sprintf("Unable to read config file ‘%s’", mustGetMcConfigPath()),
|
||||||
Error: err,
|
Error: err,
|
||||||
})
|
})
|
||||||
@@ -51,12 +51,12 @@ func runDiffCmd(ctx *cli.Context) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
switch iodine.ToError(err).(type) {
|
switch iodine.ToError(err).(type) {
|
||||||
case errUnsupportedScheme:
|
case errUnsupportedScheme:
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unknown type of URL ‘%s’", firstURL),
|
Message: fmt.Sprintf("Unknown type of URL ‘%s’", firstURL),
|
||||||
Error: err,
|
Error: err,
|
||||||
})
|
})
|
||||||
default:
|
default:
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unable to parse argument ‘%s’", firstURL),
|
Message: fmt.Sprintf("Unable to parse argument ‘%s’", firstURL),
|
||||||
Error: err,
|
Error: err,
|
||||||
})
|
})
|
||||||
@@ -65,7 +65,7 @@ func runDiffCmd(ctx *cli.Context) {
|
|||||||
|
|
||||||
_, err = getHostConfig(firstURL)
|
_, err = getHostConfig(firstURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unable to read host configuration for ‘%s’ from config file ‘%s’", firstURL, mustGetMcConfigPath()),
|
Message: fmt.Sprintf("Unable to read host configuration for ‘%s’ from config file ‘%s’", firstURL, mustGetMcConfigPath()),
|
||||||
Error: err,
|
Error: err,
|
||||||
})
|
})
|
||||||
@@ -73,7 +73,7 @@ func runDiffCmd(ctx *cli.Context) {
|
|||||||
|
|
||||||
_, err = getHostConfig(secondURL)
|
_, err = getHostConfig(secondURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unable to read host configuration for ‘%s’ from config file ‘%s’", secondURL, mustGetMcConfigPath()),
|
Message: fmt.Sprintf("Unable to read host configuration for ‘%s’ from config file ‘%s’", secondURL, mustGetMcConfigPath()),
|
||||||
Error: err,
|
Error: err,
|
||||||
})
|
})
|
||||||
@@ -83,12 +83,12 @@ func runDiffCmd(ctx *cli.Context) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
switch iodine.ToError(err).(type) {
|
switch iodine.ToError(err).(type) {
|
||||||
case errUnsupportedScheme:
|
case errUnsupportedScheme:
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unknown type of URL ‘%s’", secondURL),
|
Message: fmt.Sprintf("Unknown type of URL ‘%s’", secondURL),
|
||||||
Error: err,
|
Error: err,
|
||||||
})
|
})
|
||||||
default:
|
default:
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unable to parse argument ‘%s’", secondURL),
|
Message: fmt.Sprintf("Unable to parse argument ‘%s’", secondURL),
|
||||||
Error: err,
|
Error: err,
|
||||||
})
|
})
|
||||||
@@ -98,7 +98,7 @@ func runDiffCmd(ctx *cli.Context) {
|
|||||||
newFirstURL := stripRecursiveURL(firstURL)
|
newFirstURL := stripRecursiveURL(firstURL)
|
||||||
for diff := range doDiffCmd(newFirstURL, secondURL, isURLRecursive(firstURL)) {
|
for diff := range doDiffCmd(newFirstURL, secondURL, isURLRecursive(firstURL)) {
|
||||||
if diff.err != nil {
|
if diff.err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: diff.message,
|
Message: diff.message,
|
||||||
Error: diff.err,
|
Error: diff.err,
|
||||||
})
|
})
|
||||||
|
|||||||
12
cmd-ls.go
12
cmd-ls.go
@@ -31,14 +31,14 @@ func runListCmd(ctx *cli.Context) {
|
|||||||
cli.ShowCommandHelpAndExit(ctx, "ls", 1) // last argument is exit code
|
cli.ShowCommandHelpAndExit(ctx, "ls", 1) // last argument is exit code
|
||||||
}
|
}
|
||||||
if !isMcConfigExist() {
|
if !isMcConfigExist() {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: "Please run \"mc config generate\"",
|
Message: "Please run \"mc config generate\"",
|
||||||
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
|
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
config, err := getMcConfig()
|
config, err := getMcConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unable to read config file ‘%s’", mustGetMcConfigPath()),
|
Message: fmt.Sprintf("Unable to read config file ‘%s’", mustGetMcConfigPath()),
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
@@ -49,12 +49,12 @@ func runListCmd(ctx *cli.Context) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
switch e := iodine.ToError(err).(type) {
|
switch e := iodine.ToError(err).(type) {
|
||||||
case errUnsupportedScheme:
|
case errUnsupportedScheme:
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unknown type of URL ‘%s’", e.url),
|
Message: fmt.Sprintf("Unknown type of URL ‘%s’", e.url),
|
||||||
Error: iodine.New(e, nil),
|
Error: iodine.New(e, nil),
|
||||||
})
|
})
|
||||||
default:
|
default:
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unable to parse argument ‘%s’", arg),
|
Message: fmt.Sprintf("Unable to parse argument ‘%s’", arg),
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
@@ -62,7 +62,7 @@ func runListCmd(ctx *cli.Context) {
|
|||||||
}
|
}
|
||||||
targetConfig, err := getHostConfig(targetURL)
|
targetConfig, err := getHostConfig(targetURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unable to read host configuration for ‘%s’ from config file ‘%s’", targetURL, mustGetMcConfigPath()),
|
Message: fmt.Sprintf("Unable to read host configuration for ‘%s’ from config file ‘%s’", targetURL, mustGetMcConfigPath()),
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
@@ -74,7 +74,7 @@ func runListCmd(ctx *cli.Context) {
|
|||||||
newTargetURL := stripRecursiveURL(targetURL)
|
newTargetURL := stripRecursiveURL(targetURL)
|
||||||
err = doListCmd(newTargetURL, targetConfig, isURLRecursive(targetURL))
|
err = doListCmd(newTargetURL, targetConfig, isURLRecursive(targetURL))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Failed to list ‘%s’", targetURL),
|
Message: fmt.Sprintf("Failed to list ‘%s’", targetURL),
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
|
|||||||
12
cmd-mb.go
12
cmd-mb.go
@@ -33,14 +33,14 @@ func runMakeBucketCmd(ctx *cli.Context) {
|
|||||||
cli.ShowCommandHelpAndExit(ctx, "mb", 1) // last argument is exit code
|
cli.ShowCommandHelpAndExit(ctx, "mb", 1) // last argument is exit code
|
||||||
}
|
}
|
||||||
if !isMcConfigExist() {
|
if !isMcConfigExist() {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: "Please run \"mc config generate\"",
|
Message: "Please run \"mc config generate\"",
|
||||||
Error: errors.New("\"mc\" is not configured"),
|
Error: errors.New("\"mc\" is not configured"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
config, err := getMcConfig()
|
config, err := getMcConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: "Unable to read config file ‘" + mustGetMcConfigPath() + "’",
|
Message: "Unable to read config file ‘" + mustGetMcConfigPath() + "’",
|
||||||
Error: err,
|
Error: err,
|
||||||
})
|
})
|
||||||
@@ -51,12 +51,12 @@ func runMakeBucketCmd(ctx *cli.Context) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
switch e := iodine.ToError(err).(type) {
|
switch e := iodine.ToError(err).(type) {
|
||||||
case errUnsupportedScheme:
|
case errUnsupportedScheme:
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unknown type of URL ‘%s’", e.url),
|
Message: fmt.Sprintf("Unknown type of URL ‘%s’", e.url),
|
||||||
Error: e,
|
Error: e,
|
||||||
})
|
})
|
||||||
default:
|
default:
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unable to parse argument ‘%s’", arg),
|
Message: fmt.Sprintf("Unable to parse argument ‘%s’", arg),
|
||||||
Error: err,
|
Error: err,
|
||||||
})
|
})
|
||||||
@@ -64,7 +64,7 @@ func runMakeBucketCmd(ctx *cli.Context) {
|
|||||||
}
|
}
|
||||||
targetConfig, err := getHostConfig(targetURL)
|
targetConfig, err := getHostConfig(targetURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unable to read host configuration for ‘%s’ from config file ‘%s’", targetURL, mustGetMcConfigPath()),
|
Message: fmt.Sprintf("Unable to read host configuration for ‘%s’ from config file ‘%s’", targetURL, mustGetMcConfigPath()),
|
||||||
Error: err,
|
Error: err,
|
||||||
})
|
})
|
||||||
@@ -74,7 +74,7 @@ func runMakeBucketCmd(ctx *cli.Context) {
|
|||||||
for targetURL, targetConfig := range targetURLConfigMap {
|
for targetURL, targetConfig := range targetURLConfigMap {
|
||||||
errorMsg, err := doMakeBucketCmd(targetURL, targetConfig)
|
errorMsg, err := doMakeBucketCmd(targetURL, targetConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Errorln(ErrorMessage{
|
console.Errors(ErrorMessage{
|
||||||
Message: errorMsg,
|
Message: errorMsg,
|
||||||
Error: err,
|
Error: err,
|
||||||
})
|
})
|
||||||
|
|||||||
12
cmd-sync.go
12
cmd-sync.go
@@ -33,7 +33,7 @@ func runSyncCmd(ctx *cli.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !isMcConfigExist() {
|
if !isMcConfigExist() {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: "Please run \"mc config generate\"",
|
Message: "Please run \"mc config generate\"",
|
||||||
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
|
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
|
||||||
})
|
})
|
||||||
@@ -41,7 +41,7 @@ func runSyncCmd(ctx *cli.Context) {
|
|||||||
|
|
||||||
URLs, err := args2URLs(ctx.Args())
|
URLs, err := args2URLs(ctx.Args())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unknown URL types found: ‘%s’", URLs),
|
Message: fmt.Sprintf("Unknown URL types found: ‘%s’", URLs),
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
@@ -76,7 +76,7 @@ func runSyncCmd(ctx *cli.Context) {
|
|||||||
|
|
||||||
for syncURLs := range prepareSyncURLs(sourceURL, targetURLs) {
|
for syncURLs := range prepareSyncURLs(sourceURL, targetURLs) {
|
||||||
if syncURLs.Error != nil {
|
if syncURLs.Error != nil {
|
||||||
console.Errorln(ErrorMessage{
|
console.Errors(ErrorMessage{
|
||||||
Message: "Failed with",
|
Message: "Failed with",
|
||||||
Error: iodine.New(syncURLs.Error, nil),
|
Error: iodine.New(syncURLs.Error, nil),
|
||||||
})
|
})
|
||||||
@@ -88,7 +88,7 @@ func runSyncCmd(ctx *cli.Context) {
|
|||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
srcConfig, err := getHostConfig(syncURLs.SourceContent.Name)
|
srcConfig, err := getHostConfig(syncURLs.SourceContent.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: "Failed with",
|
Message: "Failed with",
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
@@ -96,14 +96,14 @@ func runSyncCmd(ctx *cli.Context) {
|
|||||||
}
|
}
|
||||||
tgtConfig, err := getHostConfig(syncURLs.TargetContent.Name)
|
tgtConfig, err := getHostConfig(syncURLs.TargetContent.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: "Failed with",
|
Message: "Failed with",
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := doCopy(syncURLs.SourceContent.Name, srcConfig, syncURLs.TargetContent.Name, tgtConfig, bar); err != nil {
|
if err := doCopy(syncURLs.SourceContent.Name, srcConfig, syncURLs.TargetContent.Name, tgtConfig, bar); err != nil {
|
||||||
console.Errorln(ErrorMessage{
|
console.Errors(ErrorMessage{
|
||||||
Message: "Failed with",
|
Message: "Failed with",
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
mcUpdateURL = "http://dl.minio.io:9000/updates/2015/Apr" + "/mc" + "." + runtime.GOOS + "." + runtime.GOARCH
|
mcUpdateURL = "http://dl.minio.io:9000/updates/2015/June/" + "mc" + "." + runtime.GOOS + "." + runtime.GOARCH
|
||||||
)
|
)
|
||||||
|
|
||||||
func doUpdateCheck(config *hostConfig) (string, error) {
|
func doUpdateCheck(config *hostConfig) (string, error) {
|
||||||
@@ -38,7 +38,7 @@ func doUpdateCheck(config *hostConfig) (string, error) {
|
|||||||
}
|
}
|
||||||
latest, err := clnt.Stat()
|
latest, err := clnt.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "No update available at this time", nil
|
return "No new update available at this time", nil
|
||||||
}
|
}
|
||||||
current, _ := time.Parse(time.RFC3339Nano, BuildDate)
|
current, _ := time.Parse(time.RFC3339Nano, BuildDate)
|
||||||
if current.IsZero() {
|
if current.IsZero() {
|
||||||
@@ -58,21 +58,21 @@ func runUpdateCmd(ctx *cli.Context) {
|
|||||||
cli.ShowCommandHelpAndExit(ctx, "update", 1) // last argument is exit code
|
cli.ShowCommandHelpAndExit(ctx, "update", 1) // last argument is exit code
|
||||||
}
|
}
|
||||||
if !isMcConfigExist() {
|
if !isMcConfigExist() {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: "Please run \"mc config generate\"",
|
Message: "Please run \"mc config generate\"",
|
||||||
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
|
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
hostConfig, err := getHostConfig(mcUpdateURL)
|
hostConfig, err := getHostConfig(mcUpdateURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unable to read configuration for host ‘%s’", mcUpdateURL),
|
Message: fmt.Sprintf("Unable to read configuration for host ‘%s’", mcUpdateURL),
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
msg, err := doUpdateCheck(hostConfig)
|
msg, err := doUpdateCheck(hostConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: msg,
|
Message: msg,
|
||||||
Error: iodine.New(err, nil),
|
Error: iodine.New(err, nil),
|
||||||
})
|
})
|
||||||
|
|||||||
10
main.go
10
main.go
@@ -35,7 +35,7 @@ import (
|
|||||||
func checkConfig() {
|
func checkConfig() {
|
||||||
_, err := user.Current()
|
_, err := user.Current()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: "Unable to determine current user",
|
Message: "Unable to determine current user",
|
||||||
Error: err,
|
Error: err,
|
||||||
})
|
})
|
||||||
@@ -49,7 +49,7 @@ func checkConfig() {
|
|||||||
// Ensures config file is sane
|
// Ensures config file is sane
|
||||||
_, err = getMcConfig()
|
_, err = getMcConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Unable to read config file: %s", mustGetMcConfigPath()),
|
Message: fmt.Sprintf("Unable to read config file: %s", mustGetMcConfigPath()),
|
||||||
Error: err,
|
Error: err,
|
||||||
})
|
})
|
||||||
@@ -120,14 +120,14 @@ func main() {
|
|||||||
themeName := ctx.GlobalString("theme")
|
themeName := ctx.GlobalString("theme")
|
||||||
switch {
|
switch {
|
||||||
case console.IsValidTheme(themeName) != true:
|
case console.IsValidTheme(themeName) != true:
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Please choose from this list: %s.", console.GetThemeNames()),
|
Message: fmt.Sprintf("Please choose from this list: %s.", console.GetThemeNames()),
|
||||||
Error: fmt.Errorf("Theme ‘%s’ is not supported.", themeName),
|
Error: fmt.Errorf("Theme ‘%s’ is not supported.", themeName),
|
||||||
})
|
})
|
||||||
default:
|
default:
|
||||||
err := console.SetTheme(themeName)
|
err := console.SetTheme(themeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: fmt.Sprintf("Failed to set theme ‘%s’.", themeName),
|
Message: fmt.Sprintf("Failed to set theme ‘%s’.", themeName),
|
||||||
Error: err,
|
Error: err,
|
||||||
})
|
})
|
||||||
@@ -138,7 +138,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
app.After = func(ctx *cli.Context) error {
|
app.After = func(ctx *cli.Context) error {
|
||||||
if !isMcConfigExist() {
|
if !isMcConfigExist() {
|
||||||
console.Fatalln(ErrorMessage{
|
console.Fatals(ErrorMessage{
|
||||||
Message: "Please run \"mc config generate\"",
|
Message: "Please run \"mc config generate\"",
|
||||||
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
|
Error: iodine.New(errors.New("\"mc\" is not configured"), nil),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -123,30 +123,58 @@ var (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fatal prints a error message and exits
|
// Prints prints a structured message with a newline
|
||||||
Fatal = func(data ...interface{}) {
|
Prints = func(data ...interface{}) {
|
||||||
defer os.Exit(1)
|
|
||||||
for i := 0; i < len(data); i++ {
|
for i := 0; i < len(data); i++ {
|
||||||
err := readErrorFromdata(data[i])
|
|
||||||
if err != nil {
|
|
||||||
if NoJSONPrint {
|
if NoJSONPrint {
|
||||||
print(themesDB[currThemeName].Error, data[i])
|
println(themesDB[currThemeName].Info, data[i])
|
||||||
if !NoDebugPrint {
|
|
||||||
print(themesDB[currThemeName].Error, err)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
infoBytes, _ := json.Marshal(&data[i])
|
||||||
|
println(themesDB[currThemeName].JSON, string(infoBytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Fatal print a error message and exit
|
||||||
|
Fatal = func(data ...interface{}) {
|
||||||
|
defer os.Exit(1)
|
||||||
|
if NoJSONPrint {
|
||||||
|
print(themesDB[currThemeName].Error, data...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for i := 0; i < len(data); i++ {
|
||||||
errorMessageBytes, _ := json.Marshal(&data[i])
|
errorMessageBytes, _ := json.Marshal(&data[i])
|
||||||
print(themesDB[currThemeName].JSON, string(errorMessageBytes))
|
print(themesDB[currThemeName].JSON, string(errorMessageBytes))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fatalf print a error message with a format specified and exit
|
||||||
|
Fatalf = func(f string, data ...interface{}) {
|
||||||
|
defer os.Exit(1)
|
||||||
|
if NoJSONPrint {
|
||||||
|
printf(themesDB[currThemeName].Error, f, data...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for i := 0; i < len(data); i++ {
|
||||||
|
errorMessageBytes, _ := json.Marshal(&data[i])
|
||||||
|
printf(themesDB[currThemeName].JSON, "", string(errorMessageBytes))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fatalf is undefined since under the context of typed messages formatting
|
// Fatalln print a error message with a new line and exit
|
||||||
// is already done before caller invokes console.Fatal*
|
|
||||||
|
|
||||||
// Fatalln prints a error message with a new line and exits
|
|
||||||
Fatalln = func(data ...interface{}) {
|
Fatalln = func(data ...interface{}) {
|
||||||
|
defer os.Exit(1)
|
||||||
|
if NoJSONPrint {
|
||||||
|
println(themesDB[currThemeName].Error, data...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for i := 0; i < len(data); i++ {
|
||||||
|
errorMessageBytes, _ := json.Marshal(&data[i])
|
||||||
|
println(themesDB[currThemeName].JSON, string(errorMessageBytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fatals print a error structure with a new line and exit
|
||||||
|
Fatals = func(data ...interface{}) {
|
||||||
defer os.Exit(1)
|
defer os.Exit(1)
|
||||||
for i := 0; i < len(data); i++ {
|
for i := 0; i < len(data); i++ {
|
||||||
err := readErrorFromdata(data[i])
|
err := readErrorFromdata(data[i])
|
||||||
@@ -154,7 +182,7 @@ var (
|
|||||||
if NoJSONPrint {
|
if NoJSONPrint {
|
||||||
println(themesDB[currThemeName].Error, data[i])
|
println(themesDB[currThemeName].Error, data[i])
|
||||||
if !NoDebugPrint {
|
if !NoDebugPrint {
|
||||||
println(themesDB[currThemeName].Error, err)
|
print(themesDB[currThemeName].Error, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -166,34 +194,49 @@ var (
|
|||||||
|
|
||||||
// Error prints a error message
|
// Error prints a error message
|
||||||
Error = func(data ...interface{}) {
|
Error = func(data ...interface{}) {
|
||||||
for i := 0; i < len(data); i++ {
|
|
||||||
err := readErrorFromdata(data[i])
|
|
||||||
if err != nil {
|
|
||||||
if NoJSONPrint {
|
if NoJSONPrint {
|
||||||
print(themesDB[currThemeName].Error, data[i])
|
print(themesDB[currThemeName].Error, data...)
|
||||||
if !NoDebugPrint {
|
|
||||||
print(themesDB[currThemeName].Error, err)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
for i := 0; i < len(data); i++ {
|
||||||
errorMessageBytes, _ := json.Marshal(&data[i])
|
errorMessageBytes, _ := json.Marshal(&data[i])
|
||||||
print(themesDB[currThemeName].JSON, string(errorMessageBytes))
|
print(themesDB[currThemeName].JSON, string(errorMessageBytes))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Errorf is undefined since under the context of typed messages formatting
|
// Errorf print a error message with a format specified
|
||||||
// is already done before caller invokes console.Error*
|
Errorf = func(f string, data ...interface{}) {
|
||||||
|
if NoJSONPrint {
|
||||||
|
printf(themesDB[currThemeName].Error, f, data...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for i := 0; i < len(data); i++ {
|
||||||
|
errorMessageBytes, _ := json.Marshal(&data[i])
|
||||||
|
printf(themesDB[currThemeName].JSON, "", string(errorMessageBytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Errorln prints a error message with a new line
|
// Errorln prints a error message with a new line
|
||||||
Errorln = func(data ...interface{}) {
|
Errorln = func(data ...interface{}) {
|
||||||
|
if NoJSONPrint {
|
||||||
|
println(themesDB[currThemeName].Error, data...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for i := 0; i < len(data); i++ {
|
||||||
|
errorMessageBytes, _ := json.Marshal(&data[i])
|
||||||
|
println(themesDB[currThemeName].JSON, string(errorMessageBytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Errors print a error structure with a new line
|
||||||
|
Errors = func(data ...interface{}) {
|
||||||
for i := 0; i < len(data); i++ {
|
for i := 0; i < len(data); i++ {
|
||||||
err := readErrorFromdata(data[i])
|
err := readErrorFromdata(data[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if NoJSONPrint {
|
if NoJSONPrint {
|
||||||
println(themesDB[currThemeName].Error, data[i])
|
println(themesDB[currThemeName].Error, data[i])
|
||||||
if !NoDebugPrint {
|
if !NoDebugPrint {
|
||||||
println(themesDB[currThemeName].Error, err)
|
print(themesDB[currThemeName].Error, err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -239,6 +282,18 @@ var (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Infos print a informational structured message
|
||||||
|
Infos = func(data ...interface{}) {
|
||||||
|
for i := 0; i < len(data); i++ {
|
||||||
|
if NoJSONPrint {
|
||||||
|
println(themesDB[currThemeName].Info, data[i])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
infoBytes, _ := json.Marshal(&data[i])
|
||||||
|
println(themesDB[currThemeName].JSON, string(infoBytes))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Debug prints a debug message without a new line
|
// Debug prints a debug message without a new line
|
||||||
// Debug prints a debug message
|
// Debug prints a debug message
|
||||||
Debug = func(a ...interface{}) {
|
Debug = func(a ...interface{}) {
|
||||||
@@ -328,6 +383,22 @@ var (
|
|||||||
c.Printf(f, a...)
|
c.Printf(f, a...)
|
||||||
color.Output = output
|
color.Output = output
|
||||||
mutex.Unlock()
|
mutex.Unlock()
|
||||||
|
case themesDB[currThemeName].Fatal:
|
||||||
|
mutex.Lock()
|
||||||
|
output := color.Output
|
||||||
|
color.Output = stderrColoredOutput
|
||||||
|
c.Print(ProgramName() + ": <FATAL> ")
|
||||||
|
c.Printf(f, a...)
|
||||||
|
color.Output = output
|
||||||
|
mutex.Unlock()
|
||||||
|
case themesDB[currThemeName].Error:
|
||||||
|
mutex.Lock()
|
||||||
|
output := color.Output
|
||||||
|
color.Output = stderrColoredOutput
|
||||||
|
c.Print(ProgramName() + ": <ERROR> ")
|
||||||
|
c.Printf(f, a...)
|
||||||
|
color.Output = output
|
||||||
|
mutex.Unlock()
|
||||||
case themesDB[currThemeName].Info:
|
case themesDB[currThemeName].Info:
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
c.Print(ProgramName() + ": ")
|
c.Print(ProgramName() + ": ")
|
||||||
|
|||||||
Reference in New Issue
Block a user