Ohm-Management - Projektarbeit B-ME
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 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <img width="75px" height="75px" align="right" alt="Inquirer Logo" src="https://raw.githubusercontent.com/SBoudrias/Inquirer.js/master/assets/inquirer_readme.svg?sanitize=true" title="Inquirer.js"/>
  2. # Inquirer.js
  3. [![npm](https://badge.fury.io/js/inquirer.svg)](http://badge.fury.io/js/inquirer) [![tests](https://travis-ci.org/SBoudrias/Inquirer.js.svg?branch=master)](http://travis-ci.org/SBoudrias/Inquirer.js) [![Coverage Status](https://codecov.io/gh/SBoudrias/Inquirer.js/branch/master/graph/badge.svg)](https://codecov.io/gh/SBoudrias/Inquirer.js) [![dependencies](https://david-dm.org/SBoudrias/Inquirer.js.svg?theme=shields.io)](https://david-dm.org/SBoudrias/Inquirer.js)
  4. A collection of common interactive command line user interfaces.
  5. **Version 4.x** only supports Node 6 and over. For Node 4 support please use [version 3.x](https://github.com/SBoudrias/Inquirer.js/tree/v3.3.0).
  6. ## Table of Contents
  7. 1. [Documentation](#documentation)
  8. 1. [Installation](#installation)
  9. 2. [Examples](#examples)
  10. 3. [Methods](#methods)
  11. 4. [Objects](#objects)
  12. 5. [Questions](#questions)
  13. 6. [Answers](#answers)
  14. 7. [Separator](#separator)
  15. 8. [Prompt Types](#prompt)
  16. 2. [User Interfaces and Layouts](#layouts)
  17. 1. [Reactive Interface](#reactive)
  18. 3. [Support](#support)
  19. 4. [News](#news)
  20. 5. [Contributing](#contributing)
  21. 6. [License](#license)
  22. 7. [Plugins](#plugins)
  23. ## Goal and Philosophy
  24. **`Inquirer.js`** strives to be an easily embeddable and beautiful command line interface for [Node.js](https://nodejs.org/) (and perhaps the "CLI [Xanadu](https://en.wikipedia.org/wiki/Citizen_Kane)").
  25. **`Inquirer.js`** should ease the process of
  26. - providing _error feedback_
  27. - _asking questions_
  28. - _parsing_ input
  29. - _validating_ answers
  30. - managing _hierarchical prompts_
  31. > **Note:** **`Inquirer.js`** provides the user interface and the inquiry session flow. If you're searching for a full blown command line program utility, then check out [commander](https://github.com/visionmedia/commander.js), [vorpal](https://github.com/dthree/vorpal) or [args](https://github.com/leo/args).
  32. ## [Documentation](#documentation)
  33. <a name="documentation"></a>
  34. ### Installation
  35. <a name="installation"></a>
  36. ```shell
  37. npm install inquirer
  38. ```
  39. ```javascript
  40. var inquirer = require('inquirer');
  41. inquirer
  42. .prompt([
  43. /* Pass your questions in here */
  44. ])
  45. .then(answers => {
  46. // Use user feedback for... whatever!!
  47. });
  48. ```
  49. <a name="examples"></a>
  50. ### Examples (Run it and see it)
  51. Check out the [`packages/inquirer/examples/`](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/inquirer/examples) folder for code and interface examples.
  52. ```shell
  53. node packages/inquirer/examples/pizza.js
  54. node packages/inquirer/examples/checkbox.js
  55. # etc...
  56. ```
  57. ### Methods
  58. <a name="methods"></a>
  59. #### `inquirer.prompt(questions) -> promise`
  60. Launch the prompt interface (inquiry session)
  61. - **questions** (Array) containing [Question Object](#question) (using the [reactive interface](#reactive-interface), you can also pass a `Rx.Observable` instance)
  62. - returns a **Promise**
  63. #### `inquirer.registerPrompt(name, prompt)`
  64. Register prompt plugins under `name`.
  65. - **name** (string) name of the this new prompt. (used for question `type`)
  66. - **prompt** (object) the prompt object itself (the plugin)
  67. #### `inquirer.createPromptModule() -> prompt function`
  68. Create a self contained inquirer module. If you don't want to affect other libraries that also rely on inquirer when you overwrite or add new prompt types.
  69. ```js
  70. var prompt = inquirer.createPromptModule();
  71. prompt(questions).then(/* ... */);
  72. ```
  73. ### Objects
  74. <a name="objects"></a>
  75. #### Question
  76. <a name="questions"></a>
  77. A question object is a `hash` containing question related values:
  78. - **type**: (String) Type of the prompt. Defaults: `input` - Possible values: `input`, `number`, `confirm`,
  79. `list`, `rawlist`, `expand`, `checkbox`, `password`, `editor`
  80. - **name**: (String) The name to use when storing the answer in the answers hash. If the name contains periods, it will define a path in the answers hash.
  81. - **message**: (String|Function) The question to print. If defined as a function, the first parameter will be the current inquirer session answers. Defaults to the value of `name` (followed by a colon).
  82. - **default**: (String|Number|Boolean|Array|Function) Default value(s) to use if nothing is entered, or a function that returns the default value(s). If defined as a function, the first parameter will be the current inquirer session answers.
  83. - **choices**: (Array|Function) Choices array or a function returning a choices array. If defined as a function, the first parameter will be the current inquirer session answers.
  84. Array values can be simple `numbers`, `strings`, or `objects` containing a `name` (to display in list), a `value` (to save in the answers hash) and a `short` (to display after selection) properties. The choices array can also contain [a `Separator`](#separator).
  85. - **validate**: (Function) Receive the user input and answers hash. Should return `true` if the value is valid, and an error message (`String`) otherwise. If `false` is returned, a default error message is provided.
  86. - **filter**: (Function) Receive the user input and return the filtered value to be used inside the program. The value returned will be added to the _Answers_ hash.
  87. - **transformer**: (Function) Receive the user input, answers hash and option flags, and return a transformed value to display to the user. The transformation only impacts what is shown while editing. It does not modify the answers hash.
  88. - **when**: (Function, Boolean) Receive the current user answers hash and should return `true` or `false` depending on whether or not this question should be asked. The value can also be a simple boolean.
  89. - **pageSize**: (Number) Change the number of lines that will be rendered when using `list`, `rawList`, `expand` or `checkbox`.
  90. - **prefix**: (String) Change the default _prefix_ message.
  91. - **suffix**: (String) Change the default _suffix_ message.
  92. `default`, `choices`(if defined as functions), `validate`, `filter` and `when` functions can be called asynchronously. Either return a promise or use `this.async()` to get a callback you'll call with the final value.
  93. ```javascript
  94. {
  95. /* Preferred way: with promise */
  96. filter() {
  97. return new Promise(/* etc... */);
  98. },
  99. /* Legacy way: with this.async */
  100. validate: function (input) {
  101. // Declare function as asynchronous, and save the done callback
  102. var done = this.async();
  103. // Do async stuff
  104. setTimeout(function() {
  105. if (typeof input !== 'number') {
  106. // Pass the return value in the done callback
  107. done('You need to provide a number');
  108. return;
  109. }
  110. // Pass the return value in the done callback
  111. done(null, true);
  112. }, 3000);
  113. }
  114. }
  115. ```
  116. ### Answers
  117. <a name="answers"></a>
  118. A key/value hash containing the client answers in each prompt.
  119. - **Key** The `name` property of the _question_ object
  120. - **Value** (Depends on the prompt)
  121. - `confirm`: (Boolean)
  122. - `input` : User input (filtered if `filter` is defined) (String)
  123. - `number`: User input (filtered if `filter` is defined) (Number)
  124. - `rawlist`, `list` : Selected choice value (or name if no value specified) (String)
  125. ### Separator
  126. <a name="separator"></a>
  127. A separator can be added to any `choices` array:
  128. ```
  129. // In the question object
  130. choices: [ "Choice A", new inquirer.Separator(), "choice B" ]
  131. // Which'll be displayed this way
  132. [?] What do you want to do?
  133. > Order a pizza
  134. Make a reservation
  135. --------
  136. Ask opening hours
  137. Talk to the receptionist
  138. ```
  139. The constructor takes a facultative `String` value that'll be use as the separator. If omitted, the separator will be `--------`.
  140. Separator instances have a property `type` equal to `separator`. This should allow tools façading Inquirer interface from detecting separator types in lists.
  141. <a name="prompt"></a>
  142. ### Prompt types
  143. ---
  144. > **Note:**: _allowed options written inside square brackets (`[]`) are optional. Others are required._
  145. #### List - `{type: 'list'}`
  146. Take `type`, `name`, `message`, `choices`[, `default`, `filter`] properties. (Note that
  147. default must be the choice `index` in the array or a choice `value`)
  148. ![List prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/list.svg)
  149. ---
  150. #### Raw List - `{type: 'rawlist'}`
  151. Take `type`, `name`, `message`, `choices`[, `default`, `filter`] properties. (Note that
  152. default must be the choice `index` in the array)
  153. ![Raw list prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/rawlist.svg)
  154. ---
  155. #### Expand - `{type: 'expand'}`
  156. Take `type`, `name`, `message`, `choices`[, `default`] properties. (Note that
  157. default must be the choice `index` in the array. If `default` key not provided, then `help` will be used as default choice)
  158. Note that the `choices` object will take an extra parameter called `key` for the `expand` prompt. This parameter must be a single (lowercased) character. The `h` option is added by the prompt and shouldn't be defined by the user.
  159. See `examples/expand.js` for a running example.
  160. ![Expand prompt closed](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/expand-y.svg)
  161. ![Expand prompt expanded](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/expand-d.svg)
  162. ---
  163. #### Checkbox - `{type: 'checkbox'}`
  164. Take `type`, `name`, `message`, `choices`[, `filter`, `validate`, `default`] properties. `default` is expected to be an Array of the checked choices value.
  165. Choices marked as `{checked: true}` will be checked by default.
  166. Choices whose property `disabled` is truthy will be unselectable. If `disabled` is a string, then the string will be outputted next to the disabled choice, otherwise it'll default to `"Disabled"`. The `disabled` property can also be a synchronous function receiving the current answers as argument and returning a boolean or a string.
  167. ![Checkbox prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/checkbox.svg)
  168. ---
  169. #### Confirm - `{type: 'confirm'}`
  170. Take `type`, `name`, `message`, [`default`] properties. `default` is expected to be a boolean if used.
  171. ![Confirm prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/confirm.svg)
  172. ---
  173. #### Input - `{type: 'input'}`
  174. Take `type`, `name`, `message`[, `default`, `filter`, `validate`, `transformer`] properties.
  175. ![Input prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/input.svg)
  176. ---
  177. #### Input - `{type: 'number'}`
  178. Take `type`, `name`, `message`[, `default`, `filter`, `validate`, `transformer`] properties.
  179. ---
  180. #### Password - `{type: 'password'}`
  181. Take `type`, `name`, `message`, `mask`,[, `default`, `filter`, `validate`] properties.
  182. ![Password prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/password.svg)
  183. ---
  184. Note that `mask` is required to hide the actual user input.
  185. #### Editor - `{type: 'editor'}`
  186. Take `type`, `name`, `message`[, `default`, `filter`, `validate`] properties
  187. Launches an instance of the users preferred editor on a temporary file. Once the user exits their editor, the contents of the temporary file are read in as the result. The editor to use is determined by reading the $VISUAL or $EDITOR environment variables. If neither of those are present, notepad (on Windows) or vim (Linux or Mac) is used.
  188. <a name="layouts"></a>
  189. ## User Interfaces and layouts
  190. Along with the prompts, Inquirer offers some basic text UI.
  191. #### Bottom Bar - `inquirer.ui.BottomBar`
  192. This UI present a fixed text at the bottom of a free text zone. This is useful to keep a message to the bottom of the screen while outputting command outputs on the higher section.
  193. ```javascript
  194. var ui = new inquirer.ui.BottomBar();
  195. // pipe a Stream to the log zone
  196. outputStream.pipe(ui.log);
  197. // Or simply write output
  198. ui.log.write('something just happened.');
  199. ui.log.write('Almost over, standby!');
  200. // During processing, update the bottom bar content to display a loader
  201. // or output a progress bar, etc
  202. ui.updateBottomBar('new bottom bar content');
  203. ```
  204. <a name="reactive"></a>
  205. ## Reactive interface
  206. Internally, Inquirer uses the [JS reactive extension](https://github.com/ReactiveX/rxjs) to handle events and async flows.
  207. This mean you can take advantage of this feature to provide more advanced flows. For example, you can dynamically add questions to be asked:
  208. ```js
  209. var prompts = new Rx.Subject();
  210. inquirer.prompt(prompts);
  211. // At some point in the future, push new questions
  212. prompts.next({
  213. /* question... */
  214. });
  215. prompts.next({
  216. /* question... */
  217. });
  218. // When you're done
  219. prompts.complete();
  220. ```
  221. And using the return value `process` property, you can access more fine grained callbacks:
  222. ```js
  223. inquirer.prompt(prompts).ui.process.subscribe(onEachAnswer, onError, onComplete);
  224. ```
  225. ## Support (OS Terminals)
  226. <a name="support"></a>
  227. You should expect mostly good support for the CLI below. This does not mean we won't
  228. look at issues found on other command line - feel free to report any!
  229. - **Mac OS**:
  230. - Terminal.app
  231. - iTerm
  232. - **Windows**:
  233. - [ConEmu](https://conemu.github.io/)
  234. - cmd.exe
  235. - Powershell
  236. - Cygwin
  237. - **Linux (Ubuntu, openSUSE, Arch Linux, etc)**:
  238. - gnome-terminal (Terminal GNOME)
  239. - konsole
  240. ## News on the march (Release notes)
  241. <a name="news"></a>
  242. Please refer to the [Github releases section for the changelog](https://github.com/SBoudrias/Inquirer.js/releases)
  243. ## Contributing
  244. <a name="contributing"></a>
  245. **Unit test**
  246. Unit test are written in [Mocha](https://mochajs.org/). Please add a unit test for every new feature or bug fix. `npm test` to run the test suite.
  247. **Documentation**
  248. Add documentation for every API change. Feel free to send typo fixes and better docs!
  249. We're looking to offer good support for multiple prompts and environments. If you want to
  250. help, we'd like to keep a list of testers for each terminal/OS so we can contact you and
  251. get feedback before release. Let us know if you want to be added to the list (just tweet
  252. to [@vaxilart](https://twitter.com/Vaxilart)) or just add your name to [the wiki](https://github.com/SBoudrias/Inquirer.js/wiki/Testers)
  253. ## License
  254. <a name="license"></a>
  255. Copyright (c) 2016 Simon Boudrias (twitter: [@vaxilart](https://twitter.com/Vaxilart))
  256. Licensed under the MIT license.
  257. ## Plugins
  258. <a name="plugins"></a>
  259. ### Prompts
  260. [**autocomplete**](https://github.com/mokkabonna/inquirer-autocomplete-prompt)<br>
  261. Presents a list of options as the user types, compatible with other packages such as fuzzy (for search)<br>
  262. <br>
  263. ![autocomplete prompt](https://github.com/mokkabonna/inquirer-autocomplete-prompt/raw/master/inquirer.gif)
  264. [**checkbox-plus**](https://github.com/faressoft/inquirer-checkbox-plus-prompt)<br>
  265. Checkbox list with autocomplete and other additions<br>
  266. <br>
  267. ![checkbox-plus](https://github.com/faressoft/inquirer-checkbox-plus-prompt/raw/master/demo.gif)
  268. [**datetime**](https://github.com/DerekTBrown/inquirer-datepicker-prompt)<br>
  269. Customizable date/time selector using both number pad and arrow keys<br>
  270. <br>
  271. ![Datetime Prompt](https://github.com/DerekTBrown/inquirer-datepicker-prompt/raw/master/example/datetime-prompt.png)
  272. [**inquirer-select-line**](https://github.com/adam-golab/inquirer-select-line)<br>
  273. Prompt for selecting index in array where add new element<br>
  274. <br>
  275. ![inquirer-select-line gif](https://media.giphy.com/media/xUA7b1MxpngddUvdHW/giphy.gif)
  276. [**command**](https://github.com/sullof/inquirer-command-prompt)<br>
  277. <br>
  278. Simple prompt with command history and dynamic autocomplete
  279. [**inquirer-fuzzy-path**](https://github.com/adelsz/inquirer-fuzzy-path)<br>
  280. Prompt for fuzzy file/directory selection.<br>
  281. <br>
  282. ![inquirer-fuzzy-path](https://raw.githubusercontent.com/adelsz/inquirer-fuzzy-path/master/recording.gif)
  283. [**inquirer-emoji**](https://github.com/tannerntannern/inquirer-emoji)<br>
  284. Prompt for inputting emojis.<br>
  285. <br>
  286. ![inquirer-emoji](https://github.com/tannerntannern/inquirer-emoji/raw/master/demo.gif)
  287. [**inquirer-chalk-pipe**](https://github.com/LitoMore/inquirer-chalk-pipe)<br>
  288. Prompt for input chalk-pipe style strings<br>
  289. <br>
  290. ![inquirer-chalk-pipe](https://github.com/LitoMore/inquirer-chalk-pipe/raw/master/screenshot.gif)
  291. [**inquirer-search-checkbox**](https://github.com/clinyong/inquirer-search-checkbox)<br>
  292. Searchable Inquirer checkbox<br>
  293. [**inquirer-prompt-suggest**](https://github.com/olistic/inquirer-prompt-suggest)<br>
  294. Inquirer prompt for your less creative users.
  295. ![inquirer-prompt-suggest](https://user-images.githubusercontent.com/5600126/40391192-d4f3d6d0-5ded-11e8-932f-4b75b642c09e.gif)
  296. [**inquirer-s3**](https://github.com/HQarroum/inquirer-s3)<br>
  297. An S3 object selector for Inquirer.
  298. ![inquirer-s3](https://github.com/HQarroum/inquirer-s3/raw/master/docs/inquirer-screenshot.png)
  299. [**inquirer-autosubmit-prompt**](https://github.com/yaodingyd/inquirer-autosubmit-prompt)<br>
  300. Auto submit based on your current input, saving one extra enter