Skip to content

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

Closed

Description

@Souvikns

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?

Activity

  1. Pavek commented on Feb 10, 2022

    @Pavek

    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

  2. Souvikns commented on Feb 10, 2022

    @Souvikns
    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'])
        }
    
  3. Pavek commented on Feb 17, 2022

    @Pavek

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions