2015-03-25 24 views
0

我试图找出如何记录和别名设置了一个param,它没有价值与yargsYargs记录标志

我想要做的是别名-c--compile并能够记录--compile。如果--compile

script sources -c

,我希望它是这样的

但是,调用script sources -c会产生错误

TypeError: Cannot read property 'newAliases' of undefined 
    at Object.self.help (/home/gyeates/code/lodash.modularize/node_modules/yargs/lib/usage.js:135:45) 
    at Object.self.showHelp (/home/gyeates/code/lodash.modularize/node_modules/yargs/lib/usage.js:211:29) 
    at Object.Argv.self.showHelp (/home/gyeates/code/lodash.modularize/node_modules/yargs/index.js:303:15) 
    at Object.self.fail (/home/gyeates/code/lodash.modularize/node_modules/yargs/lib/usage.js:37:39) 

回答

1

摆脱nargs('c', 1)。该方法指定了在一个键之后应该消耗的参数的数量,在这种情况下,我们不希望键取任何值。

var argv = require('yargs') 
    .usage('Usage: $0 <input> [options]') 
    .example('$0 src/**.js -c', 'Generate a build') 
    .demand(1) 

    .boolean('compile') 
    .alias('compile', ['c']) 
    .describe('compile', 'Whether to compile the results') 

    .version(function() { 
    return require('../package').version; 
    }) 
    .argv; 

yargs方法的更多信息,可以发现here

+0

谢谢,我觉得哑巴 – megawac 2015-03-25 15:58:46