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

support for colored commands in help output #1699

Open
NewFuture opened this issue Jul 22, 2020 · 3 comments
Open

support for colored commands in help output #1699

NewFuture opened this issue Jul 22, 2020 · 3 comments

Comments

@NewFuture
Copy link

NewFuture commented Jul 22, 2020

const colors = require("ansi-colors");
require("yargs")
  .command(colors.red('test'),"just test")
  .strict()

when run my-cmd test, it works with v15.3.1;

but it breaks in v15.4.1, because test is not matched with colors.red('test')

@bcoe
Copy link
Member

bcoe commented Jul 22, 2020

@NewFuture It was unintended behavior that colors.red('test') ever matched the string "test"... as colors.red() adds ansi escape codes, meaning the string is actually something like \u001b[31mtest.

I'm honestly not sure that this feature is something we're interested in making an effort to support, it would complicate the internal representation of the command, and we'd need to make an active effort to strip color codes wherever we perform a comparison.

@NewFuture
Copy link
Author

Thanks, @bcoe.
I mostly agree with you. but it worked in the early versions (a hidden breaking change?)

In addition, this behavior is a greate feature to create colorful commands.

@bcoe bcoe changed the title colors bug in v15.4.1 support for colored commands in help output Jul 28, 2020
@bcoe
Copy link
Member

bcoe commented Jul 28, 2020

@NewFuture happy to keep this open as a feature request. But, I think support would have always been somewhat broken, since there are a variety of places in the codebase where we perform a string comparison to check for command name.

tldr; even though this behavior might have changed at some point, I don't think it's worthwhile taking a new major version for yargs, or to make an effort to revert the change that was the culprit.

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