javascript - Nested commands with commander - Stack Overflow

I have the following codeexport const program = new Command();program.version('0.0.1');progr

I have the following code

export const program = new Command();

program.version('0.0.1');

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

program.parse(process.argv)

What I want to achieve is something like

groups create and groups delete

The code however chains that delete to the create. It recognizes groups create and groups create delete (which I dont want) but does not recognize the groups delete

I have the following code

export const program = new Command();

program.version('0.0.1');

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

program.parse(process.argv)

What I want to achieve is something like

groups create and groups delete

The code however chains that delete to the create. It recognizes groups create and groups create delete (which I dont want) but does not recognize the groups delete

Share Improve this question asked Feb 20, 2021 at 15:43 AngularDebutantAngularDebutant 1,5866 gold badges26 silver badges49 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

You want to add the delete submand to the groups mand. e.g.

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

const program = new Command();

program.version('0.0.1');

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

program.parse(process.argv)

The related example file is: https://github./tj/mander.js/blob/master/examples/nestedCommands.js

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744057146a4551113.html

相关推荐

  • javascript - Nested commands with commander - Stack Overflow

    I have the following codeexport const program = new Command();program.version('0.0.1');progr

    10天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信