Merge pull request #1255 from abperiasamy/console-cleanup
simplify setting console theme
This commit is contained in:
+21
-36
@@ -119,26 +119,34 @@ func checkAccessSyntax(ctx *cli.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func setAccessPalette(style string) {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Access": color.New(color.FgGreen, color.Bold),
|
||||
})
|
||||
if style == "light" {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Access": color.New(color.FgWhite, color.Bold),
|
||||
})
|
||||
func doSetAccess(targetURL string, targetPERMS accessPerms) *probe.Error {
|
||||
clnt, err := url2Client(targetURL)
|
||||
if err != nil {
|
||||
return err.Trace(targetURL)
|
||||
}
|
||||
if style == "nocolor" {
|
||||
// ALl coloring options exhausted, setting nocolor safely
|
||||
console.SetNoColor()
|
||||
if err = clnt.SetBucketAccess(targetPERMS.String()); err != nil {
|
||||
return err.Trace(targetURL, targetPERMS.String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func doGetAccess(targetURL string) (perms accessPerms, err *probe.Error) {
|
||||
clnt, err := url2Client(targetURL)
|
||||
if err != nil {
|
||||
return "", err.Trace(targetURL)
|
||||
}
|
||||
acl, err := clnt.GetBucketAccess()
|
||||
if err != nil {
|
||||
return "", err.Trace(targetURL)
|
||||
}
|
||||
return aclToPerms(acl), nil
|
||||
}
|
||||
|
||||
func mainAccess(ctx *cli.Context) {
|
||||
checkAccessSyntax(ctx)
|
||||
|
||||
setAccessPalette(ctx.GlobalString("colors"))
|
||||
|
||||
// Additional command speific theme customization.
|
||||
console.SetColor("Access", color.New(color.FgGreen, color.Bold))
|
||||
config := mustGetMcConfig()
|
||||
|
||||
switch ctx.Args().Get(0) {
|
||||
@@ -171,26 +179,3 @@ func mainAccess(ctx *cli.Context) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func doSetAccess(targetURL string, targetPERMS accessPerms) *probe.Error {
|
||||
clnt, err := url2Client(targetURL)
|
||||
if err != nil {
|
||||
return err.Trace(targetURL)
|
||||
}
|
||||
if err = clnt.SetBucketAccess(targetPERMS.String()); err != nil {
|
||||
return err.Trace(targetURL, targetPERMS.String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func doGetAccess(targetURL string) (perms accessPerms, err *probe.Error) {
|
||||
clnt, err := url2Client(targetURL)
|
||||
if err != nil {
|
||||
return "", err.Trace(targetURL)
|
||||
}
|
||||
acl, err := clnt.GetBucketAccess()
|
||||
if err != nil {
|
||||
return "", err.Trace(targetURL)
|
||||
}
|
||||
return aclToPerms(acl), nil
|
||||
}
|
||||
|
||||
+21
-40
@@ -117,46 +117,6 @@ func checkConfigAliasSyntax(ctx *cli.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func setConfigAliasPalette(style string) {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Alias": color.New(color.FgCyan, color.Bold),
|
||||
"AliasMessage": color.New(color.FgGreen, color.Bold),
|
||||
"URL": color.New(color.FgWhite, color.Bold),
|
||||
})
|
||||
if style == "light" {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Alias": color.New(color.FgWhite, color.Bold),
|
||||
"AliasMessage": color.New(color.FgWhite, color.Bold),
|
||||
"URL": color.New(color.FgWhite, color.Bold),
|
||||
})
|
||||
return
|
||||
}
|
||||
/// Add more styles here
|
||||
if style == "nocolor" {
|
||||
// All coloring options exhausted, setting nocolor safely
|
||||
console.SetNoColor()
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
func listAliases() {
|
||||
config, err := newConfig()
|
||||
fatalIf(err.Trace(globalMCConfigVersion), "Failed to initialize ‘quick’ configuration data structure.")
|
||||
@@ -234,3 +194,24 @@ func addAlias(alias, url string) {
|
||||
|
||||
printMsg(aliasMessage{op: "add", Alias: alias, URL: url})
|
||||
}
|
||||
|
||||
func mainConfigAlias(ctx *cli.Context) {
|
||||
checkConfigAliasSyntax(ctx)
|
||||
|
||||
// Additional customization speific to each command.
|
||||
console.SetColor("Alias", color.New(color.FgCyan, color.Bold))
|
||||
console.SetColor("AliasMessage", color.New(color.FgGreen, color.Bold))
|
||||
console.SetColor("URL", color.New(color.FgWhite, color.Bold))
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
+6
-26
@@ -109,35 +109,15 @@ func checkConfigHostSyntax(ctx *cli.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func setConfigHostPalette(style string) {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Host": color.New(color.FgCyan, color.Bold),
|
||||
"API": color.New(color.FgYellow, color.Bold),
|
||||
"HostMessage": color.New(color.FgGreen, color.Bold),
|
||||
"AccessKeyID": color.New(color.FgBlue, color.Bold),
|
||||
"SecretAccessKey": color.New(color.FgRed, color.Bold),
|
||||
})
|
||||
if style == "light" {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Host": color.New(color.FgWhite, color.Bold),
|
||||
"API": color.New(color.FgWhite, color.Bold),
|
||||
"HostMessage": color.New(color.FgWhite, color.Bold),
|
||||
"AccessKeyID": color.New(color.FgWhite, color.Bold),
|
||||
"SecretAccessKey": color.New(color.FgWhite, color.Bold),
|
||||
})
|
||||
return
|
||||
}
|
||||
/// Add more styles here
|
||||
if style == "nocolor" {
|
||||
// All coloring options exhausted, setting nocolor safely
|
||||
console.SetNoColor()
|
||||
}
|
||||
}
|
||||
|
||||
func mainConfigHost(ctx *cli.Context) {
|
||||
checkConfigHostSyntax(ctx)
|
||||
|
||||
setConfigHostPalette(ctx.GlobalString("colors"))
|
||||
// Additional command speific theme customization.
|
||||
console.SetColor("Host", color.New(color.FgCyan, color.Bold))
|
||||
console.SetColor("API", color.New(color.FgYellow, color.Bold))
|
||||
console.SetColor("HostMessage", color.New(color.FgGreen, color.Bold))
|
||||
console.SetColor("AccessKeyID", color.New(color.FgBlue, color.Bold))
|
||||
console.SetColor("SecretAccessKey", color.New(color.FgRed, color.Bold))
|
||||
|
||||
arg := ctx.Args().First()
|
||||
tailArgs := ctx.Args().Tail()
|
||||
|
||||
+2
-18
@@ -316,28 +316,12 @@ func doCopySession(session *sessionV2) {
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func setCopyPalette(style string) {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Copy": color.New(color.FgGreen, color.Bold),
|
||||
})
|
||||
if style == "light" {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Copy": color.New(color.FgWhite, color.Bold),
|
||||
})
|
||||
return
|
||||
}
|
||||
/// Add more styles here
|
||||
if style == "nocolor" {
|
||||
// All coloring options exhausted, setting nocolor safely
|
||||
console.SetNoColor()
|
||||
}
|
||||
}
|
||||
|
||||
// mainCopy is bound to sub-command
|
||||
func mainCopy(ctx *cli.Context) {
|
||||
checkCopySyntax(ctx)
|
||||
|
||||
setCopyPalette(ctx.GlobalString("colors"))
|
||||
// Additional command speific theme customization.
|
||||
console.SetColor("Copy", color.New(color.FgGreen, color.Bold))
|
||||
|
||||
session := newSessionV2()
|
||||
|
||||
|
||||
+35
-54
@@ -59,60 +59,6 @@ func checkDiffSyntax(ctx *cli.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func setDiffPalette(style string) {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"DiffMessage": color.New(color.FgGreen, color.Bold),
|
||||
"DiffOnlyInFirst": color.New(color.FgRed, color.Bold),
|
||||
"DiffType": color.New(color.FgYellow, color.Bold),
|
||||
"DiffSize": color.New(color.FgMagenta, color.Bold),
|
||||
})
|
||||
if style == "light" {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"DiffMessage": color.New(color.FgWhite, color.Bold),
|
||||
"DiffOnlyInFirst": color.New(color.FgWhite, color.Bold),
|
||||
"DiffType": color.New(color.FgWhite, color.Bold),
|
||||
"DiffSize": color.New(color.FgWhite, color.Bold),
|
||||
})
|
||||
return
|
||||
}
|
||||
/// Add more styles here.
|
||||
if style == "nocolor" {
|
||||
// All coloring options exhausted, setting nocolor safely.
|
||||
console.SetNoColor()
|
||||
}
|
||||
}
|
||||
|
||||
// mainDiff main for 'diff'.
|
||||
func mainDiff(ctx *cli.Context) {
|
||||
checkDiffSyntax(ctx)
|
||||
|
||||
setDiffPalette(ctx.GlobalString("colors"))
|
||||
|
||||
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."))
|
||||
}
|
||||
|
||||
// doDiffMain runs the diff.
|
||||
func doDiffMain(firstURL, secondURL string, recursive bool) <-chan diffMessage {
|
||||
ch := make(chan diffMessage, 10000)
|
||||
@@ -161,3 +107,38 @@ func doDiffInRoutine(firstURL, secondURL string, recursive bool, ch chan diffMes
|
||||
}
|
||||
diffFolders(firstClnt, secondClnt, ch)
|
||||
}
|
||||
|
||||
// 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."))
|
||||
}
|
||||
|
||||
@@ -39,9 +39,9 @@ var (
|
||||
Usage: "Suppress chatty console output.",
|
||||
}
|
||||
|
||||
mimicFlag = cli.BoolFlag{
|
||||
Name: "mimic",
|
||||
Usage: "Behave like operating system tools. Use with shell aliases.",
|
||||
colorsFlag = cli.BoolFlag{
|
||||
Name: "no-color",
|
||||
Usage: "Disable color theme.",
|
||||
}
|
||||
|
||||
jsonFlag = cli.BoolFlag{
|
||||
@@ -54,10 +54,9 @@ var (
|
||||
Usage: "Enable debugging output.",
|
||||
}
|
||||
|
||||
colorsFlag = cli.StringFlag{
|
||||
Name: "colors",
|
||||
Value: "dark",
|
||||
Usage: "Choose type of console coloring. Available options are [‘dark’, ‘light’, ‘nocolor’]",
|
||||
mimicFlag = cli.BoolFlag{
|
||||
Name: "mimic",
|
||||
Usage: "Behave like operating system tools. Use with shell aliases.",
|
||||
}
|
||||
|
||||
// Add your new flags starting here
|
||||
|
||||
+5
-26
@@ -92,34 +92,13 @@ func checkListSyntax(ctx *cli.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// setListPalette - set ls output theme
|
||||
func setListPalette(style string) {
|
||||
console.SetCustomPalette(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),
|
||||
})
|
||||
if style == "light" {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"File": color.New(color.FgWhite, color.Bold),
|
||||
"Dir": color.New(color.FgWhite, color.Bold),
|
||||
"Size": color.New(color.FgWhite, color.Bold),
|
||||
"Time": color.New(color.FgWhite, color.Bold),
|
||||
})
|
||||
return
|
||||
}
|
||||
/// Add more styles here if needed
|
||||
if style == "nocolor" {
|
||||
// All coloring options exhausted, setting nocolor safely
|
||||
console.SetNoColor()
|
||||
}
|
||||
}
|
||||
|
||||
// mainList - is a handler for mc ls command
|
||||
func mainList(ctx *cli.Context) {
|
||||
// set theme for 'ls'
|
||||
setListPalette(ctx.GlobalString("colors"))
|
||||
// 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)
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/console"
|
||||
"github.com/minio/minio-xl/pkg/probe"
|
||||
@@ -30,6 +29,39 @@ import (
|
||||
"github.com/olekukonko/ts"
|
||||
)
|
||||
|
||||
// Help template for mc
|
||||
var mcHelpTemplate = `NAME:
|
||||
{{.Name}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.Name}} {{if .Flags}}[global flags] {{end}}command{{if .Flags}} [command flags]{{end}} [arguments...]
|
||||
|
||||
COMMANDS:
|
||||
{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
|
||||
{{end}}{{if .Flags}}
|
||||
GLOBAL FLAGS:
|
||||
{{range .Flags}}{{.}}
|
||||
{{end}}{{end}}
|
||||
VERSION:
|
||||
` + mcVersion +
|
||||
`{{ "\n"}}{{range $key, $value := ExtraInfo}}
|
||||
{{$key}}:
|
||||
{{$value}}
|
||||
{{end}}`
|
||||
|
||||
// Default handler for missing commands.
|
||||
func commandNotFound(ctx *cli.Context, command string) {
|
||||
msg := fmt.Sprintf("‘%s’ is not a mc command. See ‘mc help’.", command)
|
||||
closestCommands := findClosestCommands(command)
|
||||
if len(closestCommands) > 0 {
|
||||
msg += fmt.Sprintf("\n\nDid you mean one of these?\n")
|
||||
for _, cmd := range closestCommands {
|
||||
msg += fmt.Sprintf(" ‘%s’\n", cmd)
|
||||
}
|
||||
}
|
||||
fatalIf(errDummy().Trace(), msg)
|
||||
}
|
||||
|
||||
// Check for sane config environment early on and gracefully report.
|
||||
func checkConfig() {
|
||||
// Ensures config file is sane
|
||||
@@ -76,12 +108,15 @@ func registerBefore(ctx *cli.Context) error {
|
||||
globalMimicFlag = ctx.GlobalBool("mimic")
|
||||
globalDebugFlag = ctx.GlobalBool("debug")
|
||||
globalJSONFlag = ctx.GlobalBool("json")
|
||||
|
||||
if globalDebugFlag {
|
||||
console.NoDebugPrint = false
|
||||
}
|
||||
|
||||
// Set theme.
|
||||
setMainPalette(ctx.GlobalString("colors"))
|
||||
// Disable color themes.
|
||||
if ctx.GlobalBool("no-color") == true {
|
||||
console.SetColorOff()
|
||||
}
|
||||
|
||||
// Verify golang runtime
|
||||
verifyMCRuntime()
|
||||
@@ -134,66 +169,11 @@ func registerApp() *cli.App {
|
||||
app.Commands = commands
|
||||
app.Flags = flags
|
||||
app.Author = "Minio.io"
|
||||
app.CustomAppHelpTemplate = `NAME:
|
||||
{{.Name}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.Name}} {{if .Flags}}[global flags] {{end}}command{{if .Flags}} [command flags]{{end}} [arguments...]
|
||||
|
||||
COMMANDS:
|
||||
{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
|
||||
{{end}}{{if .Flags}}
|
||||
GLOBAL FLAGS:
|
||||
{{range .Flags}}{{.}}
|
||||
{{end}}{{end}}
|
||||
VERSION:
|
||||
` + mcVersion +
|
||||
`{{ "\n"}}{{range $key, $value := ExtraInfo}}
|
||||
{{$key}}:
|
||||
{{$value}}
|
||||
{{end}}`
|
||||
app.CommandNotFound = func(ctx *cli.Context, command string) {
|
||||
msg := fmt.Sprintf("‘%s’ is not a mc command. See ‘mc help’.", command)
|
||||
closestCommands := findClosestCommands(command)
|
||||
if len(closestCommands) > 0 {
|
||||
msg += fmt.Sprintf("\n\nDid you mean one of these?\n")
|
||||
for _, cmd := range closestCommands {
|
||||
msg += fmt.Sprintf(" ‘%s’\n", cmd)
|
||||
}
|
||||
}
|
||||
fatalIf(errDummy().Trace(), msg)
|
||||
|
||||
}
|
||||
app.CustomAppHelpTemplate = mcHelpTemplate
|
||||
app.CommandNotFound = commandNotFound // handler function declared above.
|
||||
return app
|
||||
}
|
||||
|
||||
func setMainPalette(style string) {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Debug": color.New(color.FgWhite, color.Faint, color.Italic),
|
||||
"Fatal": color.New(color.FgRed, color.Italic, color.Bold),
|
||||
"Error": color.New(color.FgYellow, color.Italic),
|
||||
"Info": color.New(color.FgGreen, color.Bold),
|
||||
"Print": color.New(),
|
||||
"PrintC": color.New(color.FgGreen, color.Bold),
|
||||
})
|
||||
if style == "light" {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Debug": color.New(color.FgWhite, color.Faint, color.Italic),
|
||||
"Fatal": color.New(color.FgWhite, color.Italic, color.Bold),
|
||||
"Error": color.New(color.FgWhite, color.Italic, color.Bold),
|
||||
"Info": color.New(color.FgWhite, color.Bold),
|
||||
"Print": color.New(),
|
||||
"PrintC": color.New(color.FgWhite, color.Bold),
|
||||
})
|
||||
return
|
||||
}
|
||||
/// Add more styles here
|
||||
if style == "nocolor" {
|
||||
// All coloring options exhausted, setting nocolor safely
|
||||
console.SetNoColor()
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
probe.Init() // Set project's root source path.
|
||||
probe.SetAppInfo("Release-Tag", mcReleaseTag)
|
||||
|
||||
+2
-17
@@ -82,27 +82,12 @@ func checkMakeBucketSyntax(ctx *cli.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func setMakeBucketPalette(style string) {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"MakeBucket": color.New(color.FgGreen, color.Bold),
|
||||
})
|
||||
if style == "light" {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"MakeBucket": color.New(color.FgWhite, color.Bold),
|
||||
})
|
||||
return
|
||||
}
|
||||
if style == "nocolor" {
|
||||
// All coloring options exhausted, setting nocolor safely
|
||||
console.SetNoColor()
|
||||
}
|
||||
}
|
||||
|
||||
// mainMakeBucket is the handler for mc mb command
|
||||
func mainMakeBucket(ctx *cli.Context) {
|
||||
checkMakeBucketSyntax(ctx)
|
||||
|
||||
setMakeBucketPalette(ctx.GlobalString("colors"))
|
||||
// Additional command speific theme customization.
|
||||
console.SetColor("MakeBucket", color.New(color.FgGreen, color.Bold))
|
||||
|
||||
config := mustGetMcConfig()
|
||||
for _, arg := range ctx.Args() {
|
||||
|
||||
+2
-18
@@ -312,27 +312,11 @@ func doMirrorSession(session *sessionV2) {
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func setMirrorPalette(style string) {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Mirror": color.New(color.FgGreen, color.Bold),
|
||||
})
|
||||
if style == "light" {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Mirror": color.New(color.FgWhite, color.Bold),
|
||||
})
|
||||
return
|
||||
}
|
||||
/// Add more styles here
|
||||
if style == "nocolor" {
|
||||
// All coloring options exhausted, setting nocolor safely
|
||||
console.SetNoColor()
|
||||
}
|
||||
}
|
||||
|
||||
func mainMirror(ctx *cli.Context) {
|
||||
checkMirrorSyntax(ctx)
|
||||
|
||||
setMirrorPalette(ctx.GlobalString("colors"))
|
||||
// Additional command speific theme customization.
|
||||
console.SetColor("Mirror", color.New(color.FgGreen, color.Bold))
|
||||
|
||||
var e error
|
||||
session := newSessionV2()
|
||||
|
||||
+56
-81
@@ -25,26 +25,19 @@ import (
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/mattn/go-isatty"
|
||||
"github.com/minio/minio-xl/pkg/probe"
|
||||
"github.com/shiena/ansicolor"
|
||||
)
|
||||
|
||||
// NoDebugPrint defines if the input should be printed in debug or not. By default it's set to true.
|
||||
var NoDebugPrint = true
|
||||
|
||||
// IsTesting this flag indicates if IsExited should be set or not, false by default
|
||||
var IsTesting = false
|
||||
|
||||
// IsExited sets this boolean value if Fatal is called when IsTesting is enabled
|
||||
var IsExited = false
|
||||
|
||||
// IsError sets this boolean value if Error is called when IsTesting is enabled
|
||||
var IsError = false
|
||||
|
||||
// Palette default map
|
||||
var Palette = map[string]*color.Color{}
|
||||
|
||||
var (
|
||||
// NoDebugPrint defines if the input should be printed in debug or not. By default it's set to true.
|
||||
NoDebugPrint = true
|
||||
// IsTesting this flag indicates if IsExited should be set or not, false by default.
|
||||
IsTesting = false
|
||||
// IsExited sets this boolean value if Fatal is called when IsTesting is enabled.
|
||||
IsExited = false
|
||||
// IsError sets this boolean value if Error is called when IsTesting is enabled.
|
||||
IsError = false
|
||||
|
||||
// Used by the caller to print multiple lines atomically. Exposed by Lock/Unlock methods.
|
||||
publicMutex = &sync.Mutex{}
|
||||
// Used internally by console.
|
||||
@@ -52,32 +45,32 @@ var (
|
||||
|
||||
stderrColoredOutput = ansicolor.NewAnsiColorWriter(os.Stderr)
|
||||
|
||||
// Print prints a message
|
||||
// Print prints a message.
|
||||
Print = func(data ...interface{}) {
|
||||
consolePrint("Print", Palette["Print"], data...)
|
||||
consolePrint("Print", Theme["Print"], data...)
|
||||
return
|
||||
}
|
||||
|
||||
// PrintC prints a message with color
|
||||
// PrintC prints a message with color.
|
||||
PrintC = func(data ...interface{}) {
|
||||
consolePrint("PrintC", Palette["PrintC"], data...)
|
||||
consolePrint("PrintC", Theme["PrintC"], data...)
|
||||
return
|
||||
}
|
||||
|
||||
// Printf prints a formatted message
|
||||
// Printf prints a formatted message.
|
||||
Printf = func(format string, data ...interface{}) {
|
||||
consolePrintf("Print", Palette["Print"], format, data...)
|
||||
consolePrintf("Print", Theme["Print"], format, data...)
|
||||
return
|
||||
}
|
||||
|
||||
// Println prints a message with a newline
|
||||
// Println prints a message with a newline.
|
||||
Println = func(data ...interface{}) {
|
||||
consolePrintln("Print", Palette["Print"], data...)
|
||||
consolePrintln("Print", Theme["Print"], data...)
|
||||
return
|
||||
}
|
||||
|
||||
// fatalQuitRoutine called after fatal message printing
|
||||
// by the user specific version
|
||||
// fatalQuitRoutine called after fatal message printing.
|
||||
// by the user specific version.
|
||||
fatalQuitRoutine = func() {
|
||||
if !IsTesting {
|
||||
os.Exit(1)
|
||||
@@ -87,29 +80,29 @@ var (
|
||||
}()
|
||||
}
|
||||
|
||||
// Fatal print a error message and exit
|
||||
// Fatal print a error message and exit.
|
||||
Fatal = func(data ...interface{}) {
|
||||
consolePrint("Fatal", Palette["Fatal"], data...)
|
||||
consolePrint("Fatal", Theme["Fatal"], data...)
|
||||
fatalQuitRoutine()
|
||||
return
|
||||
}
|
||||
|
||||
// Fatalf print a error message with a format specified and exit
|
||||
// Fatalf print a error message with a format specified and exit.
|
||||
Fatalf = func(format string, data ...interface{}) {
|
||||
consolePrintf("Fatal", Palette["Fatal"], format, data...)
|
||||
consolePrintf("Fatal", Theme["Fatal"], format, data...)
|
||||
fatalQuitRoutine()
|
||||
return
|
||||
}
|
||||
|
||||
// Fatalln print a error message with a new line and exit
|
||||
// Fatalln print a error message with a new line and exit.
|
||||
Fatalln = func(data ...interface{}) {
|
||||
consolePrintln("Fatal", Palette["Fatal"], data...)
|
||||
consolePrintln("Fatal", Theme["Fatal"], data...)
|
||||
fatalQuitRoutine()
|
||||
return
|
||||
}
|
||||
|
||||
// errorQuitRoutine called after error message printing
|
||||
// by the user specific version
|
||||
// by the user specific version.
|
||||
errorQuitRoutine = func() {
|
||||
if IsTesting {
|
||||
defer func() {
|
||||
@@ -118,84 +111,84 @@ var (
|
||||
}
|
||||
}
|
||||
|
||||
// Error prints a error message
|
||||
// Error prints a error message.
|
||||
Error = func(data ...interface{}) {
|
||||
consolePrint("Error", Palette["Error"], data...)
|
||||
consolePrint("Error", Theme["Error"], data...)
|
||||
errorQuitRoutine()
|
||||
return
|
||||
}
|
||||
|
||||
// Errorf print a error message with a format specified
|
||||
// Errorf print a error message with a format specified.
|
||||
Errorf = func(format string, data ...interface{}) {
|
||||
consolePrintf("Error", Palette["Error"], format, data...)
|
||||
consolePrintf("Error", Theme["Error"], format, data...)
|
||||
errorQuitRoutine()
|
||||
return
|
||||
}
|
||||
|
||||
// Errorln prints a error message with a new line
|
||||
// Errorln prints a error message with a new line.
|
||||
Errorln = func(data ...interface{}) {
|
||||
consolePrintln("Error", Palette["Error"], data...)
|
||||
consolePrintln("Error", Theme["Error"], data...)
|
||||
errorQuitRoutine()
|
||||
return
|
||||
}
|
||||
|
||||
// Info prints a informational message
|
||||
// Info prints a informational message.
|
||||
Info = func(data ...interface{}) {
|
||||
consolePrint("Info", Palette["Info"], data...)
|
||||
consolePrint("Info", Theme["Info"], data...)
|
||||
return
|
||||
}
|
||||
|
||||
// Infof prints a informational message in custom format
|
||||
// Infof prints a informational message in custom format.
|
||||
Infof = func(format string, data ...interface{}) {
|
||||
consolePrintf("Info", Palette["Info"], format, data...)
|
||||
consolePrintf("Info", Theme["Info"], format, data...)
|
||||
return
|
||||
}
|
||||
|
||||
// Infoln prints a informational message with a new line
|
||||
// Infoln prints a informational message with a new line.
|
||||
Infoln = func(data ...interface{}) {
|
||||
consolePrintln("Info", Palette["Info"], data...)
|
||||
consolePrintln("Info", Theme["Info"], data...)
|
||||
return
|
||||
}
|
||||
|
||||
// Debug prints a debug message without a new line
|
||||
// Debug prints a debug message
|
||||
// Debug prints a debug message.
|
||||
Debug = func(data ...interface{}) {
|
||||
if !NoDebugPrint {
|
||||
consolePrint("Debug", Palette["Debug"], data...)
|
||||
consolePrint("Debug", Theme["Debug"], data...)
|
||||
}
|
||||
}
|
||||
|
||||
// Debugf prints a debug message with a new line
|
||||
// Debugf prints a debug message with a new line.
|
||||
Debugf = func(format string, data ...interface{}) {
|
||||
if !NoDebugPrint {
|
||||
consolePrintf("Debug", Palette["Debug"], format, data...)
|
||||
consolePrintf("Debug", Theme["Debug"], format, data...)
|
||||
}
|
||||
}
|
||||
|
||||
// Debugln prints a debug message with a new line
|
||||
// Debugln prints a debug message with a new line.
|
||||
Debugln = func(data ...interface{}) {
|
||||
if !NoDebugPrint {
|
||||
consolePrintln("Debug", Palette["Debug"], data...)
|
||||
consolePrintln("Debug", Theme["Debug"], data...)
|
||||
}
|
||||
}
|
||||
|
||||
// Colorize prints message in a colorized form, dictated by the corresponding tag argument
|
||||
// Colorize prints message in a colorized form, dictated by the corresponding tag argument.
|
||||
Colorize = func(tag string, data interface{}) string {
|
||||
if isatty.IsTerminal(os.Stdout.Fd()) {
|
||||
return Palette[tag].SprintFunc()(data)
|
||||
return Theme[tag].SprintFunc()(data)
|
||||
}
|
||||
return fmt.Sprint(data)
|
||||
}
|
||||
|
||||
// Eraseline Print in new line and adjust to top so that we don't print over the ongoing progress bar
|
||||
// Eraseline Print in new line and adjust to top so that we don't print over the ongoing progress bar.
|
||||
Eraseline = func() {
|
||||
consolePrintf("Print", Palette["Print"], "%c[2K\n", 27)
|
||||
consolePrintf("Print", Palette["Print"], "%c[A", 27)
|
||||
consolePrintf("Print", Theme["Print"], "%c[2K\n", 27)
|
||||
consolePrintf("Print", Theme["Print"], "%c[A", 27)
|
||||
}
|
||||
)
|
||||
|
||||
// wrap around standard fmt functions
|
||||
// consolePrint prints a message prefixed with message type and program name
|
||||
// wrap around standard fmt functions.
|
||||
// consolePrint prints a message prefixed with message type and program name.
|
||||
func consolePrint(tag string, c *color.Color, a ...interface{}) {
|
||||
privateMutex.Lock()
|
||||
defer privateMutex.Unlock()
|
||||
@@ -242,7 +235,7 @@ func consolePrint(tag string, c *color.Color, a ...interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
// consolePrintf - same as print with a new line
|
||||
// consolePrintf - same as print with a new line.
|
||||
func consolePrintf(tag string, c *color.Color, format string, a ...interface{}) {
|
||||
privateMutex.Lock()
|
||||
defer privateMutex.Unlock()
|
||||
@@ -289,7 +282,7 @@ func consolePrintf(tag string, c *color.Color, format string, a ...interface{})
|
||||
}
|
||||
}
|
||||
|
||||
// consolePrintln - same as print with a new line
|
||||
// consolePrintln - same as print with a new line.
|
||||
func consolePrintln(tag string, c *color.Color, a ...interface{}) {
|
||||
privateMutex.Lock()
|
||||
defer privateMutex.Unlock()
|
||||
@@ -336,36 +329,18 @@ func consolePrintln(tag string, c *color.Color, a ...interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
// Lock console
|
||||
// Lock console.
|
||||
func Lock() {
|
||||
publicMutex.Lock()
|
||||
}
|
||||
|
||||
// Unlock locked console
|
||||
// Unlock locked console.
|
||||
func Unlock() {
|
||||
publicMutex.Unlock()
|
||||
}
|
||||
|
||||
// SetCustomPalette sets a color theme
|
||||
func SetCustomPalette(theme map[string]*color.Color) *probe.Error {
|
||||
privateMutex.Lock()
|
||||
defer privateMutex.Unlock()
|
||||
// add new theme
|
||||
for k, v := range theme {
|
||||
Palette[k] = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ProgramName - return the name of the executable program
|
||||
// ProgramName - return the name of the executable program.
|
||||
func ProgramName() string {
|
||||
_, progName := filepath.Split(os.Args[0])
|
||||
return progName
|
||||
}
|
||||
|
||||
// SetNoColor disable coloring
|
||||
func SetNoColor() {
|
||||
privateMutex.Lock()
|
||||
defer privateMutex.Unlock()
|
||||
color.NoColor = true
|
||||
}
|
||||
|
||||
@@ -29,10 +29,9 @@ type MySuite struct{}
|
||||
|
||||
var _ = Suite(&MySuite{})
|
||||
|
||||
func (s *MySuite) TestSetPalette(c *C) {
|
||||
err := SetCustomPalette(map[string]*color.Color{"unknown": new(color.Color)})
|
||||
c.Assert(err, IsNil)
|
||||
_, ok := Palette["unknown"]
|
||||
func (s *MySuite) TestSetColor(c *C) {
|
||||
SetColor("unknown", color.New(color.FgWhite))
|
||||
_, ok := Theme["unknown"]
|
||||
c.Assert(ok, Equals, true)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Minio Client (C) 2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package console
|
||||
|
||||
import "github.com/fatih/color"
|
||||
|
||||
var (
|
||||
// Theme contains default color mapping.
|
||||
Theme = map[string]*color.Color{
|
||||
"Debug": color.New(color.FgWhite, color.Faint, color.Italic),
|
||||
"Fatal": color.New(color.FgRed, color.Italic, color.Bold),
|
||||
"Error": color.New(color.FgYellow, color.Italic),
|
||||
"Info": color.New(color.FgGreen, color.Bold),
|
||||
"Print": color.New(),
|
||||
"PrintC": color.New(color.FgGreen, color.Bold),
|
||||
}
|
||||
)
|
||||
|
||||
// SetColorOff disables coloring for the entire session.
|
||||
func SetColorOff() {
|
||||
privateMutex.Lock()
|
||||
defer privateMutex.Unlock()
|
||||
color.NoColor = true
|
||||
}
|
||||
|
||||
// SetColorOn enables coloring for the entire session.
|
||||
func SetColorOn() {
|
||||
privateMutex.Lock()
|
||||
defer privateMutex.Unlock()
|
||||
color.NoColor = false
|
||||
}
|
||||
|
||||
// SetColor sets a color for a particular tag.
|
||||
func SetColor(tag string, cl *color.Color) {
|
||||
privateMutex.Lock()
|
||||
defer privateMutex.Unlock()
|
||||
// add new theme
|
||||
Theme[tag] = cl
|
||||
}
|
||||
+3
-3
@@ -142,9 +142,9 @@ func getFixedWidth(width, percent int) int {
|
||||
|
||||
// newProgressBar - instantiate a pbBar.
|
||||
func newProgressBar(total int64) *barSend {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Bar": color.New(color.FgGreen, color.Bold),
|
||||
})
|
||||
// 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) {
|
||||
|
||||
+2
-20
@@ -177,24 +177,6 @@ func rmAll(url string, isIncomplete bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// set theme for rm command.
|
||||
func setRmPalette(style string) {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Remove": color.New(color.FgGreen, color.Bold),
|
||||
})
|
||||
if style == "light" {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Remove": color.New(color.FgWhite, color.Bold),
|
||||
})
|
||||
return
|
||||
}
|
||||
/// Add more styles here
|
||||
if style == "nocolor" {
|
||||
// All coloring options exhausted, setting nocolor safely
|
||||
console.SetNoColor()
|
||||
}
|
||||
}
|
||||
|
||||
// main for rm command.
|
||||
func mainRm(ctx *cli.Context) {
|
||||
checkRmSyntax(ctx)
|
||||
@@ -203,8 +185,8 @@ func mainRm(ctx *cli.Context) {
|
||||
isForce := ctx.Bool("force")
|
||||
isIncomplete := ctx.Bool("incomplete")
|
||||
|
||||
// Set theme.
|
||||
setRmPalette(ctx.GlobalString("colors"))
|
||||
// Set color.
|
||||
console.SetColor("Remove", color.New(color.FgGreen, color.Bold))
|
||||
|
||||
// Parse args.
|
||||
URLs, err := args2URLs(ctx.Args())
|
||||
|
||||
+5
-24
@@ -157,33 +157,14 @@ func checkSessionSyntax(ctx *cli.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
func setSessionPalette(style string) {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Command": color.New(color.FgWhite, color.Bold),
|
||||
"SessionID": color.New(color.FgYellow, color.Bold),
|
||||
"SessionTime": color.New(color.FgGreen),
|
||||
"ClearSession": color.New(color.FgGreen, color.Bold),
|
||||
})
|
||||
if style == "light" {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Command": color.New(color.FgWhite, color.Bold),
|
||||
"SessionID": color.New(color.FgWhite, color.Bold),
|
||||
"SessionTime": color.New(color.FgWhite, color.Bold),
|
||||
"ClearSession": color.New(color.FgWhite, color.Bold),
|
||||
})
|
||||
return
|
||||
}
|
||||
/// Add more styles here
|
||||
if style == "nocolor" {
|
||||
// All coloring options exhausted, setting nocolor safely
|
||||
console.SetNoColor()
|
||||
}
|
||||
}
|
||||
|
||||
func mainSession(ctx *cli.Context) {
|
||||
checkSessionSyntax(ctx)
|
||||
|
||||
setSessionPalette(ctx.GlobalString("colors"))
|
||||
// Additional command speific theme customization.
|
||||
console.SetColor("Command", color.New(color.FgWhite, color.Bold))
|
||||
console.SetColor("SessionID", color.New(color.FgYellow, color.Bold))
|
||||
console.SetColor("SessionTime", color.New(color.FgGreen))
|
||||
console.SetColor("ClearSession", color.New(color.FgGreen, color.Bold))
|
||||
|
||||
if !isSessionDirExists() {
|
||||
fatalIf(createSessionDir().Trace(), "Unable to create session folder.")
|
||||
|
||||
@@ -68,8 +68,10 @@ func checkShareDownloadSyntax(ctx *cli.Context) {
|
||||
func mainShareDownload(ctx *cli.Context) {
|
||||
// setup share data folder and file.
|
||||
shareDataSetup()
|
||||
// set share command theme.
|
||||
setSharePalette(ctx.GlobalString("colors"))
|
||||
|
||||
// Additional command speific theme customization.
|
||||
shareSetColor()
|
||||
|
||||
// check input arguments.
|
||||
checkShareDownloadSyntax(ctx)
|
||||
|
||||
|
||||
+4
-2
@@ -109,8 +109,10 @@ func doShareList() *probe.Error {
|
||||
func mainShareList(ctx *cli.Context) {
|
||||
// setup share data folder and file.
|
||||
shareDataSetup()
|
||||
// set share command theme.
|
||||
setSharePalette(ctx.GlobalString("colors"))
|
||||
|
||||
// Additional command speific theme customization.
|
||||
shareSetColor()
|
||||
|
||||
err := doShareList()
|
||||
fatalIf(err.Trace(), "Unable to list shared URLs.")
|
||||
}
|
||||
|
||||
@@ -148,4 +148,6 @@ 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.
|
||||
}
|
||||
|
||||
@@ -73,8 +73,10 @@ func checkShareUploadSyntax(ctx *cli.Context) {
|
||||
func mainShareUpload(ctx *cli.Context) {
|
||||
// setup share data folder and file.
|
||||
shareDataSetup()
|
||||
// set share command theme.
|
||||
setSharePalette(ctx.GlobalString("colors"))
|
||||
|
||||
// Additional command speific theme customization.
|
||||
shareSetColor()
|
||||
|
||||
// check input arguments.
|
||||
checkShareUploadSyntax(ctx)
|
||||
|
||||
|
||||
@@ -30,6 +30,15 @@ import (
|
||||
"github.com/minio/minio-xl/pkg/quick"
|
||||
)
|
||||
|
||||
// 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))
|
||||
}
|
||||
|
||||
// create shared data folder and file if they doesn't exist.
|
||||
func shareDataSetup() {
|
||||
if !isSharedURLsDataDirExists() {
|
||||
@@ -48,32 +57,6 @@ func shareDataSetup() {
|
||||
}
|
||||
}
|
||||
|
||||
// set share command theme
|
||||
func setSharePalette(style string) {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Share": color.New(color.FgGreen, color.Bold),
|
||||
"Expires": color.New(color.FgRed, color.Bold),
|
||||
"URL": color.New(color.FgCyan, color.Bold),
|
||||
"File": color.New(color.FgRed, color.Bold),
|
||||
})
|
||||
|
||||
if style == "light" {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Share": color.New(color.FgWhite, color.Bold),
|
||||
"Expires": color.New(color.FgWhite, color.Bold),
|
||||
"URL": color.New(color.FgWhite, color.Bold),
|
||||
"File": color.New(color.FgWhite, color.Bold),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
/// Add more styles here
|
||||
if style == "nocolor" {
|
||||
// All coloring options exhausted, setting nocolor safely
|
||||
console.SetNoColor()
|
||||
}
|
||||
}
|
||||
|
||||
// migrateSharedURLs migrate to newest version sequentially
|
||||
func migrateSharedURLs() {
|
||||
migrateSharedURLsV1ToV2()
|
||||
|
||||
+3
-20
@@ -104,30 +104,13 @@ func checkUpdateSyntax(ctx *cli.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// set update command theme.
|
||||
func setUpdatePalette(style string) {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"UpdateMessage": color.New(color.FgGreen, color.Bold),
|
||||
})
|
||||
if style == "light" {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"UpdateMessage": color.New(color.FgWhite, color.Bold),
|
||||
})
|
||||
return
|
||||
}
|
||||
/// Add more styles here.
|
||||
if style == "nocolor" {
|
||||
// All coloring options exhausted, setting nocolor safely.
|
||||
console.SetNoColor()
|
||||
}
|
||||
}
|
||||
|
||||
// main for update command.
|
||||
func mainUpdate(ctx *cli.Context) {
|
||||
// check input arguments
|
||||
checkUpdateSyntax(ctx)
|
||||
// set theme
|
||||
setUpdatePalette(ctx.GlobalString("colors"))
|
||||
|
||||
// Additional command speific theme customization.
|
||||
console.SetColor("UpdateMessage", color.New(color.FgGreen, color.Bold))
|
||||
|
||||
arg := strings.TrimSpace(ctx.Args().First())
|
||||
switch arg {
|
||||
|
||||
+2
-18
@@ -40,29 +40,13 @@ USAGE:
|
||||
`,
|
||||
}
|
||||
|
||||
func setVersionPalette(style string) {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Version": color.New(color.FgGreen, color.Bold),
|
||||
})
|
||||
if style == "light" {
|
||||
console.SetCustomPalette(map[string]*color.Color{
|
||||
"Version": color.New(color.FgWhite, color.Bold),
|
||||
})
|
||||
return
|
||||
}
|
||||
/// Add more styles here
|
||||
if style == "nocolor" {
|
||||
// All coloring options exhausted, setting nocolor safely
|
||||
console.SetNoColor()
|
||||
}
|
||||
}
|
||||
|
||||
func mainVersion(ctx *cli.Context) {
|
||||
if ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "version", 1) // last argument is exit code
|
||||
}
|
||||
|
||||
setVersionPalette(ctx.GlobalString("colors"))
|
||||
// Additional command speific theme customization.
|
||||
console.SetColor("Version", color.New(color.FgGreen, color.Bold))
|
||||
|
||||
if globalJSONFlag {
|
||||
tB, e := json.Marshal(
|
||||
|
||||
Reference in New Issue
Block a user