Issue
Following the nestjs-commander docs I have this command:
import { Command, CommandRunner, Option } from 'nest-commander';
@Command({
name: 'my-command',
})
export class MyCommand extends CommandRunner {
async run(inputs: string[], options: Record<string, any>): Promise<void> {
console.log(options); // This is an empty object
}
@Option({
flags: '-l, --limit <limit>',
description: 'Limit option',
})
parseLimit(val: string) {
return Number(val);
}
}
And this is my main-cli.ts file:
import { AppModule } from "./app.module";
import { CommandFactory } from "nest-commander";
async function bootstrap() {
await CommandFactory.run(AppModule, ["log"]);
}
bootstrap();
And I have added "console:dev": "ts-node -r tsconfig-paths/register src/main-cli.ts"
to my package.json but when I run the command with npm run console:dev my-command --limit=10
the command runs normally but I don't get the limit
value in the run
method.
Any idea why the options are not passed to the command?
Solution
I had the same problem, but it was a problem with how the npm works.
Try this:
npm run console:dev my-command -- --limit=10
Reference
Answered By - Terry
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.