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

Make mimirtool not use color when pointed to non-tty output #9119

Closed
yedayak opened this issue Aug 27, 2024 · 2 comments · Fixed by #9423
Closed

Make mimirtool not use color when pointed to non-tty output #9119

yedayak opened this issue Aug 27, 2024 · 2 comments · Fixed by #9423

Comments

@yedayak
Copy link

yedayak commented Aug 27, 2024

Is your feature request related to a problem? Please describe.

Currently when running for example mimirtool rules print | less or mimirtool rules print > rules.yaml, it outputs ansi color codes, which show up in the output and make the yaml not valid. This happens always, unless you use the --disable-color option. Using the --disable-color works ok if you know about it already and for scripts, but anyone using the tool interactively has to remember to use it when piping to a pager or a parser like yq.

Describe the solution you'd like

Detect when the output is redirected to anything other than a terminal, and don't print color codes in those cases.

Describe alternatives you've considered

Additional context

Detecting if printing to a tty is a common pattern with other CLI tools, for example jq or tree. Having the default option being auto, and than allowing forcing color or disabling it is reasonable solution IMO.

@jadolg
Copy link
Contributor

jadolg commented Sep 25, 2024

Would this require adding another flag (--force-color) to override the setting when the output is not a terminal but we still want colors for some reason? Which flag would take precedence if they are both specified?
Is that the desirable outcome or just removing colors would be enough?

@yedayak
Copy link
Author

yedayak commented Sep 25, 2024

Would this require adding another flag (--force-color) to override the setting when the output is not a terminal but we still want colors for some reason? Which flag would take precedence if they are both specified? Is that the desirable outcome or just removing colors would be enough?

I think adding a flag to output color anyway is useful, for example to allow piping to less -R which will show the colors.
I'm not sure about the naming though. Precedence should probably take the last specified option?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants