You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.4 KiB

4 years ago
  1. <p align="center">
  2. <img width="250" src="/yargs-logo.png">
  3. </p>
  4. <h1 align="center"> Yargs </h1>
  5. <p align="center">
  6. <b >Yargs be a node.js library fer hearties tryin' ter parse optstrings</b>
  7. </p>
  8. <br>
  9. [![Build Status][travis-image]][travis-url]
  10. [![Coverage Status][coveralls-image]][coveralls-url]
  11. [![NPM version][npm-image]][npm-url]
  12. [![js-standard-style][standard-image]][standard-url]
  13. [![Conventional Commits][conventional-commits-image]][conventional-commits-url]
  14. [![Slack][slack-image]][slack-url]
  15. ## Description :
  16. Yargs helps you build interactive command line tools, by parsing arguments and generating an elegant user interface.
  17. It gives you:
  18. * commands and (grouped) options (`my-program.js serve --port=5000`).
  19. * a dynamically generated help menu based on your arguments.
  20. > <img width="400" src="/screen.png">
  21. * bash-completion shortcuts for commands and options.
  22. * and [tons more](/docs/api.md).
  23. ## Installation
  24. Stable version:
  25. ```bash
  26. npm i yargs --save
  27. ```
  28. Bleeding edge version with the most recent features:
  29. ```bash
  30. npm i yargs@next --save
  31. ```
  32. ## Usage :
  33. ### Simple Example
  34. ````javascript
  35. #!/usr/bin/env node
  36. const argv = require('yargs').argv
  37. if (argv.ships > 3 && argv.distance < 53.5) {
  38. console.log('Plunder more riffiwobbles!')
  39. } else {
  40. console.log('Retreat from the xupptumblers!')
  41. }
  42. ````
  43. ```bash
  44. $ ./plunder.js --ships=4 --distance=22
  45. Plunder more riffiwobbles!
  46. $ ./plunder.js --ships 12 --distance 98.7
  47. Retreat from the xupptumblers!
  48. ```
  49. ### Complex Example
  50. ```javascript
  51. #!/usr/bin/env node
  52. require('yargs') // eslint-disable-line
  53. .command('serve [port]', 'start the server', (yargs) => {
  54. yargs
  55. .positional('port', {
  56. describe: 'port to bind on',
  57. default: 5000
  58. })
  59. }, (argv) => {
  60. if (argv.verbose) console.info(`start server on :${argv.port}`)
  61. serve(argv.port)
  62. })
  63. .option('verbose', {
  64. alias: 'v',
  65. default: false
  66. })
  67. .argv
  68. ```
  69. Run the example above with `--help` to see the help for the application.
  70. ## Community :
  71. Having problems? want to contribute? join our [community slack](http://devtoolscommunity.herokuapp.com).
  72. ## Documentation :
  73. ### Table of Contents
  74. * [Yargs' API](/docs/api.md)
  75. * [Examples](/docs/examples.md)
  76. * [Parsing Tricks](/docs/tricks.md)
  77. * [Stop the Parser](/docs/tricks.md#stop)
  78. * [Negating Boolean Arguments](/docs/tricks.md#negate)
  79. * [Numbers](/docs/tricks.md#numbers)
  80. * [Arrays](/docs/tricks.md#arrays)
  81. * [Objects](/docs/tricks.md#objects)
  82. * [Advanced Topics](/docs/advanced.md)
  83. * [Composing Your App Using Commands](/docs/advanced.md#commands)
  84. * [Building Configurable CLI Apps](/docs/advanced.md#configuration)
  85. * [Customizing Yargs' Parser](/docs/advanced.md#customizing)
  86. * [Contributing](/contributing.md)
  87. [travis-url]: https://travis-ci.org/yargs/yargs
  88. [travis-image]: https://img.shields.io/travis/yargs/yargs/master.svg
  89. [coveralls-url]: https://coveralls.io/github/yargs/yargs
  90. [coveralls-image]: https://img.shields.io/coveralls/yargs/yargs.svg
  91. [npm-url]: https://www.npmjs.com/package/yargs
  92. [npm-image]: https://img.shields.io/npm/v/yargs.svg
  93. [standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg
  94. [standard-url]: http://standardjs.com/
  95. [conventional-commits-image]: https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg
  96. [conventional-commits-url]: https://conventionalcommits.org/
  97. [slack-image]: http://devtoolscommunity.herokuapp.com/badge.svg
  98. [slack-url]: http://devtoolscommunity.herokuapp.com