func registerBefore(ctx *cli.Context) error { setMcConfigDir(ctx.GlobalString("config")) globalQuietFlag = ctx.GlobalBool("quiet") globalForceFlag = ctx.GlobalBool("force") globalAliasFlag = ctx.GlobalBool("alias") globalDebugFlag = ctx.GlobalBool("debug") globalJSONFlag = ctx.GlobalBool("json") themeName := ctx.GlobalString("theme") if globalDebugFlag { console.NoDebugPrint = false } switch { case console.IsValidTheme(themeName) != true: console.Errorf("Invalid theme, please choose from the following list: %s.\n", console.GetThemeNames()) return errInvalidTheme{Theme: themeName} default: err := console.SetTheme(themeName) if err != nil { console.Errorf("Failed to set theme ‘%s’.", themeName) return err } } // Migrate any old version of config / state files to newer format. migrate() checkConfig() return nil }
func main() { // Migrate any old version of config / state files to newer format. migrate() // Enable GOMAXPROCS to default to number of CPUs. runtime.GOMAXPROCS(runtime.NumCPU()) // Register all the commands registerCmd(lsCmd) // List contents of a bucket registerCmd(mbCmd) // make a bucket registerCmd(catCmd) // concantenate an object to standard output registerCmd(cpCmd) // copy objects and files from multiple sources to single destination registerCmd(castCmd) // cast objects and files from single source to multiple destinations registerCmd(sessionCmd) // session handling for resuming copy and cast operations registerCmd(diffCmd) // compare two objects registerCmd(accessCmd) // set permissions [public, private, readonly, authenticated] for buckets and folders. registerCmd(configCmd) // generate configuration "/home/harsha/.mc/config.json" file. registerCmd(updateCmd) // update Check for new software updates // register all the flags registerFlag(configFlag) // path to config folder registerFlag(quietFlag) // suppress console output registerFlag(forceFlag) // force copying data registerFlag(aliasFlag) // OS toolchain mimic registerFlag(themeFlag) // console theme flag registerFlag(jsonFlag) // json formatted output registerFlag(debugFlag) // enable debugging output app := cli.NewApp() app.Usage = "Minio Client for object storage and filesystems" app.Version = getVersion() app.Commands = commands app.Compiled = getVersion() app.Flags = flags app.Author = "Minio.io" app.Before = func(ctx *cli.Context) error { if ctx.GlobalString("config") != "" { setMcConfigDir(ctx.GlobalString("config")) } globalQuietFlag = ctx.GlobalBool("quiet") globalForceFlag = ctx.GlobalBool("force") globalAliasFlag = ctx.GlobalBool("alias") globalDebugFlag = ctx.GlobalBool("debug") globalJSONFlag = ctx.GlobalBool("json") if globalDebugFlag { app.ExtraInfo = getSystemData() console.NoDebugPrint = false } themeName := ctx.GlobalString("theme") switch { case console.IsValidTheme(themeName) != true: console.Errorf("Invalid theme, please choose from the following list: %s.\n", console.GetThemeNames()) return errInvalidTheme{Theme: themeName} default: err := console.SetTheme(themeName) if err != nil { console.Errorf("Failed to set theme ‘%s’.", themeName) return err } } checkConfig() return nil } app.After = func(ctx *cli.Context) error { if !isMcConfigExists() { console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{}) } return nil } app.CustomAppHelpTemplate = `NAME: {{.Name}} - {{.Usage}} USAGE: {{.Name}} {{if .Flags}}[global flags] {{end}}command{{if .Flags}} [command flags]{{end}} [arguments...] COMMANDS: {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} {{end}}{{if .Flags}} GLOBAL FLAGS: {{range .Flags}}{{.}} {{end}}{{end}} VERSION: {{if .Compiled}} {{.Compiled}}{{end}} {{range $key, $value := .ExtraInfo}} {{$key}}: {{$value}} {{end}} ` app.RunAndExitOnError() }
forceFlag = cli.BoolFlag{ Name: "force", Usage: "Force copying when destination exists", } aliasFlag = cli.BoolFlag{ Name: "alias", Usage: "Mimic operating system toolchain behavior wherever it makes sense", } themeFlag = cli.StringFlag{ Name: "theme", Value: console.GetDefaultThemeName(), Usage: fmt.Sprintf("Choose a console theme from this list [%s]", func() string { keys := []string{} for _, themeName := range console.GetThemeNames() { if console.GetThemeName() == themeName { themeName = "*" + themeName + "*" } keys = append(keys, themeName) } return strings.Join(keys, ", ") }()), } jsonFlag = cli.BoolFlag{ Name: "json", Usage: "Enable json formatted output", } debugFlag = cli.BoolFlag{