与指挥官的嵌套命令
Nested commands with commander
我有以下代码
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 create
和 groups delete
然而,代码将删除链接到创建。它识别 groups create
和 groups create delete
(我不想要)但不识别 groups delete
您想将 delete
子命令添加到 groups
命令。例如
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
我有以下代码
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 create
和 groups delete
然而,代码将删除链接到创建。它识别 groups create
和 groups create delete
(我不想要)但不识别 groups delete
您想将 delete
子命令添加到 groups
命令。例如
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