本文整理匯總了Golang中github.com/minio/mc/pkg/console.SetColor函數的典型用法代碼示例。如果您正苦於以下問題:Golang SetColor函數的具體用法?Golang SetColor怎麽用?Golang SetColor使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了SetColor函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: shareSetColor
// shareSetColor sets colors share sub-commands.
func shareSetColor() {
// Additional command speific theme customization.
console.SetColor("Share", color.New(color.FgGreen, color.Bold))
console.SetColor("Expires", color.New(color.FgRed, color.Bold))
console.SetColor("URL", color.New(color.FgCyan, color.Bold))
console.SetColor("File", color.New(color.FgRed, color.Bold))
}
示例2: 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."))
}
示例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: 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
}
}
}
示例5: shareSetColor
// shareSetColor sets colors share sub-commands.
func shareSetColor() {
// Additional command speific theme customization.
console.SetColor("URL", color.New(color.FgWhite, color.Bold))
console.SetColor("Expire", color.New(color.FgCyan))
console.SetColor("Content-type", color.New(color.FgBlue))
console.SetColor("Share", color.New(color.FgGreen))
console.SetColor("File", color.New(color.FgRed, color.Bold))
}
示例6: 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
}
示例7: 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()
}
示例8: 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()
}
示例9: 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})
}
}
示例10: mainEventsAdd
func mainEventsAdd(ctx *cli.Context) error {
console.SetColor("Events", color.New(color.FgGreen, color.Bold))
setGlobalsFromContext(ctx)
checkEventsAddSyntax(ctx)
args := ctx.Args()
path := args[0]
arn := args[1]
events := strings.Split(ctx.String("events"), ",")
prefix := ctx.String("prefix")
suffix := ctx.String("suffix")
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.AddNotificationConfig(arn, events, prefix, suffix)
fatalIf(err, "Cannot enable notification on the specified bucket.")
printMsg(eventsAddMessage{
ARN: arn,
Events: events,
Prefix: prefix,
Suffix: suffix,
})
return nil
}
示例11: 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()
}
示例12: 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
}
示例13: 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})
}
}
}
示例14: mainVersion
func mainVersion(ctx *cli.Context) {
// Set global flags from context.
setGlobalsFromContext(ctx)
// Additional command speific theme customization.
console.SetColor("Version", color.New(color.FgGreen, color.Bold))
console.SetColor("ReleaseTag", color.New(color.FgGreen))
console.SetColor("CommitID", color.New(color.FgGreen))
verMsg := versionMessage{}
verMsg.CommitID = mcCommitID
verMsg.ReleaseTag = mcReleaseTag
verMsg.Version.Value = mcVersion
verMsg.Version.Format = "RFC3339"
printMsg(verMsg)
}
示例15: newProgressBar
// newProgressBar - instantiate a pbBar.
func newProgressBar(total int64) *barSend {
// Progress bar speific theme customization.
console.SetColor("Bar", color.New(color.FgGreen, color.Bold))
cmdCh := make(chan barMsg)
finishCh := make(chan bool)
go func(total int64, cmdCh <-chan barMsg, finishCh chan<- bool) {
var started bool
var totalBytesRead int64 // total amounts of bytes read
bar := pb.New64(total)
bar.SetUnits(pb.U_BYTES)
bar.SetRefreshRate(time.Millisecond * 125)
bar.NotPrint = true
bar.ShowSpeed = true
bar.Callback = func(s string) {
console.Print(console.Colorize("Bar", "\r"+s))
}
switch runtime.GOOS {
case "linux":
bar.Format("┃▓█░┃")
// bar.Format("█▓▒░█")
case "darwin":
bar.Format(" ▓ ░ ")
default:
bar.Format("[=> ]")
}
for msg := range cmdCh {
switch msg.Op {
case pbBarSetCaption:
bar.Prefix(fixateBarCaption(msg.Arg.(string), getFixedWidth(bar.GetWidth(), 18)))
case pbBarProgress:
if bar.Total > 0 && !started {
started = true
bar.Start()
}
if msg.Arg.(int64) > 0 {
totalBytesRead += msg.Arg.(int64)
bar.Add64(msg.Arg.(int64))
}
case pbBarPutError:
if totalBytesRead > msg.Arg.(int64) {
bar.Set64(totalBytesRead - msg.Arg.(int64))
}
case pbBarGetError:
if msg.Arg.(int64) > 0 {
bar.Add64(msg.Arg.(int64))
}
case pbBarFinish:
if started {
bar.Finish()
}
finishCh <- true
return
}
}
}(total, cmdCh, finishCh)
return &barSend{cmdCh, finishCh}
}