-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.js
executable file
·93 lines (82 loc) · 2.14 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env node
import meow from 'meow';
import logSymbols from 'log-symbols';
import updateNotifier from 'update-notifier';
import errorNotifier from './lib/error-notifier.js';
const cli = meow(
`
Usage
$ onerror <command> [options]
Options
--title, -t Sets the title of the notification.
Default: "An error has occured"
--message, -m Sets the message body of the notification.
Default: "Check the terminal for more information"
--icon, -i Sets an icon. Can be any absolute path.
--sound, -s Defines which sound to use.
Use "mute" to disable default sound notification.
Options: Mute, Basso, Blow, Bottle, Frog, Funk, Glass, Hero,
Morse, Ping, Pop, Purr, Sosumi, Submarine, Tink
Default: Bottle
--version -v Displays the version number.
--help -h Displays the help.
Examples
$ onerror "wget unknown-host.xyz"
$ onerror "wget unknown-host.xyz" -s mute
$ onerror "wget unknown-host.xyz" -t Error -m "My error message"
$ onerror "wget unknown-host.xyz" -s Glass -i https://cdn.rawgit.com/npm/logos/31945b5c/npm%20square/n-64.png
`,
{
importMeta: import.meta,
alias: {
h: 'help',
v: 'version',
},
flags: {
title: {
type: 'string',
alias: 't',
},
message: {
type: 'string',
alias: 'm',
},
icon: {
type: 'string',
alias: 'i',
},
sound: {
type: 'string',
alias: 's',
},
},
},
);
updateNotifier({pkg: cli.pkg}).notify();
if (cli.input.length === 0 && cli.flags.v === true) {
cli.showVersion();
}
if (cli.input.length === 0 && cli.flags.h === true) {
cli.showHelp(0);
}
if (cli.input.length !== 1) {
console.log(
`\n${logSymbols.error} Invalid input. Please check the help below:`,
);
cli.showHelp();
}
if (
Object.keys(cli.flags)
.map((key) => typeof cli.flags[key])
.includes('boolean')
) {
console.log(
`\n${logSymbols.error} Wrong option(s) provided. Please check the help below:`,
);
cli.showHelp();
}
try {
await errorNotifier(cli.input[0], cli.flags);
} catch (error) {
process.exit(error.exitCode);
}