本文整理匯總了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
}
}
}
示例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].")
}
}
}
示例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
}
}
示例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
}
}
示例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)
}
}
示例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)
}
示例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))
}
}
示例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)
}
示例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)
}
示例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))
}
示例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)
}
}
示例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)
}
示例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)
}
示例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)
}
}
}
示例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))
}