-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Handle the --color flag via proper global state #6743
Conversation
Use `color.NoColor` as a global progressively modified as one descends down command flags. Allows non-surprising operation when --color is accepted at multiple layers, and even makes this behave predictably: lotus-miner --color actor control list --color=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.
LGTM but see the comment about GOLOG_OUTPUT
// Set the global default, to be overridden by individual cli flags in order | ||
func init() { | ||
color.NoColor = os.Getenv("GOLOG_LOG_FMT") != "color" && | ||
!isatty.IsTerminal(os.Stdout.Fd()) && |
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.
Strictly I think you should check GOLOG_OUTPUT
to see if logging is being redirected to stderr
here
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.
Urgh... that's a bit of a can of worms...
Perhaps we should just make this a public method and inspect the result?
https://github.com/ipfs/go-log/blob/5b4daa4491c2cc9e0ba85ce4b5fcc913f6fcdf6b/setup.go#L274-L377
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.
Sensible suggestion to avoid duplicating that logic
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.
Need to think about this more, that'll have to come via another PR
Use
color.NoColor
as a global progressively modified as one descendsdown command flags. Allows non-surprising operation when --color is
accepted at multiple layers, and even makes this behave predictably:
Thanks to @stuberman for poking me about the current state being non-ideal, and to @iand for prompting me to reexamine how we do things
P.S. GNU-getopt 4EVAH‼️