本文整理匯總了Golang中github.com/minio/cli.Context.GlobalString方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.GlobalString方法的具體用法?Golang Context.GlobalString怎麽用?Golang Context.GlobalString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/minio/cli.Context
的用法示例。
在下文中一共展示了Context.GlobalString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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)
}
示例3: 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()
}
示例4: registerBefore
func registerBefore(ctx *cli.Context) error {
setMcConfigDir(ctx.GlobalString("config-folder"))
globalQuietFlag = ctx.GlobalBool("quiet")
globalMimicFlag = ctx.GlobalBool("mimic")
globalDebugFlag = ctx.GlobalBool("debug")
globalJSONFlag = ctx.GlobalBool("json")
if globalDebugFlag {
console.NoDebugPrint = false
}
// Disable color themes.
if ctx.GlobalBool("no-color") == true {
console.SetColorOff()
}
// Verify golang runtime
verifyMCRuntime()
// Migrate any old version of config / state files to newer format.
migrate()
// Checkconfig if it can be read
checkConfig()
return nil
}
示例5: 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()
}
示例6: 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())
}
}
}
}
}
}
示例7: connectToMongo
func connectToMongo(c *cli.Context) *mgo.Session {
session, err := mgo.Dial(c.GlobalString("server"))
if err != nil {
panic(err)
}
// Optional. Switch the session to a monotonic behavior.
session.SetMode(mgo.Monotonic, true)
// make this configurable
db = session.DB("test").C("downloads")
return session
}
示例8: runFindCmd
func runFindCmd(c *cli.Context) {
if len(c.Args()) > 1 || c.Args().First() == "help" {
cli.ShowCommandHelpAndExit(c, "find", 1) // last argument is exit code
}
s := connectToMongo(c)
defer s.Close()
var result LogMessage
switch {
case strings.ToUpper(c.Args().First()) == "GET":
iter := db.Find(bson.M{"http.request.method": "GET"}).Iter()
for iter.Next(&result) {
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 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") {
fmt.Print(result.HTTP.Request.Method)
fmt.Print(" ")
fmt.Print(result.HTTP.Request.RemoteAddr)
fmt.Print(" ")
fmt.Print(result.HTTP.Request.RequestURI)
fmt.Println(" ")
}
}
case strings.ToUpper(c.Args().First()) == "HEAD":
iter := db.Find(bson.M{"http.request.method": "HEAD"}).Iter()
for iter.Next(&result) {
filters := strings.Split(c.GlobalString("filter"), ",")
for _, filter := range filters {
if strings.Contains(result.HTTP.Request.RemoteAddr, filter) {
continue
}
}
if !strings.HasPrefix(result.HTTP.Request.RequestURI, "/updates/2015") {
continue
}
fmt.Print(result.HTTP.Request.Method)
fmt.Print(" ")
fmt.Print(result.HTTP.Request.RemoteAddr)
fmt.Print(" ")
fmt.Print(result.HTTP.Request.RequestURI)
fmt.Println(" ")
}
}
}
示例9: mainUpdate
// mainUpdate -
func mainUpdate(ctx *cli.Context) {
checkUpdateSyntax(ctx)
setUpdatePalette(ctx.GlobalString("colors"))
arg := strings.TrimSpace(ctx.Args().First())
switch arg {
case "release":
getReleaseUpdate()
case "experimental":
getExperimentalUpdate()
}
}
示例10: mainSession
func mainSession(ctx *cli.Context) {
checkSessionSyntax(ctx)
setSessionPalette(ctx.GlobalString("colors"))
if !isSessionDirExists() {
fatalIf(createSessionDir().Trace(), "Unable to create session folder.")
}
switch strings.TrimSpace(ctx.Args().First()) {
// list resumable sessions
case "list":
fatalIf(listSessions().Trace(), "Unable to list sessions.")
case "resume":
sid := strings.TrimSpace(ctx.Args().Tail().First())
if !isSession(sid) {
fatalIf(errDummy().Trace(), "Session ‘"+sid+"’ not found.")
}
s, err := loadSessionV2(sid)
fatalIf(err.Trace(sid), "Unable to load session.")
// extra check for testing purposes
if s == nil {
return
}
savedCwd, e := os.Getwd()
fatalIf(probe.NewError(e), "Unable to verify your current working folder.")
if s.Header.RootPath != "" {
// chdir to RootPath
e = os.Chdir(s.Header.RootPath)
fatalIf(probe.NewError(e), "Unable to change our folder to root path while resuming session.")
}
sessionExecute(s)
err = s.Close()
fatalIf(err.Trace(), "Unable to close session file properly.")
err = s.Delete()
fatalIf(err.Trace(), "Unable to clear session files properly.")
// chdir back to saved path
e = os.Chdir(savedCwd)
fatalIf(probe.NewError(e), "Unable to change our folder to saved path ‘"+savedCwd+"’.")
// purge a requested pending session, if "all" purge everything
case "clear":
clearSession(strings.TrimSpace(ctx.Args().Tail().First()))
}
}
示例11: mainRm
func mainRm(ctx *cli.Context) {
checkRmSyntax(ctx)
var incomplete bool
var force bool
setRmPalette(ctx.GlobalString("colors"))
args := ctx.Args()
if len(args) != 1 {
if len(args) == 2 && args.Get(0) == "force" && args.Get(1) == "incomplete" ||
len(args) == 2 && args.Get(0) == "incomplete" && args.Get(1) == "force" {
args = args[:]
} else {
if args.Last() == "force" {
force = true
args = args[:len(args)-1]
}
if args.Last() == "incomplete" {
incomplete = true
args = args[:len(args)-1]
}
}
}
URLs, err := args2URLs(args)
fatalIf(err.Trace(ctx.Args()...), "Unable to parse arguments.")
rmPrint := rmPrinterFuncGenerate()
// execute for incomplete
if incomplete {
for _, url := range URLs {
if isURLRecursive(url) && force {
rmAllIncompleteUploads(stripRecursiveURL(url), rmPrint)
} else {
rmIncompleteUpload(url, rmPrint)
}
}
return
}
for _, url := range URLs {
if isURLRecursive(url) && force {
rmAll(stripRecursiveURL(url), rmPrint)
} else {
rmSingle(url, rmPrint)
}
}
if !globalJSONFlag && !globalQuietFlag {
console.Eraseline()
}
}
示例12: setGlobalsFromContext
// Parse command arguments and set global variables accordingly
func setGlobalsFromContext(c *cli.Context) {
// Set config dir
switch {
case c.IsSet("config-dir"):
globalConfigDir = c.String("config-dir")
case c.GlobalIsSet("config-dir"):
globalConfigDir = c.GlobalString("config-dir")
}
if globalConfigDir == "" {
console.Fatalf("Unable to get config file. Config directory is empty.")
}
// Set global quiet flag.
globalQuiet = c.Bool("quiet") || c.GlobalBool("quiet")
}
示例13: mainMakeBucket
// mainMakeBucket is the handler for mc mb command
func mainMakeBucket(ctx *cli.Context) {
checkMakeBucketSyntax(ctx)
setMakeBucketPalette(ctx.GlobalString("colors"))
config := mustGetMcConfig()
for _, arg := range ctx.Args() {
targetURL := getAliasURL(arg, config.Aliases)
fatalIf(doMakeBucket(targetURL).Trace(targetURL), "Unable to make bucket ‘"+targetURL+"’.")
Prints("%s\n", MakeBucketMessage{
Status: "success",
Bucket: targetURL,
})
}
}
示例14: mainConfigAlias
func mainConfigAlias(ctx *cli.Context) {
checkConfigAliasSyntax(ctx)
setConfigAliasPalette(ctx.GlobalString("colors"))
arg := ctx.Args().First()
tailArgs := ctx.Args().Tail()
switch strings.TrimSpace(arg) {
case "add":
addAlias(tailArgs.Get(0), tailArgs.Get(1))
case "remove":
removeAlias(tailArgs.Get(0))
case "list":
listAliases()
}
}
示例15: registerBefore
func registerBefore(ctx *cli.Context) error {
setMcConfigDir(ctx.GlobalString("config-folder"))
// Verify golang runtime.
verifyMCRuntime()
// Migrate any old version of config / state files to newer format.
migrate()
// Set global flags.
setGlobalsFromContext(ctx)
// Checkconfig if it can be read.
checkConfig()
return nil
}