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


Golang cli.Context類代碼示例

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


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

示例1: mainList

// mainList - is a handler for mc ls command
func mainList(ctx *cli.Context) {
	checkListSyntax(ctx)

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

	console.SetCustomTheme(map[string]*color.Color{
		"File": color.New(color.FgWhite),
		"Dir":  color.New(color.FgCyan, color.Bold),
		"Size": color.New(color.FgYellow),
		"Time": color.New(color.FgGreen),
	})

	config := mustGetMcConfig()
	for _, arg := range args {
		targetURL, err := getCanonicalizedURL(arg, config.Aliases)
		fatalIf(err.Trace(arg), "Unable to parse argument ‘"+arg+"’.")

		// if recursive strip off the "..."
		err = doListCmd(stripRecursiveURL(targetURL), isURLRecursive(targetURL))
		fatalIf(err.Trace(targetURL), "Unable to list target ‘"+targetURL+"’.")
	}
}
開發者ID:axcoto-lab,項目名稱:mc,代碼行數:27,代碼來源:ls-main.go

示例2: registerBefore

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
}
開發者ID:Pragatheesh,項目名稱:mc,代碼行數:29,代碼來源:main.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: mainShareDownload

// main for share download.
func mainShareDownload(ctx *cli.Context) {
	// setup share data folder and file.
	shareDataSetup()

	// Additional command speific theme customization.
	shareSetColor()

	// check input arguments.
	checkShareDownloadSyntax(ctx)

	args := ctx.Args()
	config := mustGetMcConfig()
	url := args.Get(0)
	// default expiration is 7days
	expires := time.Duration(604800) * time.Second
	if len(args) == 2 {
		var err error
		expires, err = time.ParseDuration(args.Get(1))
		fatalIf(probe.NewError(err), "Unable to parse time argument.")
	}

	targetURL := getAliasURL(url, config.Aliases)
	// if recursive strip off the "..."
	err := doShareDownloadURL(stripRecursiveURL(targetURL), isURLRecursive(targetURL), expires)
	fatalIf(err.Trace(targetURL), "Unable to generate URL for download.")
	return
}
開發者ID:koolhead17,項目名稱:mc,代碼行數:28,代碼來源:share-download-main.go

示例5: mainShareDownload

// main for share download.
func mainShareDownload(ctx *cli.Context) error {
	// Set global flags from context.
	setGlobalsFromContext(ctx)

	// check input arguments.
	checkShareDownloadSyntax(ctx)

	// Initialize share config folder.
	initShareConfig()

	// Additional command speific theme customization.
	shareSetColor()

	// Set command flags from context.
	isRecursive := ctx.Bool("recursive")
	expiry := shareDefaultExpiry
	if ctx.String("expire") != "" {
		var e error
		expiry, e = time.ParseDuration(ctx.String("expire"))
		fatalIf(probe.NewError(e), "Unable to parse expire=‘"+ctx.String("expire")+"’.")
	}

	for _, targetURL := range ctx.Args() {
		err := doShareDownloadURL(targetURL, isRecursive, expiry)
		if err != nil {
			switch err.ToGoError().(type) {
			case APINotImplemented:
				fatalIf(err.Trace(), "Unable to share a non S3 url ‘"+targetURL+"’.")
			default:
				fatalIf(err.Trace(targetURL), "Unable to share target ‘"+targetURL+"’.")
			}
		}
	}
	return nil
}
開發者ID:balamurugana,項目名稱:mc,代碼行數:36,代碼來源:share-download-main.go

示例6: mainShareUpload

// main for share upload command.
func mainShareUpload(ctx *cli.Context) {
	// setup share data folder and file.
	shareDataSetup()

	// Additional command speific theme customization.
	shareSetColor()

	// check input arguments.
	checkShareUploadSyntax(ctx)

	var expires time.Duration
	var err error
	args := ctx.Args()
	config := mustGetMcConfig()
	if strings.TrimSpace(args.Get(1)) == "" {
		expires = time.Duration(604800) * time.Second
	} else {
		expires, err = time.ParseDuration(strings.TrimSpace(args.Get(1)))
		if err != nil {
			fatalIf(probe.NewError(err), "Unable to parse time argument.")
		}
	}
	contentType := strings.TrimSpace(args.Get(2))
	targetURL := getAliasURL(strings.TrimSpace(args.Get(0)), config.Aliases)

	e := doShareUploadURL(stripRecursiveURL(targetURL), isURLRecursive(targetURL), expires, contentType)
	fatalIf(e.Trace(targetURL), "Unable to generate URL for upload.")
}
開發者ID:koolhead17,項目名稱:mc,代碼行數:29,代碼來源:share-upload-main.go

示例7: mainCopy

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

	console.SetCustomTheme(map[string]*color.Color{
		"Copy": color.New(color.FgGreen, color.Bold),
	})

	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.")
	}

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

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

示例9: mainCopy

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

	// Additional command speific theme customization.
	console.SetColor("Copy", color.New(color.FgGreen, color.Bold))

	var e error
	session := newSessionV3()
	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.")
	}

	// If force flag is set save it with in session
	session.Header.CommandBoolFlag.Key = "force"
	session.Header.CommandBoolFlag.Value = ctx.Bool("force")

	// 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:koolhead17,項目名稱:mc,代碼行數:31,代碼來源:cp-main.go

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

示例11: runAnalyticsCmd

func runAnalyticsCmd(c *cli.Context) {
	conf, err := loadConfigV1()
	if err != nil {
		log.Fatal(err.Trace())
	}
	s := connectToMongo(c)
	defer s.Close()

	var result LogMessage
	iter := db.Find(bson.M{"http.request.method": "GET"}).Iter()
	for iter.Next(&result) {
		if time.Since(result.StartTime) < time.Duration(24*time.Hour) {
			filters := strings.Split(c.GlobalString("filter"), ",")
			var skip bool
			for _, filter := range filters {
				if strings.Contains(result.HTTP.Request.RemoteAddr, filter) {
					skip = true
					break
				}
			}
			if skip {
				continue
			}
			if result.StatusMessage == "" || result.StatusMessage == "OK" {
				if strings.HasSuffix(result.HTTP.Request.RequestURI, "minio") || strings.HasSuffix(result.HTTP.Request.RequestURI, "minio.exe") || strings.HasSuffix(result.HTTP.Request.RequestURI, "mc") || strings.HasSuffix(result.HTTP.Request.RequestURI, "mc.exe") {

					if err := updateGoogleAnalytics(conf, result); err != nil {
						log.Fatal(err.Trace())
					}
				}
			}
		}
	}
}
開發者ID:balamurugana,項目名稱:aminer,代碼行數:34,代碼來源:analytics.go

示例12: mainMirror

// Main entry point for mirror command.
func mainMirror(ctx *cli.Context) {
	// Set global flags from context.
	setGlobalsFromContext(ctx)

	// check 'mirror' cli arguments.
	checkMirrorSyntax(ctx)

	// Additional command speific theme customization.
	console.SetColor("Mirror", color.New(color.FgGreen, color.Bold))

	var e error
	session := newSessionV6()
	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.")
	}

	// Set command flags from context.
	isForce := ctx.Bool("force")
	session.Header.CommandBoolFlags["force"] = isForce

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

示例13: mainList

// mainList - is a handler for mc ls command
func mainList(ctx *cli.Context) {
	checkListSyntax(ctx)

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

	console.SetCustomTheme(map[string]*color.Color{
		"File": color.New(color.FgWhite),
		"Dir":  color.New(color.FgCyan, color.Bold),
		"Size": color.New(color.FgYellow),
		"Time": color.New(color.FgGreen),
	})

	targetURLs, err := args2URLs(args)
	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 = target2Client(stripRecursiveURL(targetURL))
		fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.")

		err = doList(clnt, isURLRecursive(targetURL), len(targetURLs) > 1)
		fatalIf(err.Trace(clnt.URL().String()), "Unable to list target ‘"+clnt.URL().String()+"’.")
	}
}
開發者ID:akiradeveloper,項目名稱:mc,代碼行數:30,代碼來源:ls-main.go

示例14: mainRm

// main for rm command.
func mainRm(ctx *cli.Context) {
	// Set global flags from context.
	setGlobalsFromContext(ctx)

	// check 'rm' cli arguments.
	checkRmSyntax(ctx)

	// rm specific flags.
	isForce := ctx.Bool("force")
	isIncomplete := ctx.Bool("incomplete")
	isRecursive := ctx.Bool("recursive")
	isFake := ctx.Bool("fake")

	// Set color.
	console.SetColor("Remove", color.New(color.FgGreen, color.Bold))

	// Support multiple targets.
	for _, url := range ctx.Args() {
		targetAlias, targetURL, _ := mustExpandAlias(url)
		if isRecursive && isForce {
			rmAll(targetAlias, targetURL, isRecursive, isIncomplete, isFake)
		} else {
			if err := rm(targetAlias, targetURL, isIncomplete, isFake); err != nil {
				errorIf(err.Trace(url), "Unable to remove ‘"+url+"’.")
				continue
			}
			printMsg(rmMessage{Status: "success", URL: url})
		}
	}
}
開發者ID:fwessels,項目名稱:mc,代碼行數:31,代碼來源:rm-main.go

示例15: mainMakeBucket

// mainMakeBucket is entry point for mb command.
func mainMakeBucket(ctx *cli.Context) {
	// Set global flags from context.
	setGlobalsFromContext(ctx)

	// check 'mb' cli arguments.
	checkMakeBucketSyntax(ctx)

	// Additional command speific theme customization.
	console.SetColor("MakeBucket", color.New(color.FgGreen, color.Bold))

	for _, targetURL := range ctx.Args() {
		// Instantiate client for URL.
		clnt, err := newClient(targetURL)
		fatalIf(err.Trace(targetURL), "Invalid target ‘"+targetURL+"’.")

		// Make bucket.
		err = clnt.MakeBucket()
		// Upon error print error and continue.
		if err != nil {
			errorIf(err.Trace(targetURL), "Unable to make bucket ‘"+targetURL+"’.")
			continue
		}

		// Successfully created a bucket.
		printMsg(makeBucketMessage{Status: "success", Bucket: targetURL})
	}
}
開發者ID:fwessels,項目名稱:mc,代碼行數:28,代碼來源:mb-main.go


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