You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Node.js Commander中带参数的命令配置Help选项

解决Commander.js子命令add-repository的--help显示问题

你不需要手动给子命令添加-h,--help选项,Commander.js会自动为所有子命令内置--help(含短选项-h),手动添加反而会干扰默认的帮助触发逻辑。

把代码里的.option('-h,--help','help add-repository command')这一行删掉,保留如下代码即可:

program
  .command('add-repository <repo-name>')
  .description('configure your repository to do the repository specific tasks')
  .action(addRepoCommandHandler);

修改后,执行add-repository --help或者add-repository -h,就能正常显示该子命令的帮助文本,包含命令描述、必填参数<repo-name>的说明等内容。

内容的提问来源于stack exchange,提问作者Amit Limbasiya

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 17:15:52