-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Enhance Option class to allow hiding help, specifying choices, and change how default value displayed in help #1331
Enhance Option class to allow hiding help, specifying choices, and change how default value displayed in help #1331
Conversation
This looks awesome! I'm not seeing any tests for things being chained together - what is the expected behavior if we provide defaults and hide the help like in the following? program
.addOption(new Option('-t, --timeout').hideHelp().default(60, 'one minute')); It seems to me like anything not shown in help should require a default value - should that require Also, I realize that I was part of the impetus for this PR and I explicitly asked for a way to hide options, but should there be some way to toggle exposure of the hidden options. Something like giving every program a Thanks so much for all of your work on this and I'm sorry that I'm constantly poking holes in things to see if they pop! |
Thanks @Tbhesswebber . No popping noises yet. 🎈
These calls chain (like when configuring Command), so in your example the option will have a default value and be hidden.
Why is it different to a non-hidden option? If I don't look in the help, then I may not know what other options exists or whether they have a default value.
You can arrange for this yourself by passing false into hideHelp. Say by testing an environment variable to see whether to show everything. |
Fantastic! I think I just naturally think of all things having defaults within a CLI in order to avoid having to handle multiple ways of tracking values (with the exception of anything that is provided by a config file), so you can ignore that point of mine! Again, I really appreciate your efforts here! |
I made a bunch of tidies since review comment. (A couple related to previous PR, sorry! 😊 )
|
|
Fixed. |
I revisited this today. I was worried "deprecated" meant "we will delete this" and was too strong. But deprecated also can mean "this was a bad idea" or "there is a better way now". I'll go back to calling things deprecated instead of legacy, it is the right word for the functionality we would like people to stop using and is supported with the So I'll make some wording changes but not logic changes, again! Sorry for the churn, but I am pleased to get this sorted out in my mind. I have been wondering how best to talk about old code for a while. 🤔 💡 |
Done. Back to "deprecated"! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome!
Thanks for review @abetomo , it was a big one! 🎉 |
Pull Request
There are various requests for additional behaviours for options that are hard to add to the existing Command interface. This is an experiment to see whether turning Option into a richer class will allow adding new features in a tidy way by working directly with the option, rather than indirectly from the command.
Problem
Solution
Enhance Option with support for configuring custom behaviours. Add a created Option to command with
.addOption()
.Use like:
ChangeLog