Merge pull request #989 from harshavardhana/rename-mainfuncs
Rename all main command actions into main<Command> from run<Command>Cmd
This commit is contained in:
+2
-2
@@ -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
|
||||
}
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
+3
-3
@@ -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()
|
||||
|
||||
+3
-3
@@ -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
|
||||
}
|
||||
|
||||
+4
-8
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
+3
-3
@@ -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
|
||||
}
|
||||
|
||||
+2
-2
@@ -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()
|
||||
|
||||
+2
-2
@@ -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
|
||||
}
|
||||
|
||||
+3
-3
@@ -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
|
||||
}
|
||||
|
||||
+22
-26
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user