0

我有以下代码

export const program = new Command();

program.version('0.0.1');

program
  .command('groups')
  .command('create')
  .action(() => console.log('creating'))
  .command('delete')
  .action(() => console.log('deleting-all'))

program.parse(process.argv)

我想要实现的是

groups creategroups delete

但是,将删除的代码链接到创建。它识别groups creategroups create delete(我不想要)但不识别groups delete

4

1 回答 1

1

您想将子命令添加deletegroups命令中。例如

const { Command } = require('commander');

const program = new Command();

program.version('0.0.1');

const groups = program
  .command('groups');
groups
  .command('create')
  .action(() => console.log('creating'))
groups
  .command('delete')
  .action(() => console.log('deleting-all'))

program.parse(process.argv)

相关示例文件为:https ://github.com/tj/commander.js/blob/master/examples/nestedCommands.js

于 2021-02-21T01:02:48.360 回答