Пример #1
0
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
}
Пример #2
0
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()
}