-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·67 lines (54 loc) · 1.08 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env node
import meow from 'meow'
import stdin from 'get-stdin'
import cuid from 'cuid'
const cli = meow(`$ cuid --help
Usage
$ cuid [--slug] [number]
$ echo [number] | cuid [--slug]
Options
-s, --slug Get slug
Examples
$ cuid
ciyefyc630000x0y7mhd8o67n
$ cuid 4
ciyefyc630000x0y7mhd8o67n
ciyefyc650001x0y7f9rqtegv
ciyefyc650002x0y7e9826mhe
ciyefyc650003x0y7az4v96ec
$ cuid --slug
1m0z7cm
$ cuid 4 --slug
1m0z7cm
1n1z7om
1o2z7ud
1o3z73h
$ echo '4' | cuid --slug
1m0z7cm
1n1z7om
1o2z7ud
1o3z73h
`, {
flags: {
slug: {
type: 'boolean',
alias: 's',
default: false
}
}
})
const {input: [input], flags} = cli
const {slug = false} = flags
const init = async ({data = 1, slug = false}) => {
const cmd = slug === true ? cuid.slug : cuid
const loop = Number(data || 1)
Array.from({length: loop}).map(() => console.log(cmd()))
};
(async () => {
if (input) {
init({data: input, slug})
} else {
const data = await stdin()
init({data, slug})
}
})()