5

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()?

1

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.