Skip to content

Customize help message for a command #1023

@RonWang

Description

@RonWang

Our goal: customize the help message for the root command.

Existing solution won't help, because we need to append the message on top of auto-gen help, and also modify the auto-gen help a little bit.

Context for our cmd app: below is the root cmd, and we have a sub-cmd under the root as well as a git-style-sub-command.

commander
    .description('')
    .command('sub-cmd')
    .command('git-style-sub-cmd')
    .version(require('../package.json').version)
    .option('-h, --help', 'output help message', () => {
        console.log('custom help msg');
    })
    .parse(process.argv);

In the example I tried using option('-h, --help'), the console.log works for me with my demanded help output. But when I try sub-cmd and git-style-sub-cmd, the help message for the root command is always coming along when I type "cmd sub-cmd --help" and "cmd git-style-sub-cmd --help".

I noticed #242 , where @shadowspawn mentioned it won't be supported. Reopen it as it'd be an important feature for us.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions