Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I access command help inside command itself? #360

Closed
Souvikns opened this issue Feb 1, 2022 · 3 comments
Closed

How do I access command help inside command itself? #360

Souvikns opened this issue Feb 1, 2022 · 3 comments

Comments

@Souvikns
Copy link

Souvikns commented Feb 1, 2022

I want to print the command level help when the command is run, I used to do something like this in the old version

import { flags} from '@oclif/command';
import Command from '../base';

export class Config extends Command {
  static description = 'access configs'
  static flags = {
    help: flags.help({char: 'h'})
  }

  async run() {
    await this._help();
  }
}

In the new version, I don't think there is this._help() function.

How can I get the same functionality in the new version?

@Pavek
Copy link

Pavek commented Feb 10, 2022

I found this solution that works for me:

async run() {
      await this.config.runCommand("help", [this.id]);
}

From here: https://github.com/oclif/core/blob/main/src/main.ts#L67

@Souvikns
Copy link
Author

@Pavek what I was trying to do was a bit different but thanks to you I figured it out. Firstly I did not have a help command which is because I am not using the help plugin so this does not work but I did something like this and now it works.

    async run(){
        const Help = await loadHelpClass(this.config);
        const help = new Help(this.config)
        help.showHelp(['start', '--help'])
    }

@Pavek
Copy link

Pavek commented Feb 17, 2022

@Souvikns Glad it was helpful. You may also get rid of loadHelpClass as w/o Custom Help it's not very useful:

return Help

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

No branches or pull requests

3 participants