Class inheritance does not extend all functionality
Is there an existing issue for this?
- [X] I have searched the existing issues
Current behavior
If you want to have a "parent command class" for global options, a common logging config, shared functions or constructor behaviour, it does not work as expected. Basic class functionality works, i.e. if you create a protected logger instance, that works, and shared functions work as expected, but trying to create an @Options definition that would be "global" among Commands that inherit this class does not work.
Minimum reproduction code
base-command.ts:
import { CommandRunner } from 'nest-commander';
import { InjectPinoLogger, PinoLogger } from 'nestjs-pino';
export abstract class BaseCommand extends CommandRunner {
@InjectPinoLogger()
protected readonly logger: PinoLogger;
@Option({
flags: '-c, --common <common>',
description: 'A common flag',
})
parseCommon(val: string) {
return val;
}
}
test-command.ts:
import { Command, Option } from 'nest-commander';
import { BaseCommand } from './base-command';
@Command({
name: 'test',
})
export class TestCommand extends BaseCommand {
async run(inputs: string[], options: Record<string, any>): Promise<void> {
this.logger.info(options, 'Options');
}
}
Expected behavior
When running this code with the --common=something flag set, I would expect to see {'common': 'something'} in the logged options, but instead, the logged object is empty.
Package
- [x]
nest-commander - [ ]
nest-commander-schematics - [ ]
nest-commander-testing
Package version
3.7.1
Node.js version
18.16.0
In which operating systems have you tested?
- [ ] macOS
- [ ] Windows
- [X] Linux
Other
No response
I believe this most likely has to do with my use of @golevelup/nestjs-discovery and how it discovers metadata of each class. I'll see if I can reproduce the functionality away from nest-commander and report it to that library, or adjust my use if necessary
@jmcdo29 any ideas how to do it ?
Hmm, I was not able to reproduce this functionality in an e2e test I created for this issue. Can someone provide me a minimum reproduction