本文整理匯總了Golang中github.com/minio/cli.Context.Bool方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Bool方法的具體用法?Golang Context.Bool怎麽用?Golang Context.Bool使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/minio/cli.Context
的用法示例。
在下文中一共展示了Context.Bool方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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))
// Set global flags from context.
setGlobalsFromContext(ctx)
// check 'ls' cli arguments.
checkListSyntax(ctx)
// Set command flags from context.
isRecursive := ctx.Bool("recursive")
isIncomplete := ctx.Bool("incomplete")
args := ctx.Args()
// mimic operating system tool behavior.
if !ctx.Args().Present() {
args = []string{"."}
}
for _, targetURL := range args {
var clnt client.Client
clnt, err := newClient(targetURL)
fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.")
err = doList(clnt, isRecursive, isIncomplete)
if err != nil {
errorIf(err.Trace(clnt.GetURL().String()), "Unable to list target ‘"+clnt.GetURL().String()+"’.")
continue
}
}
}
示例2: checkRmSyntax
// Validate command line arguments.
func checkRmSyntax(ctx *cli.Context) {
args := ctx.Args()
ishelp := ctx.GlobalBool("help")
isForce := ctx.Bool("force")
if !args.Present() || ishelp {
exitCode := 1
cli.ShowCommandHelpAndExit(ctx, "rm", exitCode)
}
URLs, err := args2URLs(args)
fatalIf(err.Trace(ctx.Args()...), "Unable to parse arguments.")
// If input validation fails then provide context sensitive help without displaying generic help message.
// The context sensitive help is shown per argument instead of all arguments to keep the help display
// as well as the code simple. Also most of the times there will be just one arg
for _, url := range URLs {
u := client.NewURL(url)
if strings.HasSuffix(url, string(u.Separator)) {
fatalIf(errDummy().Trace(),
"‘"+url+"’ is a folder. To remove this folder recursively, please try ‘"+url+"...’ as argument.")
}
if isURLRecursive(url) && !isForce {
fatalIf(errDummy().Trace(),
"Recursive removal requires --force option. Please review carefully before performing this operation.")
}
}
}
示例3: 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()+"’.")
}
}
示例4: 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()
}
示例5: checkListSyntax
// checkListSyntax - validate all the passed arguments
func checkListSyntax(ctx *cli.Context) {
args := ctx.Args()
if !ctx.Args().Present() {
args = []string{"."}
}
for _, arg := range args {
if strings.TrimSpace(arg) == "" {
fatalIf(errInvalidArgument().Trace(args...), "Unable to validate empty argument.")
}
}
// extract URLs.
URLs := ctx.Args()
isIncomplete := ctx.Bool("incomplete")
for _, url := range URLs {
_, _, err := url2Stat(url)
if err != nil && !isURLPrefixExists(url, isIncomplete) {
// Bucket name empty is a valid error for 'ls myminio',
// treat it as such.
if _, ok := err.ToGoError().(BucketNameEmpty); ok {
continue
}
fatalIf(err.Trace(url), "Unable to stat ‘"+url+"’.")
}
}
}
示例6: 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
}
示例7: mainShareUpload
// main for share upload command.
func mainShareUpload(ctx *cli.Context) {
// Set global flags from context.
setGlobalsFromContext(ctx)
// check input arguments.
checkShareUploadSyntax(ctx)
// Initialize share config folder.
initShareConfig()
// Additional command speific theme customization.
shareSetColor()
// Set command flags from context.
isRecursive := ctx.Bool("recursive")
expireArg := ctx.String("expire")
expiry := shareDefaultExpiry
contentType := ctx.String("content-type")
if expireArg != "" {
var e error
expiry, e = time.ParseDuration(expireArg)
fatalIf(probe.NewError(e), "Unable to parse expire=‘"+expireArg+"’.")
}
for _, targetURL := range ctx.Args() {
err := doShareUploadURL(targetURL, isRecursive, expiry, contentType)
fatalIf(err.Trace(targetURL), "Unable to generate curl command for upload ‘"+targetURL+"’.")
}
}
示例8: mainMirror
func mainMirror(ctx *cli.Context) {
checkMirrorSyntax(ctx)
// Additional command speific theme customization.
console.SetColor("Mirror", color.New(color.FgGreen, color.Bold))
var e error
session := newSessionV3()
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.")
}
// 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(ctx.Args()...), fmt.Sprintf("One or more unknown argument types found in ‘%s’.", ctx.Args()))
}
doMirrorSession(session)
session.Delete()
}
示例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()
}
示例10: mainUpdate
// main entry point for update command.
func mainUpdate(ctx *cli.Context) {
// Check for update.
if ctx.Bool("experimental") {
getReleaseUpdate(minioUpdateExperimentalURL)
} else {
getReleaseUpdate(minioUpdateStableURL)
}
}
示例11: checkEventsRemoveSyntax
// checkEventsRemoveSyntax - validate all the passed arguments
func checkEventsRemoveSyntax(ctx *cli.Context) {
if len(ctx.Args()) == 0 || len(ctx.Args()) > 2 {
cli.ShowCommandHelpAndExit(ctx, "remove", 1) // last argument is exit code
}
if len(ctx.Args()) == 1 && !ctx.Bool("force") {
fatalIf(probe.NewError(errors.New("")), "--force flag needs to be passed to remove all bucket notifications")
}
}
示例12: checkCopySyntax
func checkCopySyntax(ctx *cli.Context) {
if len(ctx.Args()) < 2 {
cli.ShowCommandHelpAndExit(ctx, "cp", 1) // last argument is exit code.
}
// extract URLs.
URLs := ctx.Args()
if len(URLs) < 2 {
fatalIf(errDummy().Trace(ctx.Args()...), fmt.Sprintf("Unable to parse source and target arguments."))
}
srcURLs := URLs[:len(URLs)-1]
tgtURL := URLs[len(URLs)-1]
isRecursive := ctx.Bool("recursive")
/****** Generic Invalid Rules *******/
// Verify if source(s) exists.
for _, srcURL := range srcURLs {
_, _, err := url2Stat(srcURL)
if err != nil {
fatalIf(err.Trace(srcURL), fmt.Sprintf("Unable to stat '%s'.", srcURL))
}
}
// Check if bucket name is passed for URL type arguments.
url := newClientURL(tgtURL)
if url.Host != "" {
// This check is for type URL.
if !isURLVirtualHostStyle(url.Host) {
if url.Path == string(url.Separator) {
fatalIf(errInvalidArgument().Trace(), fmt.Sprintf("Target ‘%s’ does not contain bucket name.", tgtURL))
}
}
}
// Guess CopyURLsType based on source and target URLs.
copyURLsType, err := guessCopyURLType(srcURLs, tgtURL, isRecursive)
if err != nil {
fatalIf(errInvalidArgument().Trace(), "Unable to guess the type of copy operation.")
}
switch copyURLsType {
case copyURLsTypeA: // File -> File.
checkCopySyntaxTypeA(srcURLs, tgtURL)
case copyURLsTypeB: // File -> Folder.
checkCopySyntaxTypeB(srcURLs, tgtURL)
case copyURLsTypeC: // Folder... -> Folder.
checkCopySyntaxTypeC(srcURLs, tgtURL, isRecursive)
case copyURLsTypeD: // File1...FileN -> Folder.
checkCopySyntaxTypeD(srcURLs, tgtURL)
default:
fatalIf(errInvalidArgument().Trace(), "Unable to guess the type of copy operation.")
}
}
示例13: mainList
// mainList - is a handler for mc ls command
func mainList(ctx *cli.Context) error {
// Additional command specific theme customization.
console.SetColor("File", color.New(color.Bold))
console.SetColor("Dir", color.New(color.FgCyan, color.Bold))
console.SetColor("Size", color.New(color.FgYellow))
console.SetColor("Time", color.New(color.FgGreen))
// Set global flags from context.
setGlobalsFromContext(ctx)
// check 'ls' cli arguments.
checkListSyntax(ctx)
// Set command flags from context.
isRecursive := ctx.Bool("recursive")
isIncomplete := ctx.Bool("incomplete")
args := ctx.Args()
// mimic operating system tool behavior.
if !ctx.Args().Present() {
args = []string{"."}
}
var cErr error
for _, targetURL := range args {
var clnt Client
clnt, err := newClient(targetURL)
fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.")
var st *clientContent
if st, err = clnt.Stat(isIncomplete); err != nil {
switch err.ToGoError().(type) {
case BucketNameEmpty:
// For aliases like ``mc ls s3`` it's acceptable to receive BucketNameEmpty error.
// Nothing to do.
default:
fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.")
}
} else if st.Type.IsDir() {
if !strings.HasSuffix(targetURL, string(clnt.GetURL().Separator)) {
targetURL = targetURL + string(clnt.GetURL().Separator)
}
clnt, err = newClient(targetURL)
fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.")
}
if e := doList(clnt, isRecursive, isIncomplete); e != nil {
cErr = e
}
}
return cErr
}
示例14: mainUpdate
// main entry point for update command.
func mainUpdate(ctx *cli.Context) {
// Set global flags from context.
setGlobalsFromContext(ctx)
// Additional command speific theme customization.
console.SetColor("Update", color.New(color.FgGreen, color.Bold))
// Check for update.
if ctx.Bool("experimental") {
getReleaseUpdate(mcUpdateExperimentalURL)
} else {
getReleaseUpdate(mcUpdateStableURL)
}
}
示例15: 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")
}