Adding Sub commands don't seem to work
gr0wth-b0t opened this issue · 2 comments
Is there an existing issue for this?
- I have searched the existing issues
Current behavior
Defining sub commands is not working. only parent command is being called
Minimum reproduction code
Going with the example provided in the docs, tried to create a commander cli application using this repo, with the following code:
@SubCommand({ name: 'foo', arguments: '[phooey]' })
export class FooCommand implements CommandRunner {
async run(
inputs: string[],
options: Record<string, string>
): Promise<void> {
console.log('inside FooCommand class!');
}
}
@Command({
name: 'run',
arguments: '<task>',
subCommands: [FooCommand]
})
export class RunCommand implements CommandRunner {
async run(
inputs: string[],
options: Record<string, string>
): Promise<void> {
console.log('inside RunCommand class!');
}
}
The only difference is that I had to implement the run
command in the RunCommand
class because it's required by the CommandRunner
interface.
Right now, when I run the application with either:
npx ts-node ./src/bootstrap.ts run
npx ts-node ./src/bootstrap.ts run foo
npx ts-node ./src/bootstrap.ts run foo test
I get only theinside RunCommand class!
printed.
Expected behavior
Extected to print inside FooCommand class!
to the console since the sub command run function should be called.
Package
-
nest-commander
-
nest-commander-schematics
-
nest-commander-testing
Package version
2.4.0
Node.js version
14.18.1
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
No response
Not sure why @gr0wth-b0t closed this, but I am facing a similar issue
Not sure why @gr0wth-b0t closed this, but I am facing a similar issue
@simplenotezy not sure if you resolved this issue. For me it was simply that I was missing the subcommands in CLI module's provider array. I opened a PR to supplement the docs with this detail: