0

Suppose I have a file "test.js":

var args = require('yargs')
        .command('command', 'command usage here', {alias: "c"} )
        .argv;

Then I run:

>node test command

I got this error:

second argument to option must be an object

If I remove the 3rd parameter of .command:

 var args = require('yargs')
            .command('command', 'command usage here')
            .argv;

Everything is fine.

I must make a dumb mistake. But I just cannot figure it out.

Thanks

derek
  • 9,358
  • 11
  • 53
  • 94

1 Answers1

0

Your 3rd argument is not required, that's why it works when you remove it. I'm pretty sure the 3rd argument has to be a function call.

var args = require('yargs')
       .command('command',
                'command explanation', 
                 function(yargs){
                     //insert yargs.options here
                     yargs.options({
                         c:{
                             demand: true,//if you require the command
                             alias: 'c',// you will enter -c to use it
                             description: 'explain what it does'
                           }    
                 });
                 })
                 .argv;

an example of usage might be:

C:\WorkingDirectory>node app.js command -c run

your code could include console.log(args.c);//prints out run

James Zaghini
  • 3,895
  • 4
  • 45
  • 61
laukCoder
  • 61
  • 6