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


Golang Context.Args方法代碼示例

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


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

示例1: TestApp_RunAsSubcommandParseFlags

func TestApp_RunAsSubcommandParseFlags(t *testing.T) {
	var context *cli.Context

	a := cli.NewApp()
	a.Commands = []cli.Command{
		{
			Name: "foo",
			Action: func(c *cli.Context) {
				context = c
			},
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:  "lang",
					Value: "english",
					Usage: "language for the greeting",
				},
			},
			Before: func(_ *cli.Context) error { return nil },
		},
	}
	a.Run([]string{"", "foo", "--lang", "spanish", "abcd"})

	expect(t, context.Args().Get(0), "abcd")
	expect(t, context.String("lang"), "spanish")
}
開發者ID:yubobo,項目名稱:minio,代碼行數:25,代碼來源:app_test.go

示例2: runMinioInstall

func runMinioInstall(ctx *cli.Context) {
	if ctx.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(ctx, "install", 1) // last argument is exit code
	}
	minioGenerate := command{exec.Command("godep", "go", "generate", "./..."), &bytes.Buffer{}, &bytes.Buffer{}}
	minioBuild := command{exec.Command("godep", "go", "build", "-a", "./..."), &bytes.Buffer{}, &bytes.Buffer{}}
	minioTest := command{exec.Command("godep", "go", "test", "-race", "./..."), &bytes.Buffer{}, &bytes.Buffer{}}
	minioInstall := command{exec.Command("godep", "go", "install", "-a", "github.com/minio/minio"), &bytes.Buffer{}, &bytes.Buffer{}}
	minioGenerateErr := minioGenerate.runCommand()
	if minioGenerateErr != nil {
		fmt.Print(minioGenerate)
		os.Exit(1)
	}
	fmt.Print(minioGenerate)
	minioBuildErr := minioBuild.runCommand()
	if minioBuildErr != nil {
		fmt.Print(minioBuild)
		os.Exit(1)
	}
	fmt.Print(minioBuild)
	minioTestErr := minioTest.runCommand()
	if minioTestErr != nil {
		fmt.Println(minioTest)
		os.Exit(1)
	}
	fmt.Print(minioTest)
	minioInstallErr := minioInstall.runCommand()
	if minioInstallErr != nil {
		fmt.Println(minioInstall)
		os.Exit(1)
	}
	fmt.Print(minioInstall)
}
開發者ID:flandr,項目名稱:minio,代碼行數:33,代碼來源:make.go

示例3: mainCopy

// mainCopy is bound to sub-command
func mainCopy(ctx *cli.Context) {
	checkCopySyntax(ctx)

	setCopyPalette(ctx.GlobalString("colors"))

	session := newSessionV2()

	var e error
	session.Header.CommandType = "cp"
	session.Header.RootPath, e = os.Getwd()
	if e != nil {
		session.Delete()
		fatalIf(probe.NewError(e), "Unable to get current working folder.")
	}

	// extract URLs.
	var err *probe.Error
	session.Header.CommandArgs, err = args2URLs(ctx.Args())
	if err != nil {
		session.Delete()
		fatalIf(err.Trace(), "One or more unknown URL types passed.")
	}

	doCopySession(session)
	session.Delete()
}
開發者ID:dudymas,項目名稱:mc,代碼行數:27,代碼來源:cp-main.go

示例4: mainDiff

// mainDiff main for 'diff'.
func mainDiff(ctx *cli.Context) {
	checkDiffSyntax(ctx)

	// Additional command speific theme customization.
	console.SetColor("DiffMessage", color.New(color.FgGreen, color.Bold))
	console.SetColor("DiffOnlyInFirst", color.New(color.FgRed, color.Bold))
	console.SetColor("DiffType", color.New(color.FgYellow, color.Bold))
	console.SetColor("DiffSize", color.New(color.FgMagenta, color.Bold))

	config := mustGetMcConfig()
	firstArg := ctx.Args().First()
	secondArg := ctx.Args().Last()

	firstURL := getAliasURL(firstArg, config.Aliases)
	secondURL := getAliasURL(secondArg, config.Aliases)

	newFirstURL := stripRecursiveURL(firstURL)
	for diff := range doDiffMain(newFirstURL, secondURL, isURLRecursive(firstURL)) {
		if diff.Error != nil {
			// Print in new line and adjust to top so that we don't print over the ongoing scan bar
			if !globalQuietFlag && !globalJSONFlag {
				console.Eraseline()
			}
		}
		fatalIf(diff.Error.Trace(newFirstURL, secondURL), "Failed to diff ‘"+firstURL+"’ and ‘"+secondURL+"’.")
		printMsg(diff)
	}
	// Print in new line and adjust to top so that we don't print over the ongoing scan bar
	if !globalQuietFlag && !globalJSONFlag {
		console.Eraseline()
	}
	console.Println(console.Colorize("DiffMessage", "Done."))
}
開發者ID:koolhead17,項目名稱:mc,代碼行數:34,代碼來源:diff-main.go

示例5: checkShareDownloadSyntax

// checkShareDownloadSyntax - validate command-line args.
func checkShareDownloadSyntax(ctx *cli.Context) {
	args := ctx.Args()
	if !args.Present() {
		cli.ShowCommandHelpAndExit(ctx, "download", 1) // last argument is exit code.
	}

	// Parse expiry.
	expiry := shareDefaultExpiry
	expireArg := ctx.String("expire")
	if expireArg != "" {
		var e error
		expiry, e = time.ParseDuration(expireArg)
		fatalIf(probe.NewError(e), "Unable to parse expire=‘"+expireArg+"’.")
	}

	// Validate expiry.
	if expiry.Seconds() < 1 {
		fatalIf(errDummy().Trace(expiry.String()), "Expiry cannot be lesser than 1 second.")
	}
	if expiry.Seconds() > 604800 {
		fatalIf(errDummy().Trace(expiry.String()), "Expiry cannot be larger than 7 days.")
	}

	for _, url := range ctx.Args() {
		_, _, err := url2Stat(url)
		fatalIf(err.Trace(url), "Unable to stat ‘"+url+"’.")
	}
}
開發者ID:balamurugana,項目名稱:mc,代碼行數:29,代碼來源:share-download-main.go

示例6: mainEventsRemove

func mainEventsRemove(ctx *cli.Context) error {
	console.SetColor("Events", color.New(color.FgGreen, color.Bold))

	setGlobalsFromContext(ctx)
	checkEventsRemoveSyntax(ctx)

	args := ctx.Args()
	path := args.Get(0)

	arn := ""
	if len(args) == 2 {
		arn = args.Get(1)
	}

	client, err := newClient(path)
	if err != nil {
		fatalIf(err.Trace(), "Cannot parse the provided url.")
	}

	s3Client, ok := client.(*s3Client)
	if !ok {
		fatalIf(errDummy().Trace(), "The provided url doesn't point to a S3 server.")
	}

	err = s3Client.RemoveNotificationConfig(arn)
	fatalIf(err, "Cannot enable notification on the specified bucket.")
	printMsg(eventsRemoveMessage{ARN: arn})

	return nil
}
開發者ID:balamurugana,項目名稱:mc,代碼行數:30,代碼來源:events-remove.go

示例7: mainMirror

func mainMirror(ctx *cli.Context) {
	checkMirrorSyntax(ctx)

	setMirrorPalette(ctx.GlobalString("colors"))

	var e error
	session := newSessionV2()
	session.Header.CommandType = "mirror"
	session.Header.RootPath, e = os.Getwd()
	if e != nil {
		session.Delete()
		fatalIf(probe.NewError(e), "Unable to get current working folder.")
	}

	// extract URLs.
	var err *probe.Error
	session.Header.CommandArgs, err = args2URLs(ctx.Args())
	if err != nil {
		session.Delete()
		fatalIf(err.Trace(ctx.Args()...), fmt.Sprintf("One or more unknown argument types found in ‘%s’.", ctx.Args()))
	}

	doMirrorSession(session)
	session.Delete()
}
開發者ID:henrylee2cn,項目名稱:mc,代碼行數:25,代碼來源:mirror-main.go

示例8: 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

示例9: mainCopy

// 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))

	session := newSessionV6()
	session.Header.CommandType = "cp"
	session.Header.CommandBoolFlags["recursive"] = ctx.Bool("recursive")

	var e error
	if session.Header.RootPath, e = os.Getwd(); e != nil {
		session.Delete()
		fatalIf(probe.NewError(e), "Unable to get current working folder.")
	}

	// extract URLs.
	session.Header.CommandArgs = ctx.Args()
	doCopySession(session)
	session.Delete()
}
開發者ID:fwessels,項目名稱:mc,代碼行數:26,代碼來源:cp-main.go

示例10: runCastCmd

func runCastCmd(ctx *cli.Context) {
	checkCastSyntax(ctx)

	session := newSessionV2()

	var err error
	session.Header.CommandType = "cast"
	session.Header.RootPath, err = os.Getwd()
	if err != nil {
		session.Close()
		session.Delete()
		console.Fatalf("Unable to get current working folder. %s\n", err)
	}

	// extract URLs.
	session.Header.CommandArgs, err = args2URLs(ctx.Args())
	if err != nil {
		session.Close()
		session.Delete()
		console.Fatalf("One or more unknown URL types found in %s. %s\n", ctx.Args(), err)
	}

	doCastCmdSession(session)
	session.Close()
	session.Delete()
}
開發者ID:Pragatheesh,項目名稱:mc,代碼行數:26,代碼來源:cast-main.go

示例11: mainConfig

// mainConfig is the handle for "mc config" sub-command. writes configuration data in json format to config file.
func mainConfig(ctx *cli.Context) {
	checkConfigSyntax(ctx)

	// set new custom coloring
	console.SetCustomTheme(map[string]*color.Color{
		"Alias":        color.New(color.FgCyan, color.Bold),
		"AliasMessage": color.New(color.FgGreen, color.Bold),
		"URL":          color.New(color.FgWhite),
	})

	arg := ctx.Args().First()
	tailArgs := ctx.Args().Tail()

	switch strings.TrimSpace(arg) {
	case "add":
		if strings.TrimSpace(tailArgs.First()) == "alias" {
			addAlias(tailArgs.Get(1), tailArgs.Get(2))
		}
	case "remove":
		if strings.TrimSpace(tailArgs.First()) == "alias" {
			removeAlias(tailArgs.Get(1))
		}
	case "list":
		if strings.TrimSpace(tailArgs.First()) == "alias" {
			listAliases()
		}
	}
}
開發者ID:axcoto-lab,項目名稱:mc,代碼行數:29,代碼來源:config-main.go

示例12: mainShare

// mainShare - main handler for mc share command
func mainShare(ctx *cli.Context) {
	if !ctx.Args().Present() || ctx.Args().First() == "help" {
		cli.ShowAppHelp(ctx)
	}

	// sub-commands like "upload" and "download" have their own main.
}
開發者ID:koolhead17,項目名稱:mc,代碼行數:8,代碼來源:share-main.go

示例13: 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

示例14: mainList

// mainList - is a handler for mc ls command
func mainList(ctx *cli.Context) {
	// Additional command speific theme customization.
	console.SetColor("File", color.New(color.FgWhite))
	console.SetColor("Dir", color.New(color.FgCyan, color.Bold))
	console.SetColor("Size", color.New(color.FgYellow))
	console.SetColor("Time", color.New(color.FgGreen))

	// check 'ls' cli arguments
	checkListSyntax(ctx)

	args := ctx.Args()
	isIncomplete := ctx.Bool("incomplete")

	// mimic operating system tool behavior
	if globalMimicFlag && !ctx.Args().Present() {
		args = []string{"."}
	}

	targetURLs, err := args2URLs(args.Head())
	fatalIf(err.Trace(args...), "One or more unknown URL types passed.")
	for _, targetURL := range targetURLs {
		// if recursive strip off the "..."
		var clnt client.Client
		clnt, err = url2Client(stripRecursiveURL(targetURL))
		fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.")

		err = doList(clnt, isURLRecursive(targetURL), isIncomplete)
		fatalIf(err.Trace(clnt.GetURL().String()), "Unable to list target ‘"+clnt.GetURL().String()+"’.")
	}
}
開發者ID:koolhead17,項目名稱:mc,代碼行數:31,代碼來源:ls-main.go

示例15: 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


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