-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
bugCommander is not working as intendedCommander is not working as intended
Milestone
Description
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:
cli/
hello
hello-world # `hello world`
hello-world-germany # `hello world germany`
And I'm trying to run them like so:
$ node cli/hello
# Should run cli/hello
$ node cli/hello world
# Should run cli/hello-world
$ node cli/hello world germany
# Should run cli/hello-world-germany
I've read that when defining nested subcommands, you need to specify the executableFile
, so I've done this in cli/hello
:
#!/usr/bin/env node
const { program, Command } = require("commander");
const packageJSON = require("../package.json");
program.version(packageJSON.version);
const helloWorld = new Command("world");
helloWorld.command("germany", "Saying hello to Germany", {
executableFile: "hello-world-germany",
});
program.addCommand(helloWorld);
program.parse(process.argv);
However, when I run node cli/hello world germany
, I get a TypeError:
~/Desktop/commander-debug $ node cli/hello world germany
internal/validators.js:120
throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
^
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received null
at validateString (internal/validators.js:120:11)
at Object.extname (path.js:1229:5)
at Command._executeSubCommand (/Users/max/Desktop/commander-debug/node_modules/commander/index.js:774:46)
at Command._dispatchSubcommand (/Users/max/Desktop/commander-debug/node_modules/commander/index.js:863:12)
at Command._parseCommand (/Users/max/Desktop/commander-debug/node_modules/commander/index.js:882:12)
at Command._dispatchSubcommand (/Users/max/Desktop/commander-debug/node_modules/commander/index.js:865:18)
at Command._parseCommand (/Users/max/Desktop/commander-debug/node_modules/commander/index.js:882:12)
at Command.parse (/Users/max/Desktop/commander-debug/node_modules/commander/index.js:717:10)
at Object.<anonymous> (/Users/max/Desktop/commander-debug/cli/hello:14:9)
at Module._compile (internal/modules/cjs/loader.js:1138:30) {
code: 'ERR_INVALID_ARG_TYPE'
}
Is this a bug or am I doing something wrong?
Thanks for your help!
Metadata
Metadata
Assignees
Labels
bugCommander is not working as intendedCommander is not working as intended