當前位置: 首頁>>代碼示例>>Golang>>正文


Golang cli.ShowCommandHelpAndExit函數代碼示例

本文整理匯總了Golang中github.com/minio/cli.ShowCommandHelpAndExit函數的典型用法代碼示例。如果您正苦於以下問題:Golang ShowCommandHelpAndExit函數的具體用法?Golang ShowCommandHelpAndExit怎麽用?Golang ShowCommandHelpAndExit使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ShowCommandHelpAndExit函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: checkAccessSyntax

func checkAccessSyntax(ctx *cli.Context) {
	if !ctx.Args().Present() || ctx.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code
	}
	if len(ctx.Args()) < 2 {
		cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code
	}
	switch ctx.Args().Get(0) {
	case "set":
		if len(ctx.Args().Tail()) < 2 {
			cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code
		}
		perms := accessPerms(ctx.Args().Tail().Get(0))
		if !perms.isValidAccessPERM() {
			fatalIf(errDummy().Trace(),
				"Unrecognized permission ‘"+perms.String()+"’. Allowed values are [private, public, readonly].")
		}
		for _, arg := range ctx.Args().Tail().Tail() {
			if strings.TrimSpace(arg) == "" {
				fatalIf(errInvalidArgument().Trace(), "Unable to validate empty argument.")
			}
		}
	case "get":
		if len(ctx.Args().Tail()) < 1 {
			cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code
		}
	}
}
開發者ID:henrylee2cn,項目名稱:mc,代碼行數:28,代碼來源:access-main.go

示例2: checkPolicySyntax

// checkPolicySyntax check for incoming syntax.
func checkPolicySyntax(ctx *cli.Context) {
	argsLength := len(ctx.Args())
	// Always print a help message when we have extra arguments
	if argsLength > 2 {
		cli.ShowCommandHelpAndExit(ctx, "policy", 1) // last argument is exit code.
	}
	// Always print a help message when no arguments specified
	if argsLength < 1 {
		cli.ShowCommandHelpAndExit(ctx, "policy", 1)
	}

	firstArg := ctx.Args().Get(0)

	// More syntax checking
	switch accessPerms(firstArg) {
	case accessNone, accessDownload, accessUpload, accessPublic:
		// Always expect two arguments when a policy permission is provided
		if argsLength != 2 {
			cli.ShowCommandHelpAndExit(ctx, "policy", 1)
		}
	case "list":
		// Always expect an argument after list cmd
		if argsLength != 2 {
			cli.ShowCommandHelpAndExit(ctx, "policy", 1)
		}
	default:
		if argsLength == 2 {
			fatalIf(errDummy().Trace(),
				"Unrecognized permission ‘"+string(firstArg)+"’. Allowed values are [none, download, upload, public].")
		}
	}
}
開發者ID:balamurugana,項目名稱:mc,代碼行數:33,代碼來源:policy-main.go

示例3: checkConfigAliasSyntax

func checkConfigAliasSyntax(ctx *cli.Context) {
	// show help if nothing is set
	if !ctx.Args().Present() || ctx.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(ctx, "alias", 1) // last argument is exit code
	}
	if strings.TrimSpace(ctx.Args().First()) == "" {
		cli.ShowCommandHelpAndExit(ctx, "alias", 1) // last argument is exit code
	}
	if len(ctx.Args().Tail()) > 2 {
		fatalIf(errDummy().Trace(), "Incorrect number of arguments to alias command")
	}
	switch strings.TrimSpace(ctx.Args().Get(0)) {
	case "add":
		if len(ctx.Args().Tail()) != 2 {
			fatalIf(errInvalidArgument().Trace(), "Incorrect number of arguments for add alias command.")
		}
	case "remove":
		if len(ctx.Args().Tail()) != 1 {
			fatalIf(errInvalidArgument().Trace(), "Incorrect number of arguments for remove alias command.")
		}
	case "list":
	default:
		cli.ShowCommandHelpAndExit(ctx, "alias", 1) // last argument is exit code
	}
}
開發者ID:henrylee2cn,項目名稱:mc,代碼行數:25,代碼來源:config-alias-main.go

示例4: checkShareDownloadSyntax

func checkShareDownloadSyntax(ctx *cli.Context) {
	args := ctx.Args()
	if !args.Present() || args.First() == "help" {
		cli.ShowCommandHelpAndExit(ctx, "download", 1) // last argument is exit code
	}
	if len(args) > 2 {
		cli.ShowCommandHelpAndExit(ctx, "download", 1) // last argument is exit code
	}
}
開發者ID:koolhead17,項目名稱:mc,代碼行數:9,代碼來源:share-download-main.go

示例5: runAccessCmd

func runAccessCmd(ctx *cli.Context) {
	if !ctx.Args().Present() || ctx.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code
	}
	config := mustGetMcConfig()
	acl := bucketACL(ctx.Args().First())
	if !acl.isValidBucketACL() {
		console.Fatalf("Valid types are [private, public, readonly]. %s\n", errInvalidACL{acl: acl.String()})
	}
	for _, arg := range ctx.Args().Tail() {
		targetURL, err := getExpandedURL(arg, config.Aliases)
		if err != nil {
			switch e := iodine.ToError(err).(type) {
			case errUnsupportedScheme:
				console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
			default:
				console.Fatalf("Unable to parse argument %s. %s\n", arg, err)
			}
		}
		msg, err := doUpdateAccessCmd(targetURL, acl)
		if err != nil {
			console.Fatalln(msg)
		}
		console.Infoln(msg)
	}
}
開發者ID:Pragatheesh,項目名稱:mc,代碼行數:26,代碼來源:access-main.go

示例6: controllerMain

func controllerMain(c *cli.Context) {
	if c.Args().Present() && c.Args().First() != "keys" {
		cli.ShowCommandHelpAndExit(c, "controller", 1)
	}

	if c.Args().First() == "keys" {
		conf, err := getAuth()
		fatalIf(err.Trace(), "Failed to fetch keys for minio controller.", nil)
		if conf != nil {
			for _, user := range conf.Users {
				if globalJSONFlag {
					Println(accessKeys{user}.JSON())
				} else {
					Println(accessKeys{user})
				}
			}
		}
		return
	}

	err := firstTimeAuth()
	fatalIf(err.Trace(), "Failed to generate keys for minio.", nil)

	err = startController(getControllerConfig(c))
	fatalIf(err.Trace(), "Failed to start minio controller.", nil)
}
開發者ID:yujiyokoo,項目名稱:minio,代碼行數:26,代碼來源:controller-main.go

示例7: runController

func runController(c *cli.Context) {
	if len(c.Args()) < 2 || c.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(c, "controller", 1) // last argument is exit code
	}
	switch c.Args().First() {
	case "mem":
		memstats, err := controller.GetMemStats(c.Args().Tail().First())
		if err != nil {
			Fatalln(err)
		}
		Println(string(memstats))
	case "sysinfo":
		sysinfo, err := controller.GetSysInfo(c.Args().Tail().First())
		if err != nil {
			Fatalln(err)
		}
		Println(string(sysinfo))
	case "auth":
		keys, err := controller.GetAuthKeys(c.Args().Tail().First())
		if err != nil {
			Fatalln(err)
		}
		Println(string(keys))
	}
}
開發者ID:theanalyst,項目名稱:minio,代碼行數:25,代碼來源:commands.go

示例8: runDonut

func runDonut(c *cli.Context) {
	u, err := user.Current()
	if err != nil {
		Fatalf("Unable to determine current user. Reason: %s\n", err)
	}
	if len(c.Args()) < 1 {
		cli.ShowCommandHelpAndExit(c, "donut", 1) // last argument is exit code
	}
	// supporting multiple paths
	var paths []string
	if strings.TrimSpace(c.Args().First()) == "" {
		p := filepath.Join(u.HomeDir, "minio-storage", "donut")
		paths = append(paths, p)
	} else {
		for _, arg := range c.Args() {
			paths = append(paths, strings.TrimSpace(arg))
		}
	}
	apiServerConfig := getAPIServerConfig(c)
	donutDriver := server.DonutFactory{
		Config: apiServerConfig,
		Paths:  paths,
	}
	apiServer := donutDriver.GetStartServerFunc()
	//	webServer := getWebServerConfigFunc(c)
	servers := []server.StartServerFunc{apiServer} //, webServer}
	server.StartMinio(servers)
}
開發者ID:yubobo,項目名稱:minio,代碼行數:28,代碼來源:commands.go

示例9: mainConfigVersion

func mainConfigVersion(ctx *cli.Context) {
	if ctx.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(ctx, "version", 1) // last argument is exit code
	}

	config, err := newConfig()
	fatalIf(err.Trace(), "Failed to initialize ‘quick’ configuration data structure.")

	configPath := mustGetMcConfigPath()
	err = config.Load(configPath)
	fatalIf(err.Trace(configPath), "Unable to load config path")

	// convert interface{} back to its original struct
	newConf := config.Data().(*configV5)
	type Version struct {
		Value string `json:"value"`
	}
	if globalJSONFlag {
		tB, e := json.Marshal(
			struct {
				Version Version `json:"version"`
			}{Version: Version{newConf.Version}},
		)
		fatalIf(probe.NewError(e), "Unable to construct version string.")
		console.Println(string(tB))
		return
	}
	console.Println(newConf.Version)
}
開發者ID:akiradeveloper,項目名稱:mc,代碼行數:29,代碼來源:config-version-main.go

示例10: mainVersion

func mainVersion(ctx *cli.Context) {
	if ctx.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(ctx, "version", 1) // last argument is exit code
	}
	t, _ := time.Parse(time.RFC3339Nano, Version)
	if t.IsZero() {
		console.Println("")
		return
	}
	type Version struct {
		Value  time.Time `json:"value"`
		Format string    `json:"format"`
	}
	if globalJSONFlag {
		tB, e := json.Marshal(
			struct {
				Version Version `json:"version"`
			}{Version: Version{t, "RFC3339Nano"}},
		)
		fatalIf(probe.NewError(e), "Unable to construct version string.")
		console.Println(string(tB))
		return
	}
	console.Println(t.Format(http.TimeFormat))
}
開發者ID:axcoto-lab,項目名稱:mc,代碼行數:25,代碼來源:version-main.go

示例11: runMakeBucketCmd

// runMakeBucketCmd is the handler for mc mb command
func runMakeBucketCmd(ctx *cli.Context) {
	if !ctx.Args().Present() || ctx.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(ctx, "mb", 1) // last argument is exit code
	}
	if !isMcConfigExists() {
		console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
	}
	config := mustGetMcConfig()
	for _, arg := range ctx.Args() {
		targetURL, err := getExpandedURL(arg, config.Aliases)
		if err != nil {
			switch e := iodine.ToError(err).(type) {
			case errUnsupportedScheme:
				console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
			default:
				console.Fatalf("Unable to parse argument %s. %s\n", arg, err)
			}
		}
		msg, err := doMakeBucketCmd(targetURL)
		if err != nil {
			console.Fatalln(msg)
		}
		console.Infoln(msg)
	}
}
開發者ID:krishnasrinivas,項目名稱:mc,代碼行數:26,代碼來源:mb-main.go

示例12: mainConfigVersion

func mainConfigVersion(ctx *cli.Context) {
	if ctx.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(ctx, "version", 1) // last argument is exit code
	}

	config, err := loadConfigV2()
	fatalIf(err.Trace(), "Unable to load config", nil)

	// convert interface{} back to its original struct
	newConf := config
	type Version struct {
		Value string `json:"value"`
	}
	if globalJSONFlag {
		tB, e := json.Marshal(
			struct {
				Version Version `json:"version"`
			}{Version: Version{newConf.Version}},
		)
		fatalIf(probe.NewError(e), "Unable to construct version string.", nil)
		Println(string(tB))
		return
	}
	Println(newConf.Version)
}
開發者ID:seiflotfy,項目名稱:minio,代碼行數:25,代碼來源:config-version-main.go

示例13: mainVersion

func mainVersion(ctx *cli.Context) {
	if ctx.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(ctx, "version", 1) // last argument is exit code
	}

	setVersionPalette(ctx.GlobalString("colors"))

	if globalJSONFlag {
		tB, e := json.Marshal(
			struct {
				Version struct {
					Value  string `json:"value"`
					Format string `json:"format"`
				} `json:"version"`
			}{
				Version: struct {
					Value  string `json:"value"`
					Format string `json:"format"`
				}{
					Value:  mcVersion,
					Format: "RFC2616",
				},
			},
		)
		fatalIf(probe.NewError(e), "Unable to construct version string.")
		console.Println(string(tB))
		return
	}
	msg := console.Colorize("Version", fmt.Sprintf("Version: %s\n", mcVersion))
	msg += console.Colorize("Version", fmt.Sprintf("Release-Tag: %s", mcReleaseTag))
	console.Println(msg)
}
開發者ID:zhujo01,項目名稱:mc,代碼行數:32,代碼來源:version-main.go

示例14: runCatCmd

func runCatCmd(ctx *cli.Context) {
	if !ctx.Args().Present() || ctx.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(ctx, "cat", 1) // last argument is exit code
	}
	if !isMcConfigExists() {
		console.Fatalf("Please run \"mc config generate\". %s\n", errNotConfigured{})
	}
	config := mustGetMcConfig()
	// Convert arguments to URLs: expand alias, fix format...
	for _, arg := range ctx.Args() {
		sourceURL, err := getExpandedURL(arg, config.Aliases)
		if err != nil {
			switch e := iodine.ToError(err).(type) {
			case errUnsupportedScheme:
				console.Fatalf("Unknown type of URL %s. %s\n", e.url, err)
			default:
				console.Fatalf("Unable to parse argument %s. %s\n", arg, err)
			}
		}
		errorMsg, err := doCatCmd(sourceURL)
		if err != nil {
			console.Fatalln(errorMsg)
		}
	}
}
開發者ID:krishnasrinivas,項目名稱:mc,代碼行數:25,代碼來源:cat-main.go

示例15: lockControl

// "minio control lock" entry point.
func lockControl(c *cli.Context) {
	if len(c.Args()) != 1 {
		cli.ShowCommandHelpAndExit(c, "lock", 1)
	}

	parsedURL, err := url.Parse(c.Args()[0])
	fatalIf(err, "Unable to parse URL.")

	authCfg := &authConfig{
		accessKey:   serverConfig.GetCredential().AccessKeyID,
		secretKey:   serverConfig.GetCredential().SecretAccessKey,
		address:     parsedURL.Host,
		path:        path.Join(reservedBucket, controlPath),
		loginMethod: "Controller.LoginHandler",
	}
	client := newAuthClient(authCfg)

	args := &GenericArgs{}
	reply := &SystemLockState{}
	err = client.Call("Controller.LockInfo", args, reply)
	// logs the error and returns if err != nil.
	fatalIf(err, "RPC Controller.LockInfo call failed")
	// print the lock info on the console.
	b, err := json.MarshalIndent(*reply, "", "  ")
	fatalIf(err, "Failed to parse the RPC lock info response")
	fmt.Print(string(b))
}
開發者ID:hackintoshrao,項目名稱:minio,代碼行數:28,代碼來源:control-lock-main.go


注:本文中的github.com/minio/cli.ShowCommandHelpAndExit函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。