@kaynooo/cli-proc 0.7.1 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pid-cli.js +69 -46
- package/dist/ports-cli.js +75 -52
- package/dist/proc-cli.js +88 -65
- package/dist/procs-cli.js +72 -49
- package/package.json +2 -2
- package/src/pid.ts +4 -3
- package/src/ports.ts +4 -3
- package/src/procs.ts +4 -3
package/dist/ports-cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/ports-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process18 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -431,18 +431,14 @@ var FULL_STOP = /\.$/;
|
|
|
431
431
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
432
432
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
433
433
|
}
|
|
434
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [],
|
|
435
|
-
return [usageLine(usage, colors),
|
|
434
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
435
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
436
436
|
`);
|
|
437
437
|
}
|
|
438
438
|
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
439
439
|
if (exits.length === 0)
|
|
440
440
|
return [];
|
|
441
|
-
|
|
442
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
443
|
-
}
|
|
444
|
-
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
445
|
-
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
441
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
446
442
|
}
|
|
447
443
|
function wantsHelpJson(env = process8.env) {
|
|
448
444
|
return env.KIT_HELP === "json";
|
|
@@ -738,9 +734,33 @@ function nearestOption(message, options, allowNegative) {
|
|
|
738
734
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
739
735
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
740
736
|
}
|
|
737
|
+
// ../kit/src/argv.ts
|
|
738
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
739
|
+
import { resolve as resolve3 } from "path";
|
|
740
|
+
import process10 from "process";
|
|
741
|
+
function commandLine() {
|
|
742
|
+
try {
|
|
743
|
+
return readFileSync2("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
744
|
+
} catch {
|
|
745
|
+
return;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
function realPath(word) {
|
|
749
|
+
try {
|
|
750
|
+
return realpathSync(resolve3(word));
|
|
751
|
+
} catch {
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
|
|
756
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
757
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
758
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
759
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
760
|
+
}
|
|
741
761
|
// ../kit/src/process.ts
|
|
742
762
|
import { constants } from "os";
|
|
743
|
-
import
|
|
763
|
+
import process11 from "process";
|
|
744
764
|
var KILL_GRACE_MS = 2000;
|
|
745
765
|
function exitCodeOf(code, signal) {
|
|
746
766
|
if (code !== null)
|
|
@@ -760,7 +780,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
760
780
|
return;
|
|
761
781
|
try {
|
|
762
782
|
if (grouped)
|
|
763
|
-
|
|
783
|
+
process11.kill(-proc.pid, killing);
|
|
764
784
|
else
|
|
765
785
|
proc.kill(killing);
|
|
766
786
|
} catch {}
|
|
@@ -834,15 +854,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
834
854
|
var RESET_STYLE = `${ESC}[0m`;
|
|
835
855
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
836
856
|
// ../kit/src/cli.ts
|
|
837
|
-
import { readFileSync as
|
|
857
|
+
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
838
858
|
import { dirname as dirname3, join as join5 } from "path";
|
|
839
|
-
import
|
|
859
|
+
import process13 from "process";
|
|
840
860
|
|
|
841
861
|
// ../kit/src/usage.ts
|
|
842
862
|
import { appendFileSync, mkdirSync } from "fs";
|
|
843
863
|
import { homedir as homedir3 } from "os";
|
|
844
864
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
845
|
-
import
|
|
865
|
+
import process12 from "process";
|
|
846
866
|
|
|
847
867
|
// ../kit/src/logs.ts
|
|
848
868
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -856,14 +876,14 @@ var usageError;
|
|
|
856
876
|
function noteUsageError(message) {
|
|
857
877
|
usageError = message;
|
|
858
878
|
}
|
|
859
|
-
function stateHome(env =
|
|
879
|
+
function stateHome(env = process12.env) {
|
|
860
880
|
const dir = env.XDG_STATE_HOME;
|
|
861
881
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
862
882
|
}
|
|
863
|
-
function usagePath(env =
|
|
883
|
+
function usagePath(env = process12.env) {
|
|
864
884
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
865
885
|
}
|
|
866
|
-
function usageRecorded(env =
|
|
886
|
+
function usageRecorded(env = process12.env) {
|
|
867
887
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
868
888
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
869
889
|
}
|
|
@@ -877,7 +897,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
877
897
|
usageError = undefined;
|
|
878
898
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
879
899
|
}
|
|
880
|
-
function recordUsage(entry, env =
|
|
900
|
+
function recordUsage(entry, env = process12.env) {
|
|
881
901
|
if (!usageRecorded(env))
|
|
882
902
|
return;
|
|
883
903
|
try {
|
|
@@ -954,7 +974,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
954
974
|
header(colors, summary),
|
|
955
975
|
"",
|
|
956
976
|
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
957
|
-
...replacesRows(replaces, colors),
|
|
958
977
|
"",
|
|
959
978
|
...await commandRows(commands, colors),
|
|
960
979
|
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
@@ -968,8 +987,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
968
987
|
`);
|
|
969
988
|
}
|
|
970
989
|
function printError(prefix, message, hint, cause) {
|
|
971
|
-
const colors = paint(
|
|
972
|
-
const styled = takesControlCodes(
|
|
990
|
+
const colors = paint(process13.stderr);
|
|
991
|
+
const styled = takesControlCodes(process13.stderr);
|
|
973
992
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
974
993
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
975
994
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1012,11 +1031,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1012
1031
|
}
|
|
1013
1032
|
}
|
|
1014
1033
|
if (name === undefined && level.path.length > 1) {
|
|
1015
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1034
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stderr));
|
|
1016
1035
|
return 2;
|
|
1017
1036
|
}
|
|
1018
1037
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1019
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1038
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stdout));
|
|
1020
1039
|
return 0;
|
|
1021
1040
|
}
|
|
1022
1041
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1072,24 +1091,24 @@ function candidateLine(candidate) {
|
|
|
1072
1091
|
}
|
|
1073
1092
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
1074
1093
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1075
|
-
|
|
1094
|
+
const typed = [];
|
|
1076
1095
|
let at = 0;
|
|
1077
1096
|
while (at < before.length) {
|
|
1078
1097
|
const word = before[at];
|
|
1079
1098
|
if (word === "--") {
|
|
1080
|
-
|
|
1099
|
+
typed.push(...before.slice(at + 1));
|
|
1081
1100
|
break;
|
|
1082
1101
|
}
|
|
1083
1102
|
if (!word.startsWith("-"))
|
|
1084
|
-
|
|
1103
|
+
typed.push(word);
|
|
1085
1104
|
else if (takesValue(word))
|
|
1086
1105
|
at++;
|
|
1087
1106
|
at++;
|
|
1088
1107
|
}
|
|
1089
1108
|
const last = positionals.at(-1);
|
|
1090
|
-
if (
|
|
1091
|
-
return positionals[
|
|
1092
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1109
|
+
if (typed.length < positionals.length)
|
|
1110
|
+
return { name: positionals[typed.length], typed };
|
|
1111
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1093
1112
|
}
|
|
1094
1113
|
async function leafCandidates(run, words) {
|
|
1095
1114
|
const completing = await completingOf(run);
|
|
@@ -1097,12 +1116,12 @@ async function leafCandidates(run, words) {
|
|
|
1097
1116
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1098
1117
|
const flag = words.at(-2);
|
|
1099
1118
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1119
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1100
1120
|
if (option?.type === "string") {
|
|
1101
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1121
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1102
1122
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1103
1123
|
}
|
|
1104
|
-
const
|
|
1105
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1124
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1106
1125
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1107
1126
|
}
|
|
1108
1127
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
@@ -1133,9 +1152,13 @@ async function printCandidates(found) {
|
|
|
1133
1152
|
return 0;
|
|
1134
1153
|
}
|
|
1135
1154
|
function packageVersion(entry = Bun.main) {
|
|
1136
|
-
|
|
1155
|
+
let resolved = entry;
|
|
1156
|
+
try {
|
|
1157
|
+
resolved = realpathSync2(entry);
|
|
1158
|
+
} catch {}
|
|
1159
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1137
1160
|
try {
|
|
1138
|
-
const { version } = JSON.parse(
|
|
1161
|
+
const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
|
|
1139
1162
|
if (typeof version === "string")
|
|
1140
1163
|
return version;
|
|
1141
1164
|
} catch {}
|
|
@@ -1143,7 +1166,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
1143
1166
|
return "0.0.0";
|
|
1144
1167
|
}
|
|
1145
1168
|
}
|
|
1146
|
-
async function runCli(cli, argv =
|
|
1169
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
1147
1170
|
const version = cli.version ?? packageVersion();
|
|
1148
1171
|
if (argv[0] === COMPLETE)
|
|
1149
1172
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1170,7 +1193,7 @@ function commandPath(scope, argv) {
|
|
|
1170
1193
|
}
|
|
1171
1194
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1172
1195
|
}
|
|
1173
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1196
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1174
1197
|
if (argv[0] === COMPLETE)
|
|
1175
1198
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1176
1199
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1214,7 +1237,7 @@ function parseSize(text, bareUnit = 1) {
|
|
|
1214
1237
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1215
1238
|
}
|
|
1216
1239
|
// ../kit/src/watch.ts
|
|
1217
|
-
import
|
|
1240
|
+
import process14 from "process";
|
|
1218
1241
|
import { format } from "util";
|
|
1219
1242
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1220
1243
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1236,7 +1259,7 @@ function withoutWatch(args) {
|
|
|
1236
1259
|
}
|
|
1237
1260
|
return rest;
|
|
1238
1261
|
}
|
|
1239
|
-
async function watching(value, step, stream =
|
|
1262
|
+
async function watching(value, step, stream = process14.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1240
1263
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1241
1264
|
if (!takesControlCodes(stream))
|
|
1242
1265
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1244,12 +1267,12 @@ async function watching(value, step, stream = process13.stdout, sleep = Bun.slee
|
|
|
1244
1267
|
for (let round = 0;round < rounds; round++) {
|
|
1245
1268
|
const held = [];
|
|
1246
1269
|
const { log, info } = console;
|
|
1247
|
-
const write =
|
|
1270
|
+
const write = process14.stdout.write.bind(process14.stdout);
|
|
1248
1271
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1249
1272
|
`);
|
|
1250
1273
|
console.log = hold;
|
|
1251
1274
|
console.info = hold;
|
|
1252
|
-
|
|
1275
|
+
process14.stdout.write = (text) => {
|
|
1253
1276
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1254
1277
|
return true;
|
|
1255
1278
|
};
|
|
@@ -1258,7 +1281,7 @@ async function watching(value, step, stream = process13.stdout, sleep = Bun.slee
|
|
|
1258
1281
|
} finally {
|
|
1259
1282
|
console.log = log;
|
|
1260
1283
|
console.info = info;
|
|
1261
|
-
|
|
1284
|
+
process14.stdout.write = write;
|
|
1262
1285
|
}
|
|
1263
1286
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1264
1287
|
await sleep(interval);
|
|
@@ -1267,10 +1290,10 @@ async function watching(value, step, stream = process13.stdout, sleep = Bun.slee
|
|
|
1267
1290
|
}
|
|
1268
1291
|
// src/ports.ts
|
|
1269
1292
|
import { basename as basename2 } from "path";
|
|
1270
|
-
import
|
|
1293
|
+
import process17 from "process";
|
|
1271
1294
|
|
|
1272
1295
|
// ../kit/src/prompt.ts
|
|
1273
|
-
import
|
|
1296
|
+
import process16 from "process";
|
|
1274
1297
|
|
|
1275
1298
|
// ../kit/src/picker/score.ts
|
|
1276
1299
|
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
@@ -1362,7 +1385,7 @@ function asking(colors, question, typed, keys) {
|
|
|
1362
1385
|
function answer(colors, question, state, picked) {
|
|
1363
1386
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1364
1387
|
}
|
|
1365
|
-
async function ask(question, { hint, terminal =
|
|
1388
|
+
async function ask(question, { hint, terminal = process16 }, render, press) {
|
|
1366
1389
|
const { stdin, stderr } = terminal;
|
|
1367
1390
|
if (!isInteractive(terminal))
|
|
1368
1391
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
@@ -1808,9 +1831,8 @@ var usage2 = `ports [port]
|
|
|
1808
1831
|
|
|
1809
1832
|
Lists what listens on this machine, TCP and UDP over IPv4 and IPv6, one row per port with its bound address, the owning process, its command and its working directory. A port Docker publishes is held by docker-proxy, and shows as its compose project and service when docker is installed; the owner of a socket of another user cannot be read and shows as -.
|
|
1810
1833
|
\`ports <port>\` keeps that port alone and exits 1 when nothing listens on it.
|
|
1811
|
-
\`ports <port> --kill\` stops its owner with SIGTERM, and with --force SIGKILL once --grace has passed, after asking on a terminal unless --yes is given. It refuses processes of other users, pid 1, this command and its ancestors, and docker-proxy, for which it names the container to stop instead
|
|
1812
|
-
|
|
1813
|
-
Exits 0 when it listed or stopped, 1 when nothing listens on the given port or the owner could not be stopped, 2 on a usage error.`;
|
|
1834
|
+
\`ports <port> --kill\` stops its owner with SIGTERM, and with --force SIGKILL once --grace has passed, after asking on a terminal unless --yes is given. It refuses processes of other users, pid 1, this command and its ancestors, and docker-proxy, for which it names the container to stop instead.`;
|
|
1835
|
+
var EXITS = [[0, "it listed or stopped"], [1, "nothing listens on the given port or the owner could not be stopped"], [2, "a usage error"]];
|
|
1814
1836
|
var options = {
|
|
1815
1837
|
json: jsonOption("[{ port, protocol, addresses, pid, command, cwd, container }]"),
|
|
1816
1838
|
kill: { type: "boolean", conflicts: ["watch"], description: "stop the owner of the given port" },
|
|
@@ -1859,7 +1881,7 @@ function refusal(row, proc, guard) {
|
|
|
1859
1881
|
return reason === undefined ? undefined : `pid ${row.pid} is ${reason}`;
|
|
1860
1882
|
}
|
|
1861
1883
|
function render(rows) {
|
|
1862
|
-
const colors = paint(
|
|
1884
|
+
const colors = paint(process17.stdout);
|
|
1863
1885
|
const cells = rows.map((row) => [
|
|
1864
1886
|
colors.cyan(String(row.port)),
|
|
1865
1887
|
row.protocol,
|
|
@@ -1871,7 +1893,7 @@ function render(rows) {
|
|
|
1871
1893
|
return table([["PORT", "PROTO", "ADDRESS", "PID", "COMMAND", "CWD"], ...cells], { header: true });
|
|
1872
1894
|
}
|
|
1873
1895
|
async function stop(port, rows, procs, values) {
|
|
1874
|
-
const guard = { uid:
|
|
1896
|
+
const guard = { uid: process17.getuid?.() ?? -1, mine: new Set(ancestry(process17.pid, procs)) };
|
|
1875
1897
|
const targets = new Map;
|
|
1876
1898
|
for (const row of rows) {
|
|
1877
1899
|
const reason = refusal(row, row.pid === undefined ? undefined : procs.get(row.pid), guard);
|
|
@@ -1884,7 +1906,7 @@ async function stop(port, rows, procs, values) {
|
|
|
1884
1906
|
return 1;
|
|
1885
1907
|
const names = [...targets].map(([pid, row]) => `${pid} (${truncate(row.command ?? "", 40)})`).join(", ");
|
|
1886
1908
|
if (values.yes !== true) {
|
|
1887
|
-
if (!
|
|
1909
|
+
if (!process17.stdin.isTTY)
|
|
1888
1910
|
fail(`stopping ${names} needs a terminal to ask on: pass --yes`, 2);
|
|
1889
1911
|
if (await confirm(`Stop ${names}?`, { default: false }) !== true)
|
|
1890
1912
|
return 1;
|
|
@@ -1898,6 +1920,7 @@ async function stop(port, rows, procs, values) {
|
|
|
1898
1920
|
}
|
|
1899
1921
|
async function ports(args) {
|
|
1900
1922
|
const { values, positionals } = parse(args, usage2, options, {
|
|
1923
|
+
exits: EXITS,
|
|
1901
1924
|
positionals: ["[port]"],
|
|
1902
1925
|
replaces: "ss -ltnp | grep, lsof -i, fuser -k and lookups of docker-proxy by hand",
|
|
1903
1926
|
examples: [
|
|
@@ -1915,7 +1938,7 @@ async function ports(args) {
|
|
|
1915
1938
|
badUsage(`<port> takes a whole number from 1 to 65535, not ${given}`);
|
|
1916
1939
|
if (values.kill === true && port === undefined)
|
|
1917
1940
|
badUsage("--kill takes the port to free: ports <port> --kill");
|
|
1918
|
-
const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot("/proc", (uid) => uid ===
|
|
1941
|
+
const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot("/proc", (uid) => uid === process17.getuid?.())]);
|
|
1919
1942
|
const byPid = new Map(procs.map((proc) => [proc.pid, proc]));
|
|
1920
1943
|
const wanted = sockets.filter((socket) => port === undefined || socket.port === port);
|
|
1921
1944
|
const needsDocker = wanted.some((socket) => {
|
|
@@ -1936,9 +1959,9 @@ async function ports(args) {
|
|
|
1936
1959
|
console.log(render(rows));
|
|
1937
1960
|
const unknown = rows.filter((row) => row.pid === undefined && row.container === undefined).length;
|
|
1938
1961
|
if (unknown > 0)
|
|
1939
|
-
console.error(paint(
|
|
1962
|
+
console.error(paint(process17.stderr).dim(`${unknown} ${unknown === 1 ? "port has" : "ports have"} an owner this user cannot read, shown as -`));
|
|
1940
1963
|
return 0;
|
|
1941
1964
|
}
|
|
1942
1965
|
|
|
1943
1966
|
// src/ports-cli.ts
|
|
1944
|
-
|
|
1967
|
+
process18.exitCode = await runMain({ name: "ports", run: ports });
|