指挥官的短期帮助和长期帮助

问题描述

我使用 commander 包作为 CLI 解析器。

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

有没有办法在调用全局帮助命令时显示简短的描述,例如

myprogram help

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

但也可以在调用特定命令的帮助时显示扩展帮助:

myprogram help command1

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

解决方法

在包的作者帮助下弄清楚了。 .description() 可用于添加仅在常规 help 命令中显示的简短内联描述,而 .addHelpText() 可包含在特定命令帮助中显示的附加帮助测试,例如

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