admin管理员组

文章数量:1356560

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

本文标签: javascriptNested commands with commanderStack Overflow