From 6a59d9a04691bc7cc1cb1170a3c3da5385d1c2c9 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Wed, 12 Aug 2015 01:26:35 -0700 Subject: [PATCH] Rename all main command actions into main from runCmd --- access-main.go | 4 ++-- config-main.go | 6 +++--- cp-main.go | 6 +++--- diff-main.go | 6 +++--- ls-main.go | 12 ++++-------- ls.go | 4 ++-- mb-main.go | 6 +++--- mirror-main.go | 4 ++-- session-main.go | 4 ++-- share-main.go | 6 +++--- update-main.go | 48 ++++++++++++++++++++++-------------------------- 11 files changed, 49 insertions(+), 57 deletions(-) diff --git a/access-main.go b/access-main.go index 75d25924..f8faa6f8 100644 --- a/access-main.go +++ b/access-main.go @@ -26,7 +26,7 @@ import ( var accessCmd = cli.Command{ Name: "access", Usage: "Set access permissions", - Action: runAccessCmd, + Action: mainAccess, CustomHelpTemplate: `Name: mc {{.Name}} - {{.Usage}} @@ -57,7 +57,7 @@ EXAMPLES: `, } -func runAccessCmd(ctx *cli.Context) { +func mainAccess(ctx *cli.Context) { if !ctx.Args().Present() || ctx.Args().First() == "help" { cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code } diff --git a/config-main.go b/config-main.go index 23ad9e92..1e146184 100644 --- a/config-main.go +++ b/config-main.go @@ -38,7 +38,7 @@ import ( var configCmd = cli.Command{ Name: "config", Usage: "Add new alias to default configuration file [~/.mc/config.json]", - Action: runConfigCmd, + Action: mainConfig, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} @@ -52,8 +52,8 @@ EXAMPLES: `, } -// runConfigCmd is the handle for "mc config" sub-command -func runConfigCmd(ctx *cli.Context) { +// mainConfig is the handle for "mc config" sub-command +func mainConfig(ctx *cli.Context) { // show help if nothing is set if !ctx.Args().Present() || ctx.Args().First() == "help" { cli.ShowCommandHelpAndExit(ctx, "config", 1) // last argument is exit code diff --git a/cp-main.go b/cp-main.go index 395dd3ac..31251a4e 100644 --- a/cp-main.go +++ b/cp-main.go @@ -35,7 +35,7 @@ import ( var cpCmd = cli.Command{ Name: "cp", Usage: "Copy files and folders from many sources to a single destination", - Action: runCopyCmd, + Action: mainCopy, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} @@ -261,8 +261,8 @@ func doCopyCmdSession(session *sessionV2) { wg.Wait() } -// runCopyCmd is bound to sub-command -func runCopyCmd(ctx *cli.Context) { +// mainCopy is bound to sub-command +func mainCopy(ctx *cli.Context) { checkCopySyntax(ctx) session := newSessionV2() diff --git a/diff-main.go b/diff-main.go index 728805be..a9a824fd 100644 --- a/diff-main.go +++ b/diff-main.go @@ -27,7 +27,7 @@ var diffCmd = cli.Command{ Name: "diff", Usage: "Compute differences between two files or folders", Description: "NOTE: This command *DOES NOT* check for content similarity, which means objects with same size, but different content will not be spotted", - Action: runDiffCmd, + Action: mainDiff, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} @@ -51,8 +51,8 @@ EXAMPLES: `, } -// runDiffCmd - is a handler for mc diff command -func runDiffCmd(ctx *cli.Context) { +// mainDiff - is a handler for mc diff command +func mainDiff(ctx *cli.Context) { if len(ctx.Args()) != 2 || ctx.Args().First() == "help" { cli.ShowCommandHelpAndExit(ctx, "diff", 1) // last argument is exit code } diff --git a/ls-main.go b/ls-main.go index d2d1b62f..2edb1b68 100644 --- a/ls-main.go +++ b/ls-main.go @@ -25,7 +25,7 @@ import ( var lsCmd = cli.Command{ Name: "ls", Usage: "List files and folders", - Action: runListCmd, + Action: mainList, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} @@ -69,8 +69,8 @@ EXAMPLES: `, } -// runListCmd - is a handler for mc ls command -func runListCmd(ctx *cli.Context) { +// mainList - is a handler for mc ls command +func mainList(ctx *cli.Context) { args := ctx.Args() if globalAliasFlag { if !ctx.Args().Present() { @@ -96,9 +96,5 @@ func doListCmd(targetURL string, recursive bool) *probe.Error { if err != nil { return err.Trace() } - err = doList(clnt, recursive) - if err != nil { - return err.Trace() - } - return nil + return doList(clnt, recursive).Trace() } diff --git a/ls.go b/ls.go index 7c1c94e2..9ab2f819 100644 --- a/ls.go +++ b/ls.go @@ -79,11 +79,11 @@ func doList(clnt client.Client, recursive bool) *probe.Error { switch contentCh.Err.ToError().(type) { // handle this specifically for filesystem case client.ISBrokenSymlink: - errorIf(contentCh.Err) + errorIf(contentCh.Err.Trace()) continue } if os.IsNotExist(contentCh.Err.ToError()) || os.IsPermission(contentCh.Err.ToError()) { - errorIf(contentCh.Err) + errorIf(contentCh.Err.Trace()) continue } err = contentCh.Err.Trace() diff --git a/mb-main.go b/mb-main.go index 7447a464..d71c5a7f 100644 --- a/mb-main.go +++ b/mb-main.go @@ -26,7 +26,7 @@ import ( var mbCmd = cli.Command{ Name: "mb", Usage: "Make a bucket or folder", - Action: runMakeBucketCmd, + Action: mainMakeBucket, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} @@ -52,8 +52,8 @@ EXAMPLES: `, } -// runMakeBucketCmd is the handler for mc mb command -func runMakeBucketCmd(ctx *cli.Context) { +// mainMakeBucket is the handler for mc mb command +func mainMakeBucket(ctx *cli.Context) { if !ctx.Args().Present() || ctx.Args().First() == "help" { cli.ShowCommandHelpAndExit(ctx, "mb", 1) // last argument is exit code } diff --git a/mirror-main.go b/mirror-main.go index 44a60cf8..960a8ed0 100644 --- a/mirror-main.go +++ b/mirror-main.go @@ -35,7 +35,7 @@ import ( var mirrorCmd = cli.Command{ Name: "mirror", Usage: "Mirror files and folders from a single source to many destinations", - Action: runMirrorCmd, + Action: mainMirror, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} @@ -261,7 +261,7 @@ func doMirrorCmdSession(session *sessionV2) { wg.Wait() } -func runMirrorCmd(ctx *cli.Context) { +func mainMirror(ctx *cli.Context) { checkMirrorSyntax(ctx) session := newSessionV2() diff --git a/session-main.go b/session-main.go index fcd1c2ac..265c3307 100644 --- a/session-main.go +++ b/session-main.go @@ -30,7 +30,7 @@ import ( var sessionCmd = cli.Command{ Name: "session", Usage: "Manage sessions for cp and mirror", - Action: runSessionCmd, + Action: mainSession, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} @@ -111,7 +111,7 @@ func sessionExecute(s *sessionV2) { } } -func runSessionCmd(ctx *cli.Context) { +func mainSession(ctx *cli.Context) { if len(ctx.Args()) < 1 || ctx.Args().First() == "help" { cli.ShowCommandHelpAndExit(ctx, "session", 1) // last argument is exit code } diff --git a/share-main.go b/share-main.go index b79d497a..a6f17813 100644 --- a/share-main.go +++ b/share-main.go @@ -32,7 +32,7 @@ import ( var shareCmd = cli.Command{ Name: "share", Usage: "Share presigned URLs from cloud storage", - Action: runShareCmd, + Action: mainShare, CustomHelpTemplate: `NAME: mc {{.Name}} - {{.Usage}} @@ -56,8 +56,8 @@ EXAMPLES: `, } -// runShareCmd - is a handler for mc share command -func runShareCmd(ctx *cli.Context) { +// mainShare - is a handler for mc share command +func mainShare(ctx *cli.Context) { if !ctx.Args().Present() || ctx.Args().First() == "help" || len(ctx.Args()) > 2 { cli.ShowCommandHelpAndExit(ctx, "share", 1) // last argument is exit code } diff --git a/update-main.go b/update-main.go index 03c44293..2dfc8e48 100644 --- a/update-main.go +++ b/update-main.go @@ -41,7 +41,7 @@ const ( var updateCmd = cli.Command{ Name: "update", Usage: "Check for new software updates", - Action: runUpdateCmd, + Action: mainUpdate, CustomHelpTemplate: `Name: mc {{.Name}} - {{.Usage}} @@ -55,29 +55,38 @@ EXAMPLES: `, } -func doUpdateCheck() (string, *probe.Error) { +// mainUpdate - +func mainUpdate(ctx *cli.Context) { + if ctx.Args().First() == "help" { + cli.ShowCommandHelpAndExit(ctx, "update", 1) // last argument is exit code + } + fatalIf(doUpdateCheck()) +} + +func doUpdateCheck() *probe.Error { clnt, err := url2Client(mcUpdateURL) if err != nil { - return "Unable to create client: " + mcUpdateURL, err.Trace() + return err.Trace(mcUpdateURL) } data, _, err := clnt.GetObject(0, 0) if err != nil { - return "Unable to read: " + mcUpdateURL, err.Trace() + return err.Trace(mcUpdateURL) } current, _ := time.Parse(time.RFC3339Nano, Version) if current.IsZero() { - message := `Version is empty, must be a custom build cannot update. Please download releases from -https://dl.minio.io:9000 for continuous updates` - return message, nil + console.Infoln(`Version is empty, must be a custom build cannot update. Please download releases from +https://dl.minio.io:9000 for continuous updates`) + return nil } var updates Updates decoder := json.NewDecoder(data) if err := decoder.Decode(&updates); err != nil { - return "Unable to parse update fields", probe.NewError(err) + return probe.NewError(err) } latest, _ := time.Parse(http.TimeFormat, updates.BuildDate) if latest.IsZero() { - return "No update available at this time", nil + console.Infoln("No update available at this time") + return nil } mcUpdateURLParse := clnt.URL() if latest.After(current) { @@ -89,24 +98,11 @@ https://dl.minio.io:9000 for continuous updates` } msg, err := printUpdateNotify(updateString, "new", "old") if err != nil { - return "", probe.NewError(err) + return probe.NewError(err) } console.Println(msg) - return "", nil - } - return "You are already running the most recent version of ‘mc’", nil - -} - -// runUpdateCmd - -func runUpdateCmd(ctx *cli.Context) { - if ctx.Args().First() == "help" { - cli.ShowCommandHelpAndExit(ctx, "update", 1) // last argument is exit code - } - msg, err := doUpdateCheck() - fatalIf(err) - // no msg do not print one - if msg != "" { - console.Infoln(msg) + return nil } + console.Infoln("You are already running the most recent version of ‘mc’") + return nil }