-
-
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
add opts() for getting key-value pairs #262
Conversation
opts sounds good to me. @thethomaseffect Look good? |
Looks great, will also unblock anyone who wanted to use the names of JS internals like |
add opts() for getting key-value pairs of options
@thethomaseffect any plans for a 2.4.0 or 2.3.1 release? I didn't see any obvious documentation or milestones set up and I was wondering when this would be in an official version. |
Hopefully in the next few days, want to update the documentation first and do some manual testing of a few new features and then should push out the new version! |
@tonylukasavage was it a deliberate decision for
The first log has the default, the second one not. |
You didn't parse()
|
Same result (probably copy pasted it wrong):
|
A common usage pattern I have when using commander is to process the CLI in a bin file and defer all actual program-specific execution to a separate module. I often pass all options gathered from commander straight my module, like this:
While this works, it would be nice if the object passed through included only the options I specified when setting up the program object.
This PR add the
opts()
function to the program object (viaCommand.prototype
) so as to return the options, with special handling for the version, as a simple object of key-value pairs. No parsing Option objects, no additional properties associated with the program obejcts, I can then do the following in my above example to get the desired behavior.The included test case also demonstrates this fairly simply.
NOTE: I am entirely open to changing the name of the API.
opts()
was the first thing to occur to me that wasn't already claimed on theCommand
object. If someone has a better alternative I'd be happy to update the code and testing.