Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@eletrolitico
Copy link

Add a flag to force colored output, closes #417

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")
Copy link
Contributor

@ccoVeille ccoVeille May 1, 2025

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

Suggested change
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.

Copy link
Author

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
Comment on lines 87 to 89
if forceColor {
color.NoColor = false
}
Copy link
Contributor

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

Suggested change
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")
}

@eletrolitico eletrolitico requested a review from ccoVeille May 2, 2025 18:26
@eletrolitico eletrolitico changed the title feat: add colored flag feat: add color flag May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support forcing color

2 participants