-
-
Notifications
You must be signed in to change notification settings - Fork 896
feat: add color flag #766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: add color flag #766
Conversation
main.go
Outdated
| flag.StringVar(&cfgPath, "c", "", "config path") | ||
| flag.BoolVar(&debugMode, "d", false, "debug mode") | ||
| flag.BoolVar(&showVersion, "v", false, "show version") | ||
| flag.BoolVar(&forceColor, "colored", false, "force colored output") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect to be able to force color on or off via the CLI argument
| flag.BoolVar(&forceColor, "colored", false, "force colored output") | |
| flag.StringVar(&colorMode, "color", "auto", "colored output: auto, always, never") |
It's a common pattern with CLI tool.
I know NO_COLOR env can be used with fatih/color, but people could expect to disable color with CLI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, thank you for the insight. As a web dev I don't have much experience creating/maintaining CLI tools
main.go
Outdated
| if forceColor { | ||
| color.NoColor = false | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So here, you can use
| if forceColor { | |
| color.NoColor = false | |
| } | |
| switch colorMode { | |
| case "always": | |
| color.NoColor = false | |
| case "never": | |
| color.NoColor = true | |
| case "auto", "": | |
| // do nothing | |
| default: | |
| log.Fatal("unsupported color mode: use always, never, auto") | |
| } |
Add a flag to force colored output, closes #417