项目原始demo,不改动
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
Este repositório está arquivado. Você pode visualizar os arquivos e realizar clone, mas não poderá realizar push nem abrir issues e pull requests.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # Yargs
  2. [![Build Status][travis-image]][travis-url]
  3. [![Coverage Status][coveralls-image]][coveralls-url]
  4. [![NPM version][npm-image]][npm-url]
  5. [![Windows Tests][windows-image]][windows-url]
  6. [![js-standard-style][standard-image]][standard-url]
  7. [![Conventional Commits][conventional-commits-image]][conventional-commits-url]
  8. [![Gitter][gitter-image]][gitter-url]
  9. > Yargs be a node.js library fer hearties tryin' ter parse optstrings.
  10. <img width="250" src="/yargs-logo.png">
  11. Yargs helps you build interactive command line tools, by parsing arguments and generating an elegant user interface. It gives you:
  12. * commands and (grouped) options (`my-program.js serve --port=5000`).
  13. * a dynamically generated help menu based on your arguments.
  14. > <img width="400" src="/screen.png">
  15. * bash-completion shortcuts for commands and options.
  16. * and [tons more](/docs/api.md).
  17. ## Installation
  18. ```bash
  19. npm i yargs --save
  20. ```
  21. ## Simple Example
  22. ````javascript
  23. #!/usr/bin/env node
  24. const argv = require('yargs').argv
  25. if (argv.ships > 3 && argv.distance < 53.5) {
  26. console.log('Plunder more riffiwobbles!')
  27. } else {
  28. console.log('Retreat from the xupptumblers!')
  29. }
  30. ````
  31. ```bash
  32. $ ./plunder.js --ships=4 --distance=22
  33. Plunder more riffiwobbles!
  34. $ ./plunder.js --ships 12 --distance 98.7
  35. Retreat from the xupptumblers!
  36. ```
  37. ## Complex Example
  38. ```js
  39. #!/usr/bin/env node
  40. const yargs = require('yargs') // eslint-disable-line
  41. .command('serve', 'start the server', (yargs) => {
  42. yargs.option('port', {
  43. describe: 'port to bind on',
  44. default: 5000
  45. })
  46. }, (argv) => {
  47. if (argv.verbose) console.info(`start server on :${argv.port}`)
  48. serve(argv.port)
  49. })
  50. .option('verbose', {
  51. alias: 'v',
  52. default: false
  53. })
  54. .help()
  55. .argv
  56. ```
  57. ## Table of Contents
  58. * [Yargs' API](/docs/api.md)
  59. * [Examples](/docs/examples.md)
  60. * [Parsing Tricks](/docs/tricks.md)
  61. * [Stop the Parser](/docs/tricks.md#stop)
  62. * [Negating Boolean Arguments](/docs/tricks.md#negate)
  63. * [Numbers](/docs/tricks.md#numbers)
  64. * [Arrays](/docs/tricks.md#arrays)
  65. * [Objects](/docs/tricks.md#objects)
  66. * [Advanced Topics](/docs/advanced.md)
  67. * [Composing Your App Using Commands](/docs/advanced.md#commands)
  68. * [Building Configurable CLI Apps](/docs/advanced.md#configuration)
  69. * [Customizing Yargs' Parser](/docs/advanced.md#customizing)
  70. * [Contributing](/contributing.md)
  71. [travis-url]: https://travis-ci.org/yargs/yargs
  72. [travis-image]: https://img.shields.io/travis/yargs/yargs/master.svg
  73. [coveralls-url]: https://coveralls.io/github/yargs/yargs
  74. [coveralls-image]: https://img.shields.io/coveralls/yargs/yargs.svg
  75. [npm-url]: https://www.npmjs.com/package/yargs
  76. [npm-image]: https://img.shields.io/npm/v/yargs.svg
  77. [windows-url]: https://ci.appveyor.com/project/bcoe/yargs-ljwvf
  78. [windows-image]: https://img.shields.io/appveyor/ci/bcoe/yargs-ljwvf/master.svg?label=Windows%20Tests
  79. [standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg
  80. [standard-url]: http://standardjs.com/
  81. [conventional-commits-image]: https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg
  82. [conventional-commits-url]: https://conventionalcommits.org/
  83. [gitter-image]: https://img.shields.io/gitter/room/nwjs/nw.js.svg?maxAge=2592000
  84. [gitter-url]: https://gitter.im/yargs/Lobby?utm_source=share-link&utm_medium=link&utm_campaign=share-link