forked from sindresorhus/fkill-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·63 lines (55 loc) · 1.2 KB
/
cli.js
File metadata and controls
executable file
·63 lines (55 loc) · 1.2 KB
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
#!/usr/bin/env node
'use strict';
const meow = require('meow');
const fkill = require('fkill');
const cli = meow(`
Usage
$ fkill [<pid|name|:port> …]
Options
--force -f Force kill
--verbose -v Show process arguments
--silent -s Silently kill and always exit with code 0
Examples
$ fkill 1337
$ fkill safari
$ fkill :8080
$ fkill 1337 safari :8080
$ fkill
To kill a port, prefix it with a colon. For example: :8080.
Run without arguments to use the interactive interface.
The process name is case insensitive.
`, {
inferType: true,
flags: {
force: {
type: 'boolean',
alias: 'f'
},
verbose: {
type: 'boolean',
alias: 'v'
},
silent: {
type: 'boolean',
alias: 's'
}
}
});
if (cli.input.length === 0) {
require('./interactive').init(cli.flags);
} else {
const promise = fkill(cli.input, {...cli.flags, ignoreCase: true});
if (cli.flags.silent) {
promise.catch(error => {
return;
});
} else if (!cli.flags.force) {
promise.catch(error => {
if (/Couldn't find a process with port/.test(error.message)) {
console.error(error.message);
process.exit(1);
}
return require('./interactive').handleFkillError(cli.input);
});
}
}