@commercelayer/cli-ux 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +325 -0
- package/lib/index.d.mts +469 -0
- package/lib/index.d.ts +469 -0
- package/lib/index.js +19 -0
- package/lib/index.mjs +19 -0
- package/package.json +84 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Salesforce.com
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
cli-ux
|
|
2
|
+
======
|
|
3
|
+
|
|
4
|
+
# ========= This module has been deprecated in favor of [oclif/core](https://github.com/oclif/core) and will no longer be maintained. =========
|
|
5
|
+
|
|
6
|
+
cli IO utilities
|
|
7
|
+
|
|
8
|
+
[](https://npmjs.org/package/cli-ux)
|
|
9
|
+
[](https://circleci.com/gh/oclif/cli-ux/tree/main)
|
|
10
|
+
[](https://ci.appveyor.com/project/heroku/cli-ux/branch/main)
|
|
11
|
+
[](https://snyk.io/test/npm/cli-ux)
|
|
12
|
+
[](https://npmjs.org/package/cli-ux)
|
|
13
|
+
[](https://github.com/oclif/cli-ux/blob/main/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
|
+
JavaScript:
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
const {cli} = require('cli-ux')
|
|
28
|
+
|
|
29
|
+
cli.prompt('What is your name?')
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
# cli.prompt()
|
|
33
|
+
|
|
34
|
+
Prompt for user input.
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
// just prompt for input
|
|
38
|
+
await cli.prompt('What is your name?')
|
|
39
|
+
|
|
40
|
+
// mask input after enter is pressed
|
|
41
|
+
await cli.prompt('What is your two-factor token?', {type: 'mask'})
|
|
42
|
+
|
|
43
|
+
// mask input on keypress (before enter is pressed)
|
|
44
|
+
await cli.prompt('What is your password?', {type: 'hide'})
|
|
45
|
+
|
|
46
|
+
// yes/no confirmation
|
|
47
|
+
await cli.confirm('Continue?')
|
|
48
|
+
|
|
49
|
+
// "press any key to continue"
|
|
50
|
+
await cli.anykey()
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+

|
|
54
|
+
|
|
55
|
+
# cli.url(text, uri)
|
|
56
|
+
|
|
57
|
+
Create a hyperlink (if supported in the terminal)
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
await cli.url('sometext', 'https://google.com')
|
|
61
|
+
// shows sometext as a hyperlink in supported terminals
|
|
62
|
+
// shows https://google.com in unsupported terminals
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+

|
|
66
|
+
|
|
67
|
+
# cli.open
|
|
68
|
+
|
|
69
|
+
Open a url in the browser
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
await cli.open('https://oclif.io')
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
# cli.action
|
|
76
|
+
|
|
77
|
+
Shows a spinner
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
// start the spinner
|
|
81
|
+
cli.action.start('starting a process')
|
|
82
|
+
// show on stdout instead of stderr
|
|
83
|
+
cli.action.start('starting a process', 'initializing', {stdout: true})
|
|
84
|
+
|
|
85
|
+
// stop the spinner
|
|
86
|
+
cli.action.stop() // shows 'starting a process... done'
|
|
87
|
+
cli.action.stop('custom message') // shows 'starting a process... custom message'
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
This degrades gracefully when not connected to a TTY. It queues up any writes to stdout/stderr so they are displayed above the spinner.
|
|
91
|
+
|
|
92
|
+

|
|
93
|
+
|
|
94
|
+
# cli.annotation
|
|
95
|
+
|
|
96
|
+
Shows an iterm annotation
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
cli.annotation('sometext', 'annotated with this text')
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+

|
|
103
|
+
|
|
104
|
+
# cli.wait
|
|
105
|
+
|
|
106
|
+
Waits for 1 second or given milliseconds
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
await cli.wait()
|
|
110
|
+
await cli.wait(3000)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
# cli.table
|
|
114
|
+
|
|
115
|
+
Displays tabular data
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
cli.table(data, columns, options)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Where:
|
|
122
|
+
|
|
123
|
+
- `data`: array of data objects to display
|
|
124
|
+
- `columns`: [Table.Columns](./src/styled/table.ts)
|
|
125
|
+
- `options`: [Table.Options](./src/styled/table.ts)
|
|
126
|
+
|
|
127
|
+
`cli.table.flags()` returns an object containing all the table flags to include in your command.
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
{
|
|
131
|
+
columns: Flags.string({exclusive: ['additional'], description: 'only show provided columns (comma-separated)'}),
|
|
132
|
+
sort: Flags.string({description: 'property to sort by (prepend '-' for descending)'}),
|
|
133
|
+
filter: Flags.string({description: 'filter property by partial string matching, ex: name=foo'}),
|
|
134
|
+
csv: Flags.boolean({exclusive: ['no-truncate'], description: 'output is csv format'}),
|
|
135
|
+
extended: Flags.boolean({char: 'x', description: 'show extra columns'}),
|
|
136
|
+
'no-truncate': Flags.boolean({exclusive: ['csv'], description: 'do not truncate output to fit screen'}),
|
|
137
|
+
'no-header': Flags.boolean({exclusive: ['csv'], description: 'hide table header from output'}),
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Passing `{only: ['columns']}` or `{except: ['columns']}` as an argument into `cli.table.flags()` will allow/block those flags from the returned object.
|
|
142
|
+
|
|
143
|
+
`Table.Columns` defines the table columns and their display options.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
const columns: Table.Columns = {
|
|
147
|
+
// where `.name` is a property of a data object
|
|
148
|
+
name: {}, // "Name" inferred as the column header
|
|
149
|
+
id: {
|
|
150
|
+
header: 'ID', // override column header
|
|
151
|
+
minWidth: '10', // column must display at this width or greater
|
|
152
|
+
extended: true, // only display this column when the --extended flag is present
|
|
153
|
+
get: row => `US-O1-${row.id}`, // custom getter for data row object
|
|
154
|
+
},
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
`Table.Options` defines the table options, most of which are the parsed flags from the user for display customization, all of which are optional.
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
const options: Table.Options = {
|
|
162
|
+
printLine: myLogger, // custom logger
|
|
163
|
+
columns: flags.columns,
|
|
164
|
+
sort: flags.sort,
|
|
165
|
+
filter: flags.filter,
|
|
166
|
+
csv: flags.csv,
|
|
167
|
+
extended: flags.extended,
|
|
168
|
+
'no-truncate': flags['no-truncate'],
|
|
169
|
+
'no-header': flags['no-header'],
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Example class:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
import {Command} from '@oclif/core'
|
|
177
|
+
import {cli} from 'cli-ux'
|
|
178
|
+
import axios from 'axios'
|
|
179
|
+
|
|
180
|
+
export default class Users extends Command {
|
|
181
|
+
static flags = {
|
|
182
|
+
...cli.table.flags()
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
async run() {
|
|
186
|
+
const {flags} = this.parse(Users)
|
|
187
|
+
const {data: users} = await axios.get('https://jsonplaceholder.typicode.com/users')
|
|
188
|
+
|
|
189
|
+
cli.table(users, {
|
|
190
|
+
name: {
|
|
191
|
+
minWidth: 7,
|
|
192
|
+
},
|
|
193
|
+
company: {
|
|
194
|
+
get: row => row.company && row.company.name
|
|
195
|
+
},
|
|
196
|
+
id: {
|
|
197
|
+
header: 'ID',
|
|
198
|
+
extended: true
|
|
199
|
+
}
|
|
200
|
+
}, {
|
|
201
|
+
printLine: this.log,
|
|
202
|
+
...flags, // parsed flags
|
|
203
|
+
})
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Displays:
|
|
209
|
+
|
|
210
|
+
```shell
|
|
211
|
+
$ example-cli users
|
|
212
|
+
Name Company
|
|
213
|
+
Leanne Graham Romaguera-Crona
|
|
214
|
+
Ervin Howell Deckow-Crist
|
|
215
|
+
Clementine Bauch Romaguera-Jacobson
|
|
216
|
+
Patricia Lebsack Robel-Corkery
|
|
217
|
+
Chelsey Dietrich Keebler LLC
|
|
218
|
+
Mrs. Dennis Schulist Considine-Lockman
|
|
219
|
+
Kurtis Weissnat Johns Group
|
|
220
|
+
Nicholas Runolfsdottir V Abernathy Group
|
|
221
|
+
Glenna Reichert Yost and Sons
|
|
222
|
+
Clementina DuBuque Hoeger LLC
|
|
223
|
+
|
|
224
|
+
$ example-cli users --extended
|
|
225
|
+
Name Company ID
|
|
226
|
+
Leanne Graham Romaguera-Crona 1
|
|
227
|
+
Ervin Howell Deckow-Crist 2
|
|
228
|
+
Clementine Bauch Romaguera-Jacobson 3
|
|
229
|
+
Patricia Lebsack Robel-Corkery 4
|
|
230
|
+
Chelsey Dietrich Keebler LLC 5
|
|
231
|
+
Mrs. Dennis Schulist Considine-Lockman 6
|
|
232
|
+
Kurtis Weissnat Johns Group 7
|
|
233
|
+
Nicholas Runolfsdottir V Abernathy Group 8
|
|
234
|
+
Glenna Reichert Yost and Sons 9
|
|
235
|
+
Clementina DuBuque Hoeger LLC 10
|
|
236
|
+
|
|
237
|
+
$ example-cli users --columns=name
|
|
238
|
+
Name
|
|
239
|
+
Leanne Graham
|
|
240
|
+
Ervin Howell
|
|
241
|
+
Clementine Bauch
|
|
242
|
+
Patricia Lebsack
|
|
243
|
+
Chelsey Dietrich
|
|
244
|
+
Mrs. Dennis Schulist
|
|
245
|
+
Kurtis Weissnat
|
|
246
|
+
Nicholas Runolfsdottir V
|
|
247
|
+
Glenna Reichert
|
|
248
|
+
Clementina DuBuque
|
|
249
|
+
|
|
250
|
+
$ example-cli users --filter="company=Group"
|
|
251
|
+
Name Company
|
|
252
|
+
Kurtis Weissnat Johns Group
|
|
253
|
+
Nicholas Runolfsdottir V Abernathy Group
|
|
254
|
+
|
|
255
|
+
$ example-cli users --sort=company
|
|
256
|
+
Name Company
|
|
257
|
+
Nicholas Runolfsdottir V Abernathy Group
|
|
258
|
+
Mrs. Dennis Schulist Considine-Lockman
|
|
259
|
+
Ervin Howell Deckow-Crist
|
|
260
|
+
Clementina DuBuque Hoeger LLC
|
|
261
|
+
Kurtis Weissnat Johns Group
|
|
262
|
+
Chelsey Dietrich Keebler LLC
|
|
263
|
+
Patricia Lebsack Robel-Corkery
|
|
264
|
+
Leanne Graham Romaguera-Crona
|
|
265
|
+
Clementine Bauch Romaguera-Jacobson
|
|
266
|
+
Glenna Reichert Yost and Sons
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
# cli.tree
|
|
270
|
+
|
|
271
|
+
Generate a tree and display it
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
let tree = cli.tree()
|
|
275
|
+
tree.insert('foo')
|
|
276
|
+
tree.insert('bar')
|
|
277
|
+
|
|
278
|
+
let subtree = cli.tree()
|
|
279
|
+
subtree.insert('qux')
|
|
280
|
+
tree.nodes.bar.insert('baz', subtree)
|
|
281
|
+
|
|
282
|
+
tree.display()
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
Outputs:
|
|
286
|
+
```shell
|
|
287
|
+
├─ foo
|
|
288
|
+
└─ bar
|
|
289
|
+
└─ baz
|
|
290
|
+
└─ qux
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
# cli.progress
|
|
294
|
+
|
|
295
|
+
Generate a customizable progress bar and display it
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
const simpleBar = cli.progress()
|
|
299
|
+
simpleBar.start()
|
|
300
|
+
|
|
301
|
+
const customBar = cli.progress({
|
|
302
|
+
format: 'PROGRESS | {bar} | {value}/{total} Files',
|
|
303
|
+
barCompleteChar: '\u2588',
|
|
304
|
+
barIncompleteChar: '\u2591',
|
|
305
|
+
})
|
|
306
|
+
customBar.start()
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
Outputs:
|
|
310
|
+
```shell
|
|
311
|
+
bar1:
|
|
312
|
+
progress [=====================-------------------] 53% | ETA: 1s | 53/100
|
|
313
|
+
bar2:
|
|
314
|
+
PROGRESS | █████████████████████████████░░░░░░░░░░░ | 146/204 Files
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
To see a more detailed example, run
|
|
318
|
+
```shell script
|
|
319
|
+
$ ts-node examples/progress.ts
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
This extends [cli-progress](https://www.npmjs.com/package/cli-progress)
|
|
323
|
+
see all of the options and customizations there, which can be passed in with the options object.
|
|
324
|
+
Only the single bar variant of cli-progress is currently supported.
|
|
325
|
+
|