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

Open
yedayak opened this issue Aug 27, 2024 · 0 comments
Open

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

yedayak opened this issue Aug 27, 2024 · 0 comments

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.

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

No branches or pull requests

2 participants