-
-
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
TypeError when running nested subcommand #1274
Comments
You have uncovered a bug, but I think your program isn't working the way you intend either and fixing that will avoid the bug. The error message is due to a bug when a sub-sub-command implemented as a stand-alone executable is added. The internal For implementing nested subcommands, you can either do it within a single program (from Commander v5), or using stand-alone executables. Your program is a bit of both. Would you like some help towards doing it within a single program, or as multiple stand-alone subcommands? (Or both approaches because you are exploring!) The example file for nested subcommands within a single program is: https://github.com/tj/commander.js/blob/master/examples/nestedCommands.js The example file for stand-alone executable subcommands just has one layer, but the subcommands can add subcommands...: https://github.com/tj/commander.js/blob/master/examples/pm |
Hey @shadowspawn, thanks for the quick and helpful reply! You pointed me in the right direction and I've got the following program now working :) cli/hello #!/usr/bin/env node
const { program, Command } = require("commander");
const packageJSON = require("../package.json");
program.version(packageJSON.version);
program.command("world", "Saying hello world");
program.action(() => {
console.log("hello");
});
program.parse(process.argv); cli/hello-world #!/usr/bin/env node
const { program, Command } = require("commander");
const packageJSON = require("../package.json");
program.version(packageJSON.version);
program.command("germany", "Saying hello to Germany");
program.action(() => {
console.log("Hello world");
});
program.parse(process.argv); cli/hello-world-germany #!/usr/bin/env node
const { program } = require("commander");
const packageJSON = require("../package.json");
program.version(packageJSON.version);
program.action(() => {
console.log("Hello world germany");
});
program.parse(process.argv); ...and when I run the programs I get the expected output :)
Thank you! 🥳 |
Released in Commander v6.1 |
Repo with minimal example code to reproduce: https://github.com/maximilianschmitt/commander-debug
Hi!
I'm currently developing a CLI where I'm wanting to nest the subcommands.
I have the following files:
And I'm trying to run them like so:
I've read that when defining nested subcommands, you need to specify the
executableFile
, so I've done this incli/hello
:However, when I run
node cli/hello world germany
, I get a TypeError:Is this a bug or am I doing something wrong?
Thanks for your help!
The text was updated successfully, but these errors were encountered: