Skip to content

Subcommands syntax and usage #764

Closed
Closed
@a-fas

Description

@a-fas

Hi there !

Is it possible to define subcommands in commander ?

e.g.

node script.js thecommand subcommand1 -op1 -op2
node script.js thecommand subcommand2 -op3

A particularly intended usage would be to define program.command('thecommand').action('./path/to/subcommands.js') in root index.js or other starting point and then I would have some dir with commands (path/to/subcommands), where I can then define subcommands

program
  .command('subcommand1').action(...)
  .command('subcommand2').action(...)

or maybe some kind of array with commands

module.exports = [
  { command: 'subcommand1', options: '...', action: someFn },
  { command: 'subcommand2', options: '...', action: someFn }
]

I found something promising here, but it is not documented and I cannot figure out how it works

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions