-
-
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
executeSubCommand() shouldn't be called if I provide action #706
Comments
Having same issue here. Did workaround by doing this: commander.executeSubCommand = () => false;
commander.parse(process.argv); Either this behavior should be documented or removed. |
This happens for me when I provide a description as part of the command call. Despite the presence of the action handler, commander tries to find a file to execute. const program = require('commander')
const action = require('./some-action-handler')
program
.command('blah', 'do some stuff')
.action(action) But things act as expected when I instead separate the description into a use of const program = require('commander')
const action = require('./some-action-handler')
program
.command('blah')
.description('do some stuff')
.action(action) That's pretty goofy. The docs seem to suggest that the presence of the action handler is the key to disabling this behavior, but this behavior seems to say otherwise. After a brief glimpse into the source, I'd point a finger at this: https://github.com/pandapaul/commander.js/blob/master/index.js#L178-L183 Just noticed this other issue pointing to the same problem: #715 And this, which is sort of the other side of the same coin: #633 |
I can confirm this happening on 2.14.1 as well in Windows. @maxpert 's fix does act as a work around if you don't need subcommand at all. Strangely, it fails finding the file even when it exists as well. |
Adding a description to the |
Recategorising this as a bug and adding to v3 milestone to have a go at changing the behaviour in a breaking version. |
Had a look into this, and not going to attempt it in v3 after all. An insight though: the git-style executable (with description) returns the program for chaining; the action-style subcommand (without description) returns the new command for chaining. |
This issue will be resolved when v3.0.0 is released. Available now as a prerelease. See #1001 Reworked the README and JSDoc and TypeScript to hopefully make the two modes of operation clearer. Have not changed the runtime, but will close this issue and see how the changes help. |
Reworked the README and JSDoc and TypeScript to hopefully make the two modes of operation clearer. Have not changed the runtime, but will close this issue and see how the changes help. Shipped in v3: https://github.com/tj/commander.js/releases/tag/v3.0.0 |
Disclaimer: I'm new to Commander, maybe I'm missing something.
I'm trying this very simple example:
I'd assume that my
action()
callback is what represents the command, however, it seems that Commander is also trying to execute the module calledindex-example
:I thought this is a bug but after inspecting the source code, maybe this is intentional?
I can create
index-example.js
as a workaround but it's not ideal:node index.js example
) as calling justnode index example
will throw errorENOENT: no such file or directory, lstat '...\index'
.ts-node
(Node + TypeScript) as the source code of Commander assumes.js
file extensions. I'm gettingCannot find module 'index.ts-example'
error and the workaround is a file namedvpmake.ts-example.js
; that looks quite weird.The text was updated successfully, but these errors were encountered: