3

値を取らないパラメーターを文書化してエイリアスする方法を見つけようとしていましたyargs

私がやりたいのは、へのエイリアス-c--compileあり、文書化できるようにすること--compileです。もしも--compile

script sources -c

こんな感じになると予想してた

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

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

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

ただし、呼び出す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)
4

1 に答える 1

4

を取り除きnargs('c', 1)ます。このメソッドは、キーの後に消費される引数の数を指定します。この場合は 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メソッドの詳細については、こちらを参照してください。

于 2015-03-25T04:57:54.847 に答える