1 | cli-ux
|
2 | ======
|
3 |
|
4 | cli IO utilities
|
5 |
|
6 | [![Version](https://img.shields.io/npm/v/cli-ux.svg)](https://npmjs.org/package/cli-ux)
|
7 | [![CircleCI](https://circleci.com/gh/oclif/cli-ux/tree/master.svg?style=svg)](https://circleci.com/gh/oclif/cli-ux/tree/master)
|
8 | [![Appveyor CI](https://ci.appveyor.com/api/projects/status/github/oclif/cli-ux?branch=master&svg=true)](https://ci.appveyor.com/project/heroku/cli-ux/branch/master)
|
9 | [![Codecov](https://codecov.io/gh/oclif/cli-ux/branch/master/graph/badge.svg)](https://codecov.io/gh/oclif/cli-ux)
|
10 | [![Greenkeeper](https://badges.greenkeeper.io/oclif/cli-ux.svg)](https://greenkeeper.io/)
|
11 | [![Known Vulnerabilities](https://snyk.io/test/npm/cli-ux/badge.svg)](https://snyk.io/test/npm/cli-ux)
|
12 | [![Downloads/week](https://img.shields.io/npm/dw/cli-ux.svg)](https://npmjs.org/package/cli-ux)
|
13 | [![License](https://img.shields.io/npm/l/cli-ux.svg)](https://github.com/oclif/cli-ux/blob/master/package.json)
|
14 |
|
15 | # Usage
|
16 |
|
17 | The following assumes you have installed `cli-ux` to your project with `npm install cli-ux` or `yarn add cli-ux` and have it required in your script (TypeScript example):
|
18 |
|
19 | ```typescript
|
20 | import cli from 'cli-ux'
|
21 | cli.prompt('What is your name?')
|
22 | ```
|
23 |
|
24 | # cli.prompt()
|
25 |
|
26 | Prompt for user input.
|
27 |
|
28 | ```typescript
|
29 | // just prompt for input
|
30 | await cli.prompt('What is your name?')
|
31 |
|
32 | // mask input after enter is pressed
|
33 | await cli.prompt('What is your two-factor token?', {type: 'mask'})
|
34 |
|
35 | // mask input on keypress (before enter is pressed)
|
36 | await cli.prompt('What is your password?', {type: 'hide'})
|
37 | ```
|
38 |
|
39 | ![prompt demo](assets/prompt.gif)
|
40 |
|
41 | # cli.url(text, uri)
|
42 |
|
43 | Create a hyperlink (if supported in the terminal)
|
44 |
|
45 | ```typescript
|
46 | await cli.prompt('sometext', 'https://google.com')
|
47 | // shows sometext as a hyperlink in supported terminals
|
48 | // shows https://google.com in unsupported terminals
|
49 | ```
|
50 |
|
51 | ![url demo](assets/url.gif)
|
52 |
|
53 | # cli.action
|
54 |
|
55 | Shows a spinner
|
56 |
|
57 | ```typescript
|
58 | // start the spinner
|
59 | cli.action.start('starting a process')
|
60 | // show on stdout instead of stderr
|
61 | cli.action.start('starting a process', {stdout: true})
|
62 |
|
63 | // stop the spinner
|
64 | cli.action.stop() // shows 'starting a process... done'
|
65 | cli.action.stop('custom message') // shows 'starting a process... custom message'
|
66 | ```
|
67 |
|
68 | This degrades gracefully when not connected to a TTY. It queues up any writes to stdout/stderr so they are displayed above the spinner.
|
69 |
|
70 | ![action demo](assets/action.gif)
|
71 |
|
72 | # annotation
|
73 |
|
74 | Shows an iterm annotation
|
75 |
|
76 | ```typescript
|
77 | // start the spinner
|
78 | cli.annotation('sometest', 'annotated with this text')
|
79 | ```
|
80 |
|
81 | ![annotation demo](assets/annotation.png)
|