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

Add method to get help option description #1370

Closed
Melissa0x1f992 opened this issue Oct 11, 2020 · 3 comments
Closed

Add method to get help option description #1370

Melissa0x1f992 opened this issue Oct 11, 2020 · 3 comments
Milestone

Comments

@Melissa0x1f992
Copy link

Something like helpDescription()? And maybe when someone uses helpOption(..., 'custom description'), subsequent calls will return the new description?

Context: I'm using helpOption(false) to disable the implicit help because I have a non-console help output, and I'd rather not display help redundantly on the console. I use helpInformation() to get the help string in the action of my own '-h, --help' option. I'd like my help description to match commander's default help option description. My current options are just to hardcode a copy of your string, or access the _helpDescription field. I've opted for the former for now, but I'd rather not have a random copy of data when the intent was to refer to the already-existing data.

@Melissa0x1f992 Melissa0x1f992 changed the title Add method to get default help option description Add method to get help option description Oct 11, 2020
@shadowspawn
Copy link
Collaborator

Best approach currently is a copy of the string, as you have done.

There is a big refactor of the help in progress in #1365, but it does not provide access to the default descriptions.

Will be interesting to see if this gets upvotes, now helpOption(false) is possible. I don't think I would add access to the default help option description alone as this string is one of many: could also want help option flags, help command description, version option flags, version option description...

Melissa0x1f992 added a commit to Melissa0x1f992/commander.js that referenced this issue Oct 13, 2020
stdout isn't available to my user.  I have a custom method of displaying text output to the user.  I still want to make use of the full Commander help suite.  Disabling the built-in help commands and writing wrappers becomes an increasingly complicated task when you want to make use of the entire help suite.  This PR will solve that problem by removing the assumption that all output is to `process.stdout`.  A user can instead pass a writeable stream that will replace the default stdout stream.  In this way, anyone can output command results in any way that works for their use case by defining their own writeable stream.

This is a more elegant solution to the problem in tj#1370.  Instead of using `helpOption(false)` and writing my own help option, I can use Commander's help option, and handle the output with my own writeable stream.  This is a less invasive solution than tj#779, as it leaves the implementation of the writeable stream to the user.

Suggested changelog: "allow overriding the output from default (`process.stdout`) to any `stream.Writeable`"

Things to note:
* I've intentionally not updated the README or the examples/, as this is a WIP PR, and I'd like to know if this idea will be accepted before documenting it that far.
* This adds a dependency on `stream.Writeable`, but that's built into Node, so I think that's fine
* `process.stdout` is a `stream.Writeable`, but it's also a `tty.WriteStream`.  Only the latter has the `.columns` field in its API.  All of Commander's uses of that field are protected by a default if `.columns` is Falsey.  So for that reason I've kept it simple with the understanding that if someone wants a non-default column width in their custom stream, they can specify that field themself.  An alternative would be to create a type that's just a `stream.Writeable` + `.columns`.  I think this alternative adds unneeded complexity, so I didn't go for it.  However, it has the pro of not relying on the existing `.columns || 80` in the code to prevent undefined behavior.
@shadowspawn shadowspawn mentioned this issue Oct 31, 2020
5 tasks
@shadowspawn
Copy link
Collaborator

Improving support for non-console help output in #1387

@shadowspawn shadowspawn added this to the v7.0.0 milestone Nov 17, 2020
@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Nov 17, 2020
@shadowspawn
Copy link
Collaborator

Improved support for redirected output in Commander 7.0.0.

@shadowspawn shadowspawn removed the pending release Merged into a branch for a future release, but not released yet label Jan 15, 2021
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

No branches or pull requests

2 participants