2016-09-17 7 views
0

가정하자 내가 파일 "test.js"이 : 그럼yargs .command 오류 : 옵션 두 번째 인수는 객체 여야합니다

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

내가 실행을 :이 오류가 발생했습니다

>node test command 

:

second argument to option must be an object

나는 .command의 세번째 매개 변수를 제거하는 경우 :

모두 괜찮습니다.

나는 어리석은 실수를 저지 릅니다. 그러나 나는 그것을 알아낼 수 없다.

감사합니다.

답변

0

세 번째 인수가 필요하지 않으므로 제거 할 때 작동합니다. 세 번째 인수가 함수 호출이어야한다는 것은 확실합니다.

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; 

사용의 예는 다음과 같을 수 있습니다

C : 노드 app.js는 -c 실행 명령 \ WORKINGDIRECTORY>

코드를 포함 할 수 console.log(args.c);//prints out run

관련 문제