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

Error: command does not exist #1154

Closed
hossamelmansy opened this issue Jan 22, 2020 · 4 comments
Closed

Error: command does not exist #1154

hossamelmansy opened this issue Jan 22, 2020 · 4 comments
Milestone

Comments

@hossamelmansy
Copy link

hossamelmansy commented Jan 22, 2020

const program = require("commander");

program.version("0.0.1");
program.description("Webotron deploys websites to AWS");

program
  .command("list-buckets", "List all S3 buckets")
  .action(function() {
    console.log("list-buckets");
  })
  .parse(process.argv);

why this code snippet throws that error, this is the output when running the command:

››› node 01-webotron/webotron.js list-buckets                                                                                      
list-buckets
error: webotron-list-buckets(1) does not exist, try --help

OS: macOS
nodeJS version: v13.6.0
commander: "^4.1.0"

am I doing something wrong?

@shadowspawn
Copy link
Collaborator

For historical reasons, .command() for an action handler has the description separately. When the description is included Commander assumes you have an executable subcommand. You want:

program
  .command("list-buckets")
  .description("List all S3 buckets")

See https://github.com/tj/commander.js#commands for examples

@hossamelmansy
Copy link
Author

Thank you for your quick response, I don’t know that, I’ll try it out :)

@shadowspawn
Copy link
Collaborator

On a related note, I have changed the "error" to a "throw" in #1165 with some additional tips to hopefully make it quicker for the author to recognise and resolve the problem. (This change is not in a published prerelease yet.)

@shadowspawn shadowspawn added this to the v5.0.0 milestone Feb 5, 2020
@shadowspawn
Copy link
Collaborator

Commander v5.0.0 has been released with additional error output to make it easier to recognise and correct this issue.

https://github.com/tj/commander.js/releases/tag/v5.0.0

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