简体   繁体   中英

Short help and long help in commander

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, eg

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
#
# ...

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, eg

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM