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

Completed nested command support. #245

Closed
wants to merge 1 commit into from

Conversation

nowells
Copy link

@nowells nowells commented Aug 27, 2014

Nested command support was almost completely available, however, a few things
seemed to be missing to me.

  • this context on action event listeners was not bound properly.
  • We output help too early, the deepest referenced command should handle help.
  • We did not have action handling logic to delegate to subcommands if they existed.

This should address #226, and #1. Pretty much all of the support was already there, and it seemed useful to just connect the wires. I know that #63 referenced using the git subcommand model, which I love and use frequently, but there are several use cases (creating a command framework that loads external "plugin" module commands into the parent executable) that would be more easily expressed with this simple fix to connect the wires for sub-commands.

@nowells nowells force-pushed the wireup-nested-commands branch 2 times, most recently from c05a6c4 to 98d8154 Compare August 27, 2014 21:13
@thethomaseffect
Copy link
Collaborator

Cool, thanks for the work! I can't test this right now as I'm away but if someone could test this out it'd be fantastic and we can get it merged.

@nowells
Copy link
Author

nowells commented Sep 2, 2014

@thethomaseffect thanks! Let me know if there is anything I can do to help, or if you need me to fix/change the approach I have taken.

process.exit = function() { exceptionOccurred = true; throw new Error(); };
console.error = function() {};

try {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose for these try/catch blocks? These are tests, we'd want all exceptions to bubble up.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was cribbing from https://github.com/visionmedia/commander.js/blob/master/test/test.options.commands.js#L103. Basically, we hijack process.exit(x) and have it throw an error (which help calls process.exit(0)) https://github.com/visionmedia/commander.js/pull/245/files#diff-48e1e0644a9c6aeb3fee25b9561b1692R60 We are OK with having the program exit (that is what help is supposed to do) but we want to assert that it was actually called (we add a on('help') above that sets the variable if help is called.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, thanks

@nowells
Copy link
Author

nowells commented Sep 15, 2014

@SomeKittens have you run into any issues while testing/reviewing this code? No pressure, just want to see if there is anything I can do to help!

Nested command support was almost completely available, however, a few things
seemed to be missing to me.

* `this` context on `action` event listeners was not bound properly.
* We output `help` too early, the deepest referenced command should handle help.
@insidewhy
Copy link

My first day with node-commander and I've already hit issues solved by this PR. Would be so good if someone could look at this but there seems to be many neglected PRs :(

@SomeKittens
Copy link
Collaborator

@ohjames We can't merge this - there's a bunch of conflicts...

@jakiestfu
Copy link

@ohjames bump

@insidewhy
Copy link

Don't have the time to help out with this, found another library that supports it.

@jakiestfu
Copy link

@ohjames Which library?

@insidewhy
Copy link

@jakiestfu it's been added to yargs with the next flag and will be officially released within a few days.

@apla
Copy link

apla commented Aug 18, 2015

@jakiestfu also just released https://github.com/apla/commop

@insidewhy
Copy link

@apla thanks for the update, I'm your first star! Hoping you've finally made the holy grail of node.js cmd line argument parsers.

@boutell
Copy link

boutell commented Dec 2, 2017

Did this feature (nested commands) ever happen?

@insidewhy
Copy link

@boutell nope I've been using yargs for the past few years instead. It's pretty good.

@nowells
Copy link
Author

nowells commented Dec 5, 2017

I also switched to yargs a while ago (when this support was not added) and have been very happy with it. I will close this as it will likely no longer be a valid fix.

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

Successfully merging this pull request may close these issues.

None yet

7 participants