Short help and long help in commander

437 views Asked by At

I am using commander package as CLI parser.

   commander
      .command('command1 <parameter>' )
      .description('description 1 goes here')
      .command('command2 <parameter>' )
      .description('description 2 goes here')

Is there a way to display short descriptions when global help command is called, e.g.

myprogram help

# Commands:
#  command1 <parameter>  description 1 goes here
#  command2 <parameter>  description 2 goes here   

but also have ability to show expanded help when help for specific command is called:

myprogram help command1

# command1 is used for...
#
# ... detailed description
#
# ...
1

There are 1 answers

0
Yuriy Galanter On

Figured it out with package's author help. .description() can be used to add short inline description shown only on general help command, while .addHelpText()can include additional help test shown on command-specific help, e.g.

  commander
    .command('hello')
    .description('Shows greetings')
    .addHelpText('after', '\nGreets the world ....< long text goes here >')