Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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.

readme.md 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. # meow
  2. > CLI app helper
  3. ![](meow.gif)
  4. ## Features
  5. - Parses arguments
  6. - Converts flags to [camelCase](https://github.com/sindresorhus/camelcase)
  7. - Negates flags when using the `--no-` prefix
  8. - Outputs version when `--version`
  9. - Outputs description and supplied help text when `--help`
  10. - Makes unhandled rejected promises [fail hard](https://github.com/sindresorhus/hard-rejection) instead of the default silent fail
  11. - Sets the process title to the binary name defined in package.json
  12. ## Install
  13. ```
  14. $ npm install meow
  15. ```
  16. ## Usage
  17. ```
  18. $ ./foo-app.js unicorns --rainbow
  19. ```
  20. **CommonJS**
  21. ```js
  22. #!/usr/bin/env node
  23. 'use strict';
  24. const meow = require('meow');
  25. const foo = require('.');
  26. const cli = meow(`
  27. Usage
  28. $ foo <input>
  29. Options
  30. --rainbow, -r Include a rainbow
  31. Examples
  32. $ foo unicorns --rainbow
  33. 🌈 unicorns 🌈
  34. `, {
  35. flags: {
  36. rainbow: {
  37. type: 'boolean',
  38. alias: 'r'
  39. }
  40. }
  41. });
  42. /*
  43. {
  44. input: ['unicorns'],
  45. flags: {rainbow: true},
  46. ...
  47. }
  48. */
  49. foo(cli.input[0], cli.flags);
  50. ```
  51. **ES Modules**
  52. ```js
  53. #!/usr/bin/env node
  54. import {createRequire} from 'module';
  55. import foo from './lib/index.js';
  56. const meow = createRequire(import.meta.url)('meow');
  57. const cli = meow(`
  58. Usage
  59. $ foo <input>
  60. Options
  61. --rainbow, -r Include a rainbow
  62. Examples
  63. $ foo unicorns --rainbow
  64. 🌈 unicorns 🌈
  65. `, {
  66. flags: {
  67. rainbow: {
  68. type: 'boolean',
  69. alias: 'r'
  70. }
  71. }
  72. });
  73. /*
  74. {
  75. input: ['unicorns'],
  76. flags: {rainbow: true},
  77. ...
  78. }
  79. */
  80. foo(cli.input[0], cli.flags);
  81. ```
  82. ## API
  83. ### meow(helpText, options?)
  84. ### meow(options)
  85. Returns an `object` with:
  86. - `input` *(Array)* - Non-flag arguments
  87. - `flags` *(Object)* - Flags converted to camelCase excluding aliases
  88. - `unnormalizedFlags` *(Object)* - Flags converted to camelCase including aliases
  89. - `pkg` *(Object)* - The `package.json` object
  90. - `help` *(string)* - The help text used with `--help`
  91. - `showHelp([exitCode=2])` *(Function)* - Show the help text and exit with `exitCode`
  92. - `showVersion()` *(Function)* - Show the version text and exit
  93. #### helpText
  94. Type: `string`
  95. Shortcut for the `help` option.
  96. #### options
  97. Type: `object`
  98. ##### flags
  99. Type: `object`
  100. Define argument flags.
  101. The key is the flag name in camel-case and the value is an object with any of:
  102. - `type`: Type of value. (Possible values: `string` `boolean` `number`)
  103. - `alias`: Usually used to define a short flag alias.
  104. - `default`: Default value when the flag is not specified.
  105. - `isRequired`: Determine if the flag is required. (Default: false)
  106. - If it's only known at runtime whether the flag is required or not, you can pass a `Function` instead of a `boolean`, which based on the given flags and other non-flag arguments, should decide if the flag is required. Two arguments are passed to the function:
  107. - The first argument is the **flags** object, which contains the flags converted to camel-case excluding aliases.
  108. - The second argument is the **input** string array, which contains the non-flag arguments.
  109. - The function should return a `boolean`, true if the flag is required, otherwise false.
  110. - `isMultiple`: Indicates a flag can be set multiple times. Values are turned into an array. (Default: false)
  111. - Multiple values are provided by specifying the flag multiple times, for example, `$ foo -u rainbow -u cat`. Space- or comma-separated values are [currently *not* supported](https://github.com/sindresorhus/meow/issues/164).
  112. Note that flags are always defined using a camel-case key (`myKey`), but will match arguments in kebab-case (`--my-key`).
  113. Example:
  114. ```js
  115. flags: {
  116. unicorn: {
  117. type: 'string',
  118. alias: 'u',
  119. default: ['rainbow', 'cat'],
  120. isMultiple: true,
  121. isRequired: (flags, input) => {
  122. if (flags.otherFlag) {
  123. return true;
  124. }
  125. return false;
  126. }
  127. }
  128. }
  129. ```
  130. ##### description
  131. Type: `string | boolean`\
  132. Default: The package.json `"description"` property
  133. Description to show above the help text.
  134. Set it to `false` to disable it altogether.
  135. ##### help
  136. Type: `string | boolean`
  137. The help text you want shown.
  138. 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.
  139. The description will be shown above your help text automatically.
  140. ##### version
  141. Type: `string | boolean`\
  142. Default: The package.json `"version"` property
  143. Set a custom version output.
  144. ##### autoHelp
  145. Type: `boolean`\
  146. Default: `true`
  147. Automatically show the help text when the `--help` flag is present. Useful to set this value to `false` when a CLI manages child CLIs with their own help text.
  148. This option is only considered when there is only one argument in `process.argv`.
  149. ##### autoVersion
  150. Type: `boolean`\
  151. Default: `true`
  152. Automatically show the version text when the `--version` flag is present. Useful to set this value to `false` when a CLI manages child CLIs with their own version text.
  153. This option is only considered when there is only one argument in `process.argv`.
  154. ##### pkg
  155. Type: `object`\
  156. Default: Closest package.json upwards
  157. package.json as an `object`.
  158. *You most likely don't need this option.*
  159. ##### argv
  160. Type: `string[]`\
  161. Default: `process.argv.slice(2)`
  162. Custom arguments object.
  163. ##### inferType
  164. Type: `boolean`\
  165. Default: `false`
  166. Infer the argument type.
  167. By default, the argument `5` in `$ foo 5` becomes a string. Enabling this would infer it as a number.
  168. ##### booleanDefault
  169. Type: `boolean | null | undefined`\
  170. Default: `false`
  171. Value of `boolean` flags not defined in `argv`.
  172. If set to `undefined`, the flags not defined in `argv` will be excluded from the result.
  173. The `default` value set in `boolean` flags take precedence over `booleanDefault`.
  174. _Note: If used in conjunction with `isMultiple`, the default flag value is set to `[]`._
  175. __Caution: Explicitly specifying `undefined` for `booleanDefault` has different meaning from omitting key itself.__
  176. Example:
  177. ```js
  178. const meow = require('meow');
  179. const cli = meow(`
  180. Usage
  181. $ foo
  182. Options
  183. --rainbow, -r Include a rainbow
  184. --unicorn, -u Include a unicorn
  185. --no-sparkles Exclude sparkles
  186. Examples
  187. $ foo
  188. 🌈 unicorns✨🌈
  189. `, {
  190. booleanDefault: undefined,
  191. flags: {
  192. rainbow: {
  193. type: 'boolean',
  194. default: true,
  195. alias: 'r'
  196. },
  197. unicorn: {
  198. type: 'boolean',
  199. default: false,
  200. alias: 'u'
  201. },
  202. cake: {
  203. type: 'boolean',
  204. alias: 'c'
  205. },
  206. sparkles: {
  207. type: 'boolean',
  208. default: true
  209. }
  210. }
  211. });
  212. /*
  213. {
  214. flags: {
  215. rainbow: true,
  216. unicorn: false,
  217. sparkles: true
  218. },
  219. unnormalizedFlags: {
  220. rainbow: true,
  221. r: true,
  222. unicorn: false,
  223. u: false,
  224. sparkles: true
  225. },
  226. }
  227. */
  228. ```
  229. ##### hardRejection
  230. Type: `boolean`\
  231. Default: `true`
  232. Whether to use [`hard-rejection`](https://github.com/sindresorhus/hard-rejection) or not. Disabling this can be useful if you need to handle `process.on('unhandledRejection')` yourself.
  233. #### allowUnknownFlags
  234. Type `boolean`\
  235. Default: `true`
  236. Whether to allow unknown flags or not.
  237. ## Promises
  238. Meow will make unhandled rejected promises [fail hard](https://github.com/sindresorhus/hard-rejection) instead of the default silent fail. Meaning you don't have to manually `.catch()` promises used in your CLI.
  239. ## Tips
  240. See [`chalk`](https://github.com/chalk/chalk) if you want to colorize the terminal output.
  241. See [`get-stdin`](https://github.com/sindresorhus/get-stdin) if you want to accept input from stdin.
  242. See [`conf`](https://github.com/sindresorhus/conf) if you need to persist some data.
  243. See [`update-notifier`](https://github.com/yeoman/update-notifier) if you want update notifications.
  244. [More useful CLI utilities…](https://github.com/sindresorhus/awesome-nodejs#command-line-utilities)
  245. ---
  246. <div align="center">
  247. <b>
  248. <a href="https://tidelift.com/subscription/pkg/npm-meow?utm_source=npm-meow&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
  249. </b>
  250. <br>
  251. <sub>
  252. Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
  253. </sub>
  254. </div>