-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·60 lines (45 loc) · 1.16 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
#!/usr/bin/env node
'use strict';
import meow from 'meow';
import chalk from 'chalk';
import updateNotifier from 'update-notifier';
import { readFile } from 'fs/promises';
const pkg = JSON.parse(
await readFile(
new URL('./package.json', import.meta.url)
)
);
import quote from './index.cjs';
const cli = meow(`
Usage
$ wikistats [options]
Options
--number Set number of quotes returned (default: 5)
Examples
$ wikistats
I'm not in the meth business. I'm in the empire business. - Walter White
$ wikistats --number 1
`, {
flag: {
number: {
type: 'string',
default: '1'
}
}
}
);
updateNotifier({ pkg: pkg }).notify();
quote({ input: cli.input[0], flags: cli.flags })
.then(result => {
result.forEach(item => {
console.log(
'• '+ chalk.white(item.quote) + chalk.dim.white(' - ' + item.source) +'\n'
);
});
process.exit(0);
})
.catch(err => {
console.log(err);
console.log(chalk.bold.red(err));
process.exit(1);
});