diff --git a/access-main.go b/access-main.go index dd233921..e155c903 100644 --- a/access-main.go +++ b/access-main.go @@ -156,14 +156,15 @@ func doGetAccess(targetURL string) (perms accessPerms, err *probe.Error) { } func mainAccess(ctx *cli.Context) { + // Set global flags from context. + setGlobalsFromContext(ctx) + + // check 'access' cli arguments. checkAccessSyntax(ctx) // Additional command speific theme customization. console.SetColor("Access", color.New(color.FgGreen, color.Bold)) - // Set global flags from context. - setGlobalsFromContext(ctx) - switch ctx.Args().First() { case "set": perms := accessPerms(ctx.Args().Tail().First()) diff --git a/cat-main.go b/cat-main.go index 5b03ab32..4422d2df 100644 --- a/cat-main.go +++ b/cat-main.go @@ -121,11 +121,12 @@ func catOut(r io.Reader) *probe.Error { // mainCat is the main entry point for cat command. func mainCat(ctx *cli.Context) { - checkCatSyntax(ctx) - // Set global flags from context. setGlobalsFromContext(ctx) + // check 'cat' cli arguments. + checkCatSyntax(ctx) + // Set command flags from context. stdinMode := false if !ctx.Args().Present() { diff --git a/config-alias-main.go b/config-alias-main.go index ee90a7a3..2552cfb0 100644 --- a/config-alias-main.go +++ b/config-alias-main.go @@ -202,6 +202,10 @@ func listAliases() { } func mainConfigAlias(ctx *cli.Context) { + // Set global flags from context. + setGlobalsFromContext(ctx) + + // check 'config alias' cli arguments. checkConfigAliasSyntax(ctx) // Additional customization speific to each command. @@ -209,9 +213,6 @@ func mainConfigAlias(ctx *cli.Context) { console.SetColor("AliasMessage", color.New(color.FgGreen, color.Bold)) console.SetColor("URL", color.New(color.FgWhite, color.Bold)) - // Set global flags from context. - setGlobalsFromContext(ctx) - arg := ctx.Args().First() tailArgs := ctx.Args().Tail() diff --git a/config-host-main.go b/config-host-main.go index 2960fdfa..13c83324 100644 --- a/config-host-main.go +++ b/config-host-main.go @@ -214,6 +214,10 @@ func checkConfigHostRemoveSyntax(ctx *cli.Context) { } func mainConfigHost(ctx *cli.Context) { + // Set global flags from context. + setGlobalsFromContext(ctx) + + // check 'config host' cli arguments. checkConfigHostSyntax(ctx) // Additional command speific theme customization. @@ -223,9 +227,6 @@ func mainConfigHost(ctx *cli.Context) { console.SetColor("AccessKeyID", color.New(color.FgBlue, color.Bold)) console.SetColor("SecretAccessKey", color.New(color.FgRed, color.Bold)) - // Set global flags from context. - setGlobalsFromContext(ctx) - arg := ctx.Args().First() tailArgs := ctx.Args().Tail() diff --git a/config-main.go b/config-main.go index 22536e7b..9471b5d2 100644 --- a/config-main.go +++ b/config-main.go @@ -73,5 +73,5 @@ func mainConfig(ctx *cli.Context) { cli.ShowAppHelp(ctx) } - // sub-commands like "upload" and "download" have their own main. + // Sub-commands like "host" and "alias" have their own main. } diff --git a/config-version-main.go b/config-version-main.go index 883a93ce..24d04cf1 100644 --- a/config-version-main.go +++ b/config-version-main.go @@ -42,15 +42,10 @@ var configVersionCmd = cli.Command{ USAGE: mc config {{.Name}} - `, } func mainConfigVersion(ctx *cli.Context) { - if ctx.Args().First() == "help" { - cli.ShowCommandHelpAndExit(ctx, "version", 1) // last argument is exit code - } - // Set global flags from context. setGlobalsFromContext(ctx) diff --git a/cp-main.go b/cp-main.go index 2e0cf9a5..9ca69ca4 100644 --- a/cp-main.go +++ b/cp-main.go @@ -380,14 +380,15 @@ func doCopySession(session *sessionV5) { // mainCopy is the entry point for cp command. func mainCopy(ctx *cli.Context) { + // Set global flags from context. + setGlobalsFromContext(ctx) + + // check 'copy' cli arguments. checkCopySyntax(ctx) // Additional command speific theme customization. console.SetColor("Copy", color.New(color.FgGreen, color.Bold)) - // Set global flags from context. - setGlobalsFromContext(ctx) - session := newSessionV5() session.Header.CommandType = "cp" session.Header.CommandBoolFlags["recursive"] = ctx.Bool("recursive") diff --git a/diff-main.go b/diff-main.go index 78e0a65e..725ad020 100644 --- a/diff-main.go +++ b/diff-main.go @@ -170,6 +170,10 @@ func doDiffMain(firstURL, secondURL string) { // mainDiff main for 'diff'. func mainDiff(ctx *cli.Context) { + // Set global flags from context. + setGlobalsFromContext(ctx) + + // check 'diff' cli arguments. checkDiffSyntax(ctx) // Additional command specific theme customization. @@ -178,9 +182,6 @@ func mainDiff(ctx *cli.Context) { console.SetColor("DiffType", color.New(color.FgYellow, color.Bold)) console.SetColor("DiffSize", color.New(color.FgMagenta, color.Bold)) - // Set global flags from context. - setGlobalsFromContext(ctx) - URLs, err := args2URLs(ctx.Args()) fatalIf(err.Trace(ctx.Args()...), "Unable to convert args 2 URLs") diff --git a/ls-main.go b/ls-main.go index a8230507..f6018804 100644 --- a/ls-main.go +++ b/ls-main.go @@ -109,18 +109,18 @@ func mainList(ctx *cli.Context) { console.SetColor("Size", color.New(color.FgYellow)) console.SetColor("Time", color.New(color.FgGreen)) - // check 'ls' cli arguments - checkListSyntax(ctx) - // Set global flags from context. setGlobalsFromContext(ctx) + // check 'ls' cli arguments. + checkListSyntax(ctx) + // Set command flags from context. isRecursive := ctx.Bool("recursive") isIncomplete := ctx.Bool("incomplete") args := ctx.Args() - // mimic operating system tool behavior + // mimic operating system tool behavior. if !ctx.Args().Present() { args = []string{"."} } diff --git a/main.go b/main.go index 52802242..975fa77a 100644 --- a/main.go +++ b/main.go @@ -170,7 +170,6 @@ func main() { if _, e := ts.GetSize(); e != nil { globalQuiet = true } - if globalDebug { return getSystemData() } diff --git a/mb-main.go b/mb-main.go index 9bfd38ca..58d689a1 100644 --- a/mb-main.go +++ b/mb-main.go @@ -96,14 +96,15 @@ func checkMakeBucketSyntax(ctx *cli.Context) { // mainMakeBucket is entry point for mb command. func mainMakeBucket(ctx *cli.Context) { + // Set global flags from context. + setGlobalsFromContext(ctx) + + // check 'mb' cli arguments. checkMakeBucketSyntax(ctx) // Additional command speific theme customization. console.SetColor("MakeBucket", color.New(color.FgGreen, color.Bold)) - // Set global flags from context. - setGlobalsFromContext(ctx) - URLs, err := args2URLs(ctx.Args()) fatalIf(err.Trace(ctx.Args()...), "Unable to convert args to URLs.") diff --git a/mirror-main.go b/mirror-main.go index 4cd2d0ff..882485f3 100644 --- a/mirror-main.go +++ b/mirror-main.go @@ -364,6 +364,10 @@ func doMirrorSession(session *sessionV5) { // Main entry point for mirror command. func mainMirror(ctx *cli.Context) { + // Set global flags from context. + setGlobalsFromContext(ctx) + + // check 'mirror' cli arguments. checkMirrorSyntax(ctx) // Additional command speific theme customization. @@ -378,9 +382,6 @@ func mainMirror(ctx *cli.Context) { fatalIf(probe.NewError(e), "Unable to get current working folder.") } - // Set global flags from context. - setGlobalsFromContext(ctx) - // Set command flags from context. isForce := ctx.Bool("force") session.Header.CommandBoolFlags["force"] = isForce diff --git a/pkg/console/console.go b/pkg/console/console.go index 9d306230..0704b298 100644 --- a/pkg/console/console.go +++ b/pkg/console/console.go @@ -66,18 +66,21 @@ var ( // Fatal print a error message and exit. Fatal = func(data ...interface{}) { consolePrint("Fatal", Theme["Fatal"], data...) + os.Exit(1) return } // Fatalf print a error message with a format specified and exit. Fatalf = func(format string, data ...interface{}) { consolePrintf("Fatal", Theme["Fatal"], format, data...) + os.Exit(1) return } // Fatalln print a error message with a new line and exit. Fatalln = func(data ...interface{}) { consolePrintln("Fatal", Theme["Fatal"], data...) + os.Exit(1) return } diff --git a/rm-main.go b/rm-main.go index 6cf7303e..ebbc30aa 100644 --- a/rm-main.go +++ b/rm-main.go @@ -107,9 +107,6 @@ func (r rmMessage) JSON() string { // Validate command line arguments. func checkRmSyntax(ctx *cli.Context) { - // Set global flags from context. - setGlobalsFromContext(ctx) - // Set command flags from context. isForce := ctx.Bool("force") isRecursive := ctx.Bool("recursive") @@ -191,6 +188,10 @@ func rmAll(url string, isRecursive, isIncomplete, isFake bool) { // main for rm command. func mainRm(ctx *cli.Context) { + // Set global flags from context. + setGlobalsFromContext(ctx) + + // check 'rm' cli arguments. checkRmSyntax(ctx) // rm specific flags. diff --git a/session-main.go b/session-main.go index cd70fe50..ff92b003 100644 --- a/session-main.go +++ b/session-main.go @@ -193,6 +193,10 @@ func findClosestSessions(session string) []string { } func mainSession(ctx *cli.Context) { + // Set global flags from context. + setGlobalsFromContext(ctx) + + // check 'session' cli arguments. checkSessionSyntax(ctx) // Additional command speific theme customization. @@ -201,9 +205,6 @@ func mainSession(ctx *cli.Context) { console.SetColor("SessionTime", color.New(color.FgGreen)) console.SetColor("ClearSession", color.New(color.FgGreen, color.Bold)) - // Set global flags from context. - setGlobalsFromContext(ctx) - if !isSessionDirExists() { fatalIf(createSessionDir().Trace(), "Unable to create session folder.") } diff --git a/share-download-main.go b/share-download-main.go index 03ec2585..59ca7c1d 100644 --- a/share-download-main.go +++ b/share-download-main.go @@ -152,18 +152,18 @@ func doShareDownloadURL(targetURL string, isRecursive bool, expiry time.Duration // main for share download. func mainShareDownload(ctx *cli.Context) { + // Set global flags from context. + setGlobalsFromContext(ctx) + + // check input arguments. + checkShareDownloadSyntax(ctx) + // Initialize share config folder. initShareConfig() // Additional command speific theme customization. shareSetColor() - // check input arguments. - checkShareDownloadSyntax(ctx) - - // Set global flags from context. - setGlobalsFromContext(ctx) - // Set command flags from context. isRecursive := ctx.Bool("recursive") expiry := shareDefaultExpiry diff --git a/share-list-main.go b/share-list-main.go index eae667cd..7cddd377 100644 --- a/share-list-main.go +++ b/share-list-main.go @@ -104,15 +104,15 @@ func doShareList(cmd string) *probe.Error { // main entry point for share list. func mainShareList(ctx *cli.Context) { + // Set global flags from context. + setGlobalsFromContext(ctx) + // validate command-line args. checkShareListSyntax(ctx) // Additional command speific theme customization. shareSetColor() - // Set global flags from context. - setGlobalsFromContext(ctx) - // Initialize share config folder. initShareConfig() diff --git a/share-upload-main.go b/share-upload-main.go index 1482cdde..de90bce0 100644 --- a/share-upload-main.go +++ b/share-upload-main.go @@ -158,18 +158,18 @@ func doShareUploadURL(objectURL string, recursive bool, expiry time.Duration, co // main for share upload command. func mainShareUpload(ctx *cli.Context) { + // Set global flags from context. + setGlobalsFromContext(ctx) + + // check input arguments. + checkShareUploadSyntax(ctx) + // Initialize share config folder. initShareConfig() // Additional command speific theme customization. shareSetColor() - // check input arguments. - checkShareUploadSyntax(ctx) - - // Set global flags from context. - setGlobalsFromContext(ctx) - // Set command flags from context. isRecursive := ctx.Bool("recursive") expireArg := ctx.String("expire") diff --git a/update-main.go b/update-main.go index 2c4d8888..4ff059f2 100644 --- a/update-main.go +++ b/update-main.go @@ -165,12 +165,12 @@ func getReleaseUpdate(updateURL string) { // main entry point for update command. func mainUpdate(ctx *cli.Context) { - // Additional command speific theme customization. - console.SetColor("Update", color.New(color.FgGreen, color.Bold)) - // Set global flags from context. setGlobalsFromContext(ctx) + // Additional command speific theme customization. + console.SetColor("Update", color.New(color.FgGreen, color.Bold)) + // Check for update. if ctx.Bool("experimental") { getReleaseUpdate(mcUpdateExperimentalURL) diff --git a/version-main.go b/version-main.go index 057d616e..9c2164bc 100644 --- a/version-main.go +++ b/version-main.go @@ -78,14 +78,14 @@ func (v versionMessage) JSON() string { } func mainVersion(ctx *cli.Context) { + // Set global flags from context. + setGlobalsFromContext(ctx) + // Additional command speific theme customization. console.SetColor("Version", color.New(color.FgGreen, color.Bold)) console.SetColor("ReleaseTag", color.New(color.FgGreen)) console.SetColor("CommitID", color.New(color.FgGreen)) - // Set global flags from context. - setGlobalsFromContext(ctx) - verMsg := versionMessage{} verMsg.CommitID = mcCommitID verMsg.ReleaseTag = mcReleaseTag