Skip to content
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

Merged
merged 1 commit into from
Jul 13, 2021

Conversation

ribasushi
Copy link
Collaborator

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

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

image

P.S. GNU-getopt 4EVAH‼️

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
@ribasushi ribasushi requested review from iand, mvdan and magik6k July 13, 2021 10:28
Copy link
Contributor

@iand iand left a 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()) &&
Copy link
Contributor

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

Copy link
Collaborator Author

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

Copy link
Contributor

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

Copy link
Collaborator Author

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

@magik6k magik6k merged commit dd09666 into master Jul 13, 2021
@magik6k magik6k deleted the chore/centralize_all_cli_color_handling branch July 13, 2021 15:34
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.

3 participants