smallstep / certificates

🛡️ A private certificate authority (X.509 & SSH) & ACME server for secure automated certificate management, so you can use TLS everywhere & SSO for SSH.
https://smallstep.com/certificates
Apache License 2.0
6.5k stars 423 forks source link

[Bug]: Do not output terminal control codes when output is not a terminal #1709

Open larsks opened 6 months ago

larsks commented 6 months ago

Steps to Reproduce

Try running some like:

step ca --help | less

Your Environment

Expected Behavior

I expected to see the help output from step commands displayed in a readable fashion on my screen.

Actual Behavior

This mess:

ESC[0;1;99mNAMEESC[0m
      ESC[0;1;99mstep caESC[0m -- initialize and manage a certificate authority

ESC[0;1;99mUSAGEESC[0m
      ESC[0;1;99mstep caESC[0m ESC[0;4;39mcommandESC[0m ESC[0;4;39m[options]ESC[0m ESC[0;4;39m[arguments]ESC[0m

ESC[0;1;99mDESCRIPTIONESC[0m
      ESC[0;1;99mstep caESC[0m command group provides facilities to initialize a certificate
      authority, retrieve the root of trust, sign and renew certificates, and
      create and manage provisioners.

ESC[0;1;99mOPTIONSESC[0m
      ESC[0;1;99m--helpESC[0m, ESC[0;1;99m-hESC[0m
          show help

ESC[0;1;99mEXAMPLESESC[0m
      Create the configuration for a new certificate authority:

Additional Context

This is common behavior for most programs that are able to generated formatted output on the terminal; they suppress colors/other formatting when the output isn't a tty. Compare, e.g.:

step --help | less

With:

git checkout --help | less

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

tashian commented 6 months ago

From https://clig.dev/#output :

Screenshot 2024-02-13 at 10 19 44 AM
hslatman commented 6 months ago

Related issues:

dopey commented 6 months ago

Hey @larsks 👋. Thanks for opening the issue!

I believe this is actually a duplicate of an issue we have on the smallstep/cli repo (as @hslatman referenced above), but it probably makes sense to have an issue in this repo as well.

We definitely agree that supporting --no-color would be a useful feature. We've actually run into this issue a few times ourselves. Unfortunately, after some discussion this morning we came to the realization that this is probably not a "quick fix". We are a small team and we are heavily focused on product roadmap at the moment so we cannot make any guarantees with regards to prioritization. That said, we'd be happy to accept contribution from the community - if anyone is interested in working on this, please let us know as we'd love to help brainstorm and guide the implementation.

Cheers 🍻