Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

How to pass flag type to base class #80

Open
ktalebian opened this issue Jun 16, 2020 · 1 comment
Open

How to pass flag type to base class #80

ktalebian opened this issue Jun 16, 2020 · 1 comment

Comments

@ktalebian
Copy link

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
  }
}
@RasPhilCo
Copy link
Contributor

RasPhilCo commented Jul 3, 2020

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants