Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for killing by port (using a colon to indicate port usage) #27

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const psList = require('ps-list');
const numSort = require('num-sort');
const escExit = require('esc-exit');
const cliTruncate = require('cli-truncate');
const portToProc = require('portproc').portToProc;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would have been more readable as:

const portToProcess = require('portproc').portToProcess;

Not really worth saving a few characters for limited gain.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you extract the CLI in portproc into a separate package? I don't want to needlessly have commander in the dependency tree. See: sindresorhus/ama#17


const cli = meow(`
Usage
Expand Down Expand Up @@ -96,5 +97,8 @@ function handleFkillError(processes) {
if (cli.input.length === 0) {
init(cli.flags);
} else {
fkill(cli.input, cli.flags).catch(() => handleFkillError(cli.input));
Promise.all(cli.input.map(x => x[0] === ':' ? portToProc(parseInt(x.slice(1), 10)) : x))
.then(pids => pids.filter(pid => pid))
.then(pids => fkill(pids, cli.flags))
.catch(() => handleFkillError(cli.input));
Copy link
Contributor

@kevva kevva Jun 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will swallow errors from portToProc which may be unintended here. We only want to handle errors from fkill.

}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"inquirer-autocomplete-prompt": "^0.7.0",
"meow": "^3.3.0",
"num-sort": "^1.0.0",
"portproc": "^1.0.2",
"ps-list": "^3.0.0"
},
"devDependencies": {
Expand Down