Merge pull request #1473 from harshavardhana/fix-bug

mc: Fix setGlobalContext across all commands.
This commit is contained in:
Harshavardhana
2015-11-22 00:41:04 -08:00
20 changed files with 68 additions and 61 deletions
+4 -3
View File
@@ -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())
+3 -2
View File
@@ -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() {
+4 -3
View File
@@ -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()
+4 -3
View File
@@ -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()
+1 -1
View File
@@ -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.
}
-5
View File
@@ -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)
+4 -3
View File
@@ -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")
+4 -3
View File
@@ -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")
+4 -4
View File
@@ -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{"."}
}
-1
View File
@@ -170,7 +170,6 @@ func main() {
if _, e := ts.GetSize(); e != nil {
globalQuiet = true
}
if globalDebug {
return getSystemData()
}
+4 -3
View File
@@ -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.")
+4 -3
View File
@@ -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
+3
View File
@@ -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
}
+4 -3
View File
@@ -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.
+4 -3
View File
@@ -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.")
}
+6 -6
View File
@@ -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
+3 -3
View File
@@ -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()
+6 -6
View File
@@ -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")
+3 -3
View File
@@ -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)
+3 -3
View File
@@ -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