-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
executable file
·89 lines (78 loc) · 1.55 KB
/
index.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env node
const modules = require('./modules')
const {parseArgs} = require('node:util')
const version = require('./package.json').version
const readline = require('readline')
const options = {
version: {
type: 'boolean',
short: 'v',
},
help: {
type: 'boolean',
short: 'h',
},
words: {
type: 'string',
short: 'w',
},
min: {
type: 'string',
short: 'm',
default: '0',
},
max: {
type: 'string',
short: 'M',
default: '80',
},
output: {
type: 'string',
short: 'o',
},
}
const {values} = parseArgs({options})
function commandLine() {
if (values.version) {
console.log(version)
return
}
if (values.help) {
console.log(`
Usage: smangler [options]
Options:
-h, --help Show this help message and exit.
-v, --version Show the version and exit.
-w, --words [string] One or multiple words comma separated
-m, --min [number] Minimum length (default: ${options.min.default})
-M, --max [number] Max length (default: ${options.max.default})
`)
return
}
if (values.words) {
modules.run(values)
return
}
processFromStdin(values)
}
function processFromStdin(values) {
const rl = readline.createInterface({
input: process.stdin,
})
rl.on('line', line => {
modules.run({
...values,
words: line.trim(),
})
})
}
if (require.main === module) {
commandLine()
} else {
module.exports = opts =>
modules.run({
...values,
...opts,
lib: true,
})
}