Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

commander.js: passing isDefault option for command with action()

As per the commander.js readme, I can specify the default command thus:

var program = ...;

program
  ...
  .command('list', 'list packages installed', {isDefault: true})
  .parse(process.argv);

In my application, I'm using the .command() without the description parameter, for using .action(). I tried passing the second param null and the third option with the isDefault:true. But it does not seem to work:

program.command('help', null, {isDefault:true})
  .description('display help information.')
  .action(function(){
    program.outputHelp();
  });

How do I pass isDefault:true to a command with .action()?

like image 615
Subhash Chandran Avatar asked Nov 08 '22 16:11

Subhash Chandran


1 Answers

according to the documentation:

When .command() is invoked with a description argument, no .action(callback) should be called to handle sub-commands, otherwise there will be an error.

I believe this means that you will need to find a workaround, such as writing a separate subcommand.

like image 198
efong5 Avatar answered Nov 14 '22 21:11

efong5