Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / inquirer / README.md
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
3 # Inquirer.js
4
5 [![npm](https://badge.fury.io/js/inquirer.svg)](http://badge.fury.io/js/inquirer)
6 [![tests](https://travis-ci.org/SBoudrias/Inquirer.js.svg?branch=master)](http://travis-ci.org/SBoudrias/Inquirer.js)
7 [![Coverage Status](https://codecov.io/gh/SBoudrias/Inquirer.js/branch/master/graph/badge.svg)](https://codecov.io/gh/SBoudrias/Inquirer.js)
8 [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2FSBoudrias%2FInquirer.js.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2FSBoudrias%2FInquirer.js?ref=badge_shield)
9
10 A collection of common interactive command line user interfaces.
11
12 ## Table of Contents
13
14 1.  [Documentation](#documentation)
15     1.  [Installation](#installation)
16     2.  [Examples](#examples)
17     3.  [Methods](#methods)
18     4.  [Objects](#objects)
19     5.  [Questions](#questions)
20     6.  [Answers](#answers)
21     7.  [Separator](#separator)
22     8.  [Prompt Types](#prompt)
23 2.  [User Interfaces and Layouts](#layouts)
24     1.  [Reactive Interface](#reactive)
25 3.  [Support](#support)
26 4.  [Known issues](#issues)
27 4.  [News](#news)
28 5.  [Contributing](#contributing)
29 6.  [License](#license)
30 7.  [Plugins](#plugins)
31
32 ## Goal and Philosophy
33
34 **`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)").
35
36 **`Inquirer.js`** should ease the process of
37
38 - providing _error feedback_
39 - _asking questions_
40 - _parsing_ input
41 - _validating_ answers
42 - managing _hierarchical prompts_
43
44 > **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).
45
46 ## [Documentation](#documentation)
47
48 <a name="documentation"></a>
49
50 ### Installation
51
52 <a name="installation"></a>
53
54 ```shell
55 npm install inquirer
56 ```
57
58 ```javascript
59 var inquirer = require('inquirer');
60 inquirer
61   .prompt([
62     /* Pass your questions in here */
63   ])
64   .then(answers => {
65     // Use user feedback for... whatever!!
66   })
67   .catch(error => {
68     if(error.isTtyError) {
69       // Prompt couldn't be rendered in the current environment
70     } else {
71       // Something else when wrong
72     }
73   });
74 ```
75
76 <a name="examples"></a>
77
78 ### Examples (Run it and see it)
79
80 Check out the [`packages/inquirer/examples/`](https://github.com/SBoudrias/Inquirer.js/tree/master/packages/inquirer/examples) folder for code and interface examples.
81
82 ```shell
83 node packages/inquirer/examples/pizza.js
84 node packages/inquirer/examples/checkbox.js
85 # etc...
86 ```
87
88 ### Methods
89
90 <a name="methods"></a>
91
92 #### `inquirer.prompt(questions) -> promise`
93
94 Launch the prompt interface (inquiry session)
95
96 - **questions** (Array) containing [Question Object](#question) (using the [reactive interface](#reactive-interface), you can also pass a `Rx.Observable` instance)
97 - returns a **Promise**
98
99 #### `inquirer.registerPrompt(name, prompt)`
100
101 Register prompt plugins under `name`.
102
103 - **name** (string) name of the this new prompt. (used for question `type`)
104 - **prompt** (object) the prompt object itself (the plugin)
105
106 #### `inquirer.createPromptModule() -> prompt function`
107
108 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.
109
110 ```js
111 var prompt = inquirer.createPromptModule();
112
113 prompt(questions).then(/* ... */);
114 ```
115
116 ### Objects
117
118 <a name="objects"></a>
119
120 #### Question
121
122 <a name="questions"></a>
123 A question object is a `hash` containing question related values:
124
125 - **type**: (String) Type of the prompt. Defaults: `input` - Possible values: `input`, `number`, `confirm`,
126   `list`, `rawlist`, `expand`, `checkbox`, `password`, `editor`
127 - **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.
128 - **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).
129 - **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.
130 - **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.
131   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).
132 - **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.
133 - **filter**: (Function) Receive the user input and answers hash. Returns the filtered value to be used inside the program. The value returned will be added to the _Answers_ hash.
134 - **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.
135 - **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.
136 - **pageSize**: (Number) Change the number of lines that will be rendered when using `list`, `rawList`, `expand` or `checkbox`.
137 - **prefix**: (String) Change the default _prefix_ message.
138 - **suffix**: (String) Change the default _suffix_ message.
139 - **askAnswered**: (Boolean) Force to prompt the question if the answer already exists.
140 - **loop**: (Boolean) Enable list looping. Defaults: `true`
141
142 `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.
143
144 ```javascript
145 {
146   /* Preferred way: with promise */
147   filter() {
148     return new Promise(/* etc... */);
149   },
150
151   /* Legacy way: with this.async */
152   validate: function (input) {
153     // Declare function as asynchronous, and save the done callback
154     var done = this.async();
155
156     // Do async stuff
157     setTimeout(function() {
158       if (typeof input !== 'number') {
159         // Pass the return value in the done callback
160         done('You need to provide a number');
161         return;
162       }
163       // Pass the return value in the done callback
164       done(null, true);
165     }, 3000);
166   }
167 }
168 ```
169
170 ### Answers
171
172 <a name="answers"></a>
173 A key/value hash containing the client answers in each prompt.
174
175 - **Key** The `name` property of the _question_ object
176 - **Value** (Depends on the prompt)
177   - `confirm`: (Boolean)
178   - `input` : User input (filtered if `filter` is defined) (String)
179   - `number`: User input (filtered if `filter` is defined) (Number)
180   - `rawlist`, `list` : Selected choice value (or name if no value specified) (String)
181
182 ### Separator
183
184 <a name="separator"></a>
185 A separator can be added to any `choices` array:
186
187 ```
188 // In the question object
189 choices: [ "Choice A", new inquirer.Separator(), "choice B" ]
190
191 // Which'll be displayed this way
192 [?] What do you want to do?
193  > Order a pizza
194    Make a reservation
195    --------
196    Ask opening hours
197    Talk to the receptionist
198 ```
199
200 The constructor takes a facultative `String` value that'll be use as the separator. If omitted, the separator will be `--------`.
201
202 Separator instances have a property `type` equal to `separator`. This should allow tools façading Inquirer interface from detecting separator types in lists.
203
204 <a name="prompt"></a>
205
206 ### Prompt types
207
208 ---
209
210 > **Note:**: _allowed options written inside square brackets (`[]`) are optional. Others are required._
211
212 #### List - `{type: 'list'}`
213
214 Take `type`, `name`, `message`, `choices`[, `default`, `filter`, `loop`] properties. (Note that
215 default must be the choice `index` in the array or a choice `value`)
216
217 ![List prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/list.svg)
218
219 ---
220
221 #### Raw List - `{type: 'rawlist'}`
222
223 Take `type`, `name`, `message`, `choices`[, `default`, `filter`, `loop`] properties. (Note that
224 default must be the choice `index` in the array)
225
226 ![Raw list prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/rawlist.svg)
227
228 ---
229
230 #### Expand - `{type: 'expand'}`
231
232 Take `type`, `name`, `message`, `choices`[, `default`] properties. (Note that
233 default must be the choice `index` in the array. If `default` key not provided, then `help` will be used as default choice)
234
235 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.
236
237 See `examples/expand.js` for a running example.
238
239 ![Expand prompt closed](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/expand-y.svg)
240 ![Expand prompt expanded](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/expand-d.svg)
241
242 ---
243
244 #### Checkbox - `{type: 'checkbox'}`
245
246 Take `type`, `name`, `message`, `choices`[, `filter`, `validate`, `default`, `loop`] properties. `default` is expected to be an Array of the checked choices value.
247
248 Choices marked as `{checked: true}` will be checked by default.
249
250 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.
251
252 ![Checkbox prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/checkbox.svg)
253
254 ---
255
256 #### Confirm - `{type: 'confirm'}`
257
258 Take `type`, `name`, `message`, [`default`] properties. `default` is expected to be a boolean if used.
259
260 ![Confirm prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/confirm.svg)
261
262 ---
263
264 #### Input - `{type: 'input'}`
265
266 Take `type`, `name`, `message`[, `default`, `filter`, `validate`, `transformer`] properties.
267
268 ![Input prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/input.svg)
269
270 ---
271
272 #### Input - `{type: 'number'}`
273
274 Take `type`, `name`, `message`[, `default`, `filter`, `validate`, `transformer`] properties.
275
276 ---
277
278 #### Password - `{type: 'password'}`
279
280 Take `type`, `name`, `message`, `mask`,[, `default`, `filter`, `validate`] properties.
281
282 ![Password prompt](https://cdn.rawgit.com/SBoudrias/Inquirer.js/28ae8337ba51d93e359ef4f7ee24e79b69898962/assets/screenshots/password.svg)
283
284 ---
285
286 Note that `mask` is required to hide the actual user input.
287
288 #### Editor - `{type: 'editor'}`
289
290 Take `type`, `name`, `message`[, `default`, `filter`, `validate`] properties
291
292 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.
293
294 <a name="layouts"></a>
295
296 ### Use in Non-Interactive Environments
297 `prompt()` requires that it is run in an interactive environment. (I.e. [One where `process.stdin.isTTY` is `true`](https://nodejs.org/docs/latest-v12.x/api/process.html#process_a_note_on_process_i_o)). If `prompt()` is invoked outside of such an environment, then `prompt()` will return a rejected promise with an error. For convenience, the error will have a `isTtyError` property to programmatically indicate the cause.
298
299
300 ## User Interfaces and layouts
301
302 Along with the prompts, Inquirer offers some basic text UI.
303
304 #### Bottom Bar - `inquirer.ui.BottomBar`
305
306 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.
307
308 ```javascript
309 var ui = new inquirer.ui.BottomBar();
310
311 // pipe a Stream to the log zone
312 outputStream.pipe(ui.log);
313
314 // Or simply write output
315 ui.log.write('something just happened.');
316 ui.log.write('Almost over, standby!');
317
318 // During processing, update the bottom bar content to display a loader
319 // or output a progress bar, etc
320 ui.updateBottomBar('new bottom bar content');
321 ```
322
323 <a name="reactive"></a>
324
325 ## Reactive interface
326
327 Internally, Inquirer uses the [JS reactive extension](https://github.com/ReactiveX/rxjs) to handle events and async flows.
328
329 This mean you can take advantage of this feature to provide more advanced flows. For example, you can dynamically add questions to be asked:
330
331 ```js
332 var prompts = new Rx.Subject();
333 inquirer.prompt(prompts);
334
335 // At some point in the future, push new questions
336 prompts.next({
337   /* question... */
338 });
339 prompts.next({
340   /* question... */
341 });
342
343 // When you're done
344 prompts.complete();
345 ```
346
347 And using the return value `process` property, you can access more fine grained callbacks:
348
349 ```js
350 inquirer.prompt(prompts).ui.process.subscribe(onEachAnswer, onError, onComplete);
351 ```
352
353 ## Support (OS Terminals)
354
355 <a name="support"></a>
356
357 You should expect mostly good support for the CLI below. This does not mean we won't
358 look at issues found on other command line - feel free to report any!
359
360 - **Mac OS**:
361   - Terminal.app
362   - iTerm
363 - **Windows ([Known issues](#issues))**:
364   - [ConEmu](https://conemu.github.io/)
365   - cmd.exe
366   - Powershell
367   - Cygwin
368 - **Linux (Ubuntu, openSUSE, Arch Linux, etc)**:
369   - gnome-terminal (Terminal GNOME)
370   - konsole
371
372 ## Know issues
373
374 <a name="issues"></a>
375
376 Running Inquirer together with network streams in Windows platform inside some terminals can result in process hang.
377 Workaround: run inside another terminal.
378 Please refer to the https://github.com/nodejs/node/issues/21771
379
380 ## News on the march (Release notes)
381
382 <a name="news"></a>
383
384 Please refer to the [GitHub releases section for the changelog](https://github.com/SBoudrias/Inquirer.js/releases)
385
386 ## Contributing
387
388 <a name="contributing"></a>
389
390 **Unit test**
391 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.
392
393 **Documentation**
394 Add documentation for every API change. Feel free to send typo fixes and better docs!
395
396 We're looking to offer good support for multiple prompts and environments. If you want to
397 help, we'd like to keep a list of testers for each terminal/OS so we can contact you and
398 get feedback before release. Let us know if you want to be added to the list (just tweet
399 to [@vaxilart](https://twitter.com/Vaxilart)) or just add your name to [the wiki](https://github.com/SBoudrias/Inquirer.js/wiki/Testers)
400
401 ## License
402
403 <a name="license"></a>
404
405 Copyright (c) 2016 Simon Boudrias (twitter: [@vaxilart](https://twitter.com/Vaxilart))
406 Licensed under the MIT license.
407
408 ## Plugins
409
410 <a name="plugins"></a>
411
412 ### Prompts
413
414 [**autocomplete**](https://github.com/mokkabonna/inquirer-autocomplete-prompt)<br>
415 Presents a list of options as the user types, compatible with other packages such as fuzzy (for search)<br>
416 <br>
417 ![autocomplete prompt](https://github.com/mokkabonna/inquirer-autocomplete-prompt/raw/master/inquirer.gif)
418
419 [**checkbox-plus**](https://github.com/faressoft/inquirer-checkbox-plus-prompt)<br>
420 Checkbox list with autocomplete and other additions<br>
421 <br>
422 ![checkbox-plus](https://github.com/faressoft/inquirer-checkbox-plus-prompt/raw/master/demo.gif)
423
424 [**datetime**](https://github.com/DerekTBrown/inquirer-datepicker-prompt)<br>
425 Customizable date/time selector using both number pad and arrow keys<br>
426 <br>
427 ![Datetime Prompt](https://github.com/DerekTBrown/inquirer-datepicker-prompt/raw/master/example/datetime-prompt.png)
428
429 [**inquirer-select-line**](https://github.com/adam-golab/inquirer-select-line)<br>
430 Prompt for selecting index in array where add new element<br>
431 <br>
432 ![inquirer-select-line gif](https://media.giphy.com/media/xUA7b1MxpngddUvdHW/giphy.gif)
433
434 [**command**](https://github.com/sullof/inquirer-command-prompt)<br>
435 Simple prompt with command history and dynamic autocomplete<br>
436
437 [**inquirer-fuzzy-path**](https://github.com/adelsz/inquirer-fuzzy-path)<br>
438 Prompt for fuzzy file/directory selection.<br>
439 <br>
440 ![inquirer-fuzzy-path](https://raw.githubusercontent.com/adelsz/inquirer-fuzzy-path/master/recording.gif)
441
442 [**inquirer-emoji**](https://github.com/tannerntannern/inquirer-emoji)<br>
443 Prompt for inputting emojis.<br>
444 <br>
445 ![inquirer-emoji](https://github.com/tannerntannern/inquirer-emoji/raw/master/demo.gif)
446
447 [**inquirer-chalk-pipe**](https://github.com/LitoMore/inquirer-chalk-pipe)<br>
448 Prompt for input chalk-pipe style strings<br>
449 <br>
450 ![inquirer-chalk-pipe](https://github.com/LitoMore/inquirer-chalk-pipe/raw/master/screenshot.gif)
451
452 [**inquirer-search-checkbox**](https://github.com/clinyong/inquirer-search-checkbox)<br>
453 Searchable Inquirer checkbox<br>
454
455 [**inquirer-search-list**](https://github.com/robin-rpr/inquirer-search-list)<br>
456 Searchable Inquirer list<br>
457 <br>
458 ![inquirer-search-list](https://github.com/robin-rpr/inquirer-search-list/blob/master/preview.gif)
459
460 [**inquirer-prompt-suggest**](https://github.com/olistic/inquirer-prompt-suggest)<br>
461 Inquirer prompt for your less creative users.<br>
462 <br>
463 ![inquirer-prompt-suggest](https://user-images.githubusercontent.com/5600126/40391192-d4f3d6d0-5ded-11e8-932f-4b75b642c09e.gif)
464
465 [**inquirer-s3**](https://github.com/HQarroum/inquirer-s3)<br>
466 An S3 object selector for Inquirer.<br>
467 <br>
468 ![inquirer-s3](https://github.com/HQarroum/inquirer-s3/raw/master/docs/inquirer-screenshot.png)
469
470 [**inquirer-autosubmit-prompt**](https://github.com/yaodingyd/inquirer-autosubmit-prompt)<br>
471 Auto submit based on your current input, saving one extra enter<br>
472
473 [**inquirer-file-tree-selection-prompt**](https://github.com/anc95/inquirer-file-tree-selection)<br>
474 Inquirer prompt for to select a file or directory in file tree<br>
475 <br>
476 ![inquirer-file-tree-selection-prompt](https://github.com/anc95/inquirer-file-tree-selection/blob/master/example/screenshot.gif)
477
478 [**inquirer-table-prompt**](https://github.com/eduardoboucas/inquirer-table-prompt)<br>
479 A table-like prompt for Inquirer.<br>
480 <br>
481 ![inquirer-table-prompt](https://raw.githubusercontent.com/eduardoboucas/inquirer-table-prompt/master/screen-capture.gif)