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?
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
Thank you for your quick response, I don’t know that, I’ll try it out :)
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.)
Commander v5.0.0 has been released with additional error output to make it easier to recognise and correct this issue.
Most helpful comment
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:See https://github.com/tj/commander.js#commands for examples