parser icon indicating copy to clipboard operation
parser copied to clipboard

How to pass flag type to base class

Open ktalebian opened this issue 4 years ago • 1 comments

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
  }
}

ktalebian avatar Jun 16 '20 00:06 ktalebian

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.

RasPhilCo avatar Jul 03 '20 01:07 RasPhilCo