项目原始demo,不改动
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

readme.md 3.8 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # meow [![Build Status](https://travis-ci.org/sindresorhus/meow.svg?branch=master)](https://travis-ci.org/sindresorhus/meow)
  2. > CLI app helper
  3. ![](meow.gif)
  4. ## Features
  5. - Parses arguments using [minimist](https://github.com/substack/minimist)
  6. - Converts flags to [camelCase](https://github.com/sindresorhus/camelcase)
  7. - Outputs version when `--version`
  8. - Outputs description and supplied help text when `--help`
  9. - Makes unhandled rejected promises [fail loudly](https://github.com/sindresorhus/loud-rejection) instead of the default silent fail
  10. - Sets the process title to the binary name defined in package.json
  11. ## Install
  12. ```
  13. $ npm install --save meow
  14. ```
  15. ## Usage
  16. ```
  17. $ ./foo-app.js unicorns --rainbow-cake
  18. ```
  19. ```js
  20. #!/usr/bin/env node
  21. 'use strict';
  22. const meow = require('meow');
  23. const foo = require('./');
  24. const cli = meow(`
  25. Usage
  26. $ foo <input>
  27. Options
  28. -r, --rainbow Include a rainbow
  29. Examples
  30. $ foo unicorns --rainbow
  31. 🌈 unicorns 🌈
  32. `, {
  33. alias: {
  34. r: 'rainbow'
  35. }
  36. });
  37. /*
  38. {
  39. input: ['unicorns'],
  40. flags: {rainbow: true},
  41. ...
  42. }
  43. */
  44. foo(cli.input[0], cli.flags);
  45. ```
  46. ## API
  47. ### meow(options, [minimistOptions])
  48. Returns an object with:
  49. - `input` *(array)* - Non-flag arguments
  50. - `flags` *(object)* - Flags converted to camelCase
  51. - `pkg` *(object)* - The `package.json` object
  52. - `help` *(object)* - The help text used with `--help`
  53. - `showHelp([code=0])` *(function)* - Show the help text and exit with `code`
  54. #### options
  55. Type: `object`, `array`, `string`
  56. Can either be a string/array that is the `help` or an options object.
  57. ##### description
  58. Type: `string`, `boolean`
  59. Default: The package.json `"description"` property
  60. A description to show above the help text.
  61. Set it to `false` to disable it altogether.
  62. ##### help
  63. Type: `string`, `boolean`
  64. The help text you want shown.
  65. The input is reindented and starting/ending newlines are trimmed which means you can use a [template literal](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/template_strings) without having to care about using the correct amount of indent.
  66. <del>If it's an array each item will be a line.</del>
  67. *(Still supported, but you should use a template literal instead.)*
  68. The description will be shown above your help text automatically.
  69. Set it to `false` to disable it altogether.
  70. ##### version
  71. Type: `string`, `boolean`
  72. Default: The package.json `"version"` property
  73. Set a custom version output.
  74. Set it to `false` to disable it altogether.
  75. ##### pkg
  76. Type: `string`, `object`
  77. Default: Closest package.json upwards
  78. Relative path to package.json or as an object.
  79. ##### argv
  80. Type: `array`
  81. Default: `process.argv.slice(2)`
  82. Custom arguments object.
  83. #### minimistOptions
  84. Type: `object`
  85. Default: `{}`
  86. Minimist [options](https://github.com/substack/minimist#var-argv--parseargsargs-opts).
  87. Keys passed to the minimist `default` option are [decamelized](https://github.com/sindresorhus/decamelize), so you can for example pass in `fooBar: 'baz'` and have it be the default for the `--foo-bar` flag.
  88. ## Promises
  89. Meow will make unhandled rejected promises [fail loudly](https://github.com/sindresorhus/loud-rejection) instead of the default silent fail. Meaning you don't have to manually `.catch()` promises used in your CLI.
  90. ## Tips
  91. See [`chalk`](https://github.com/chalk/chalk) if you want to colorize the terminal output.
  92. See [`get-stdin`](https://github.com/sindresorhus/get-stdin) if you want to accept input from stdin.
  93. See [`update-notifier`](https://github.com/yeoman/update-notifier) if you want update notifications.
  94. See [`configstore`](https://github.com/yeoman/configstore) if you need to persist some data.
  95. [More useful CLI utilities.](https://github.com/sindresorhus/awesome-nodejs#command-line-utilities)
  96. ## License
  97. MIT © [Sindre Sorhus](http://sindresorhus.com)