parser
parser copied to clipboard
How to pass flag type to base class
This is mostly a Typescript question more than anything else with OClif itself. I want to create a BaseCommand and define some additional parameters. One such is a getter for flags
. I cannot figure out how to set the type of it though so it's dynamic based on whatever the implemented class is:
export abstract class BaseCommand extends Command {
protected flags: WhatToPutHere;
async run() {
this.flags = this.parse(this.constructor).flags;
}
}
class MyCommand extends BaseCommand {
static flags = {
version: flags.string()
}
async run() {
// I want to access this.flags.version
}
}
See base class parsing in an init
function here: https://oclif.io/docs/base_class. But as you have it you need to call super.run()
inside of MyCommand#run
.