加载中...

七、帮助信息


yargs 模块提供以下方法,生成帮助信息。

  • usage:用法格式
  • example:提供例子
  • help:显示帮助信息
  • epilog:出现在帮助信息的结尾
  1. #!/usr/bin/env node
  2. var argv = require('yargs')
  3. .option('f', {
  4. alias : 'name',
  5. demand: true,
  6. default: 'tom',
  7. describe: 'your name',
  8. type: 'string'
  9. })
  10. .usage('Usage: hello [options]')
  11. .example('hello -n tom', 'say hello to Tom')
  12. .help('h')
  13. .alias('h', 'help')
  14. .epilog('copyright 2015')
  15. .argv;
  16. console.log('hello ', argv.n);

执行结果如下。

  1. $ hello -h
  2. Usage: hello [options]
  3. Options:
  4. -f, --name your name [string] [required] [default: "tom"]
  5. -h, --help Show help [boolean]
  6. Examples:
  7. hello -n tom say hello to Tom
  8. copyright 2015

还没有评论.