@kaynooo/cli-proc 0.7.0 → 0.7.1
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 +281 -58
- package/dist/ports-cli.js +303 -74
- package/dist/proc-cli.js +324 -93
- package/dist/procs-cli.js +295 -70
- package/package.json +2 -2
- package/src/ports.ts +7 -6
- package/src/procs.ts +6 -4
package/dist/ports-cli.js
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/ports-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process17 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
|
-
import
|
|
7
|
+
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
9
9
|
|
|
10
10
|
// ../kit/src/format.ts
|
|
11
|
-
import
|
|
11
|
+
import process7 from "process";
|
|
12
|
+
|
|
12
13
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
13
14
|
var N = new Map;
|
|
14
15
|
var Nt = /\s+\S*$/;
|
|
@@ -26,6 +27,7 @@ function ko(t, e, r = "...") {
|
|
|
26
27
|
}
|
|
27
28
|
var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
28
29
|
var z = new Map;
|
|
30
|
+
|
|
29
31
|
// ../kit/src/mode.ts
|
|
30
32
|
import process2 from "process";
|
|
31
33
|
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
@@ -48,7 +50,7 @@ function isInteractive(streams = process2) {
|
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
// ../kit/src/style.ts
|
|
51
|
-
import
|
|
53
|
+
import process6 from "process";
|
|
52
54
|
|
|
53
55
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
54
56
|
var G2 = /^[a-f0-9]+$/i;
|
|
@@ -74,7 +76,7 @@ function C(r, e = globalThis.process?.env ?? {}) {
|
|
|
74
76
|
return false;
|
|
75
77
|
return r?.isTTY === true;
|
|
76
78
|
}
|
|
77
|
-
function
|
|
79
|
+
function f(r, e = []) {
|
|
78
80
|
let l = "", n = "";
|
|
79
81
|
for (let t = 0, i = e.length;t < i; t++)
|
|
80
82
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
@@ -84,7 +86,7 @@ function f2(r, e = []) {
|
|
|
84
86
|
if (Array.isArray(a)) {
|
|
85
87
|
let s = g.get(i);
|
|
86
88
|
if (s === undefined)
|
|
87
|
-
s =
|
|
89
|
+
s = f(r, [...e, a]), g.set(i, s);
|
|
88
90
|
return s;
|
|
89
91
|
}
|
|
90
92
|
if (typeof a === "function")
|
|
@@ -93,30 +95,251 @@ function f2(r, e = []) {
|
|
|
93
95
|
if (u === undefined) {
|
|
94
96
|
if (g.size >= 64)
|
|
95
97
|
g.clear();
|
|
96
|
-
u =
|
|
98
|
+
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
97
99
|
}
|
|
98
100
|
return u;
|
|
99
101
|
};
|
|
100
102
|
throw Error(`Unknown style: ${String(i)}`);
|
|
101
103
|
} });
|
|
102
104
|
}
|
|
103
|
-
function
|
|
104
|
-
return
|
|
105
|
+
function Fe(r = {}) {
|
|
106
|
+
return f(r);
|
|
107
|
+
}
|
|
108
|
+
var o = Fe();
|
|
109
|
+
|
|
110
|
+
// ../kit/src/theme.ts
|
|
111
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
112
|
+
import { homedir as homedir2 } from "os";
|
|
113
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
114
|
+
import process5 from "process";
|
|
115
|
+
|
|
116
|
+
// ../kit/src/config.ts
|
|
117
|
+
import { existsSync } from "fs";
|
|
118
|
+
import { dirname, join, resolve } from "path";
|
|
119
|
+
import process3 from "process";
|
|
120
|
+
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
121
|
+
const wanted = typeof names === "string" ? [names] : names;
|
|
122
|
+
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
123
|
+
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
124
|
+
if (found !== undefined)
|
|
125
|
+
return found;
|
|
126
|
+
if (stop(dir) || dirname(dir) === dir)
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ../kit/src/user-config.ts
|
|
132
|
+
import { homedir } from "os";
|
|
133
|
+
import { join as join2 } from "path";
|
|
134
|
+
import process4 from "process";
|
|
135
|
+
function configBase(where = {}) {
|
|
136
|
+
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
137
|
+
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
138
|
+
}
|
|
139
|
+
function userConfigPath(bin, where = {}) {
|
|
140
|
+
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
105
141
|
}
|
|
106
|
-
var o2 = Fe2();
|
|
107
142
|
|
|
108
143
|
// ../kit/src/theme.ts
|
|
109
144
|
var ENDS = new Map;
|
|
145
|
+
var DEFAULT = {
|
|
146
|
+
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
147
|
+
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
|
|
148
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
149
|
+
bins: {},
|
|
150
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
151
|
+
};
|
|
152
|
+
var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", plan: "magentaBright", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
153
|
+
var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", plan: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
154
|
+
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
155
|
+
var PRESETS = {
|
|
156
|
+
default: {},
|
|
157
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
158
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
159
|
+
ascii: { glyphs: ASCII }
|
|
160
|
+
};
|
|
110
161
|
var STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
|
|
162
|
+
var HEX = /^#[0-9a-f]{6}$/i;
|
|
163
|
+
var CONTROL = /\p{Cc}/u;
|
|
111
164
|
var MAX_FILE_BYTES = 64 * 1024;
|
|
165
|
+
var SPACES = /\s+/;
|
|
166
|
+
function isColorSpec(spec) {
|
|
167
|
+
if (typeof spec === "number")
|
|
168
|
+
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
169
|
+
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
170
|
+
}
|
|
171
|
+
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
172
|
+
function cubeLevel(channel) {
|
|
173
|
+
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
174
|
+
}
|
|
175
|
+
function nearest256(hex) {
|
|
176
|
+
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
177
|
+
const levels = rgb.map(cubeLevel);
|
|
178
|
+
const cube = levels.map((level) => CUBE[level]);
|
|
179
|
+
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
180
|
+
const greyValue = 8 + grey * 10;
|
|
181
|
+
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
182
|
+
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
183
|
+
}
|
|
184
|
+
function hasTrueColor(env) {
|
|
185
|
+
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
186
|
+
}
|
|
187
|
+
function tinted(colors, spec, env = process5.env) {
|
|
188
|
+
if (typeof spec === "number")
|
|
189
|
+
return colors.ansi256(spec);
|
|
190
|
+
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
191
|
+
if (HEX.test(token))
|
|
192
|
+
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
193
|
+
return chain[token] ?? chain;
|
|
194
|
+
}, colors);
|
|
195
|
+
}
|
|
196
|
+
function isRecord(value) {
|
|
197
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
198
|
+
}
|
|
199
|
+
function readThemeFile(path, warn) {
|
|
200
|
+
try {
|
|
201
|
+
const stat = statSync(path, { throwIfNoEntry: false });
|
|
202
|
+
if (stat === undefined)
|
|
203
|
+
return;
|
|
204
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
205
|
+
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
209
|
+
if (isRecord(parsed))
|
|
210
|
+
return parsed;
|
|
211
|
+
warn(`${path} is not a JSON object, theme ignored`);
|
|
212
|
+
} catch (error) {
|
|
213
|
+
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
214
|
+
}
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
function applyPreset(theme, name, warn, where) {
|
|
218
|
+
if (name === undefined)
|
|
219
|
+
return;
|
|
220
|
+
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
221
|
+
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const preset = PRESETS[name];
|
|
225
|
+
Object.assign(theme.colors, preset.colors);
|
|
226
|
+
Object.assign(theme.glyphs, preset.glyphs);
|
|
227
|
+
if (preset.accents !== undefined)
|
|
228
|
+
theme.accents = [...preset.accents];
|
|
229
|
+
if (Object.hasOwn(preset, "gradient"))
|
|
230
|
+
theme.gradient = preset.gradient;
|
|
231
|
+
return name;
|
|
232
|
+
}
|
|
233
|
+
function applyFile(theme, file, where, warn) {
|
|
234
|
+
if (isRecord(file.colors)) {
|
|
235
|
+
for (const [key, value] of Object.entries(file.colors)) {
|
|
236
|
+
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
237
|
+
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
238
|
+
else if (!isColorSpec(value))
|
|
239
|
+
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
240
|
+
else
|
|
241
|
+
theme.colors[key] = value;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
if (isRecord(file.glyphs)) {
|
|
245
|
+
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
246
|
+
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
247
|
+
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
248
|
+
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
249
|
+
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
250
|
+
else
|
|
251
|
+
theme.glyphs[key] = value;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
255
|
+
theme.accents = [...file.accents];
|
|
256
|
+
else if (file.accents !== undefined)
|
|
257
|
+
warn(`${where}: accents must be a non-empty list of colours`);
|
|
258
|
+
if (file.gradient === null)
|
|
259
|
+
theme.gradient = undefined;
|
|
260
|
+
else if (Array.isArray(file.gradient) && file.gradient.length === 2 && file.gradient.every((end) => typeof end === "string" && HEX.test(end)))
|
|
261
|
+
theme.gradient = [file.gradient[0], file.gradient[1]];
|
|
262
|
+
else if (file.gradient !== undefined)
|
|
263
|
+
warn(`${where}: gradient must be two \`#rrggbb\` colours, or null for none`);
|
|
264
|
+
if (isRecord(file.bins)) {
|
|
265
|
+
for (const [bin, value] of Object.entries(file.bins)) {
|
|
266
|
+
if (isColorSpec(value))
|
|
267
|
+
theme.bins[bin] = value;
|
|
268
|
+
else
|
|
269
|
+
warn(`${where}: bin ${bin} has no valid colour`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function endsWalk(home) {
|
|
274
|
+
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
275
|
+
}
|
|
112
276
|
var warned = new Set;
|
|
277
|
+
function warnOnce(message) {
|
|
278
|
+
if (warned.has(message))
|
|
279
|
+
return;
|
|
280
|
+
warned.add(message);
|
|
281
|
+
console.error(`warning: theme ${message}`);
|
|
282
|
+
}
|
|
283
|
+
function isPath(chosen) {
|
|
284
|
+
return chosen.includes("/") || chosen.endsWith(".json");
|
|
285
|
+
}
|
|
286
|
+
function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
287
|
+
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null), gradient: DEFAULT.gradient };
|
|
288
|
+
const sources = [];
|
|
289
|
+
const chosen = env.KIT_THEME ?? "";
|
|
290
|
+
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
291
|
+
if (isPath(chosen))
|
|
292
|
+
wanted.push(resolve2(from, chosen));
|
|
293
|
+
const files = [];
|
|
294
|
+
for (const path of wanted) {
|
|
295
|
+
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
296
|
+
if (path !== undefined && file !== undefined)
|
|
297
|
+
files.push({ path, file });
|
|
298
|
+
}
|
|
299
|
+
let preset = "default";
|
|
300
|
+
if (chosen !== "" && !isPath(chosen)) {
|
|
301
|
+
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
302
|
+
} else {
|
|
303
|
+
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
304
|
+
if (named !== undefined)
|
|
305
|
+
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
306
|
+
}
|
|
307
|
+
for (const { path, file } of files) {
|
|
308
|
+
applyFile(theme, file, path, warn);
|
|
309
|
+
sources.push(path);
|
|
310
|
+
}
|
|
311
|
+
return { theme, sources, preset };
|
|
312
|
+
}
|
|
313
|
+
var current;
|
|
314
|
+
var currentKey = "";
|
|
315
|
+
function activeTheme() {
|
|
316
|
+
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
317
|
+
if (current === undefined || key !== currentKey) {
|
|
318
|
+
current = loadTheme();
|
|
319
|
+
currentKey = key;
|
|
320
|
+
}
|
|
321
|
+
return current;
|
|
322
|
+
}
|
|
113
323
|
|
|
114
324
|
// ../kit/src/style.ts
|
|
115
|
-
|
|
325
|
+
var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
326
|
+
function takesControlCodes(stream, env = process6.env) {
|
|
116
327
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
117
328
|
}
|
|
118
|
-
function paint(stream, env =
|
|
119
|
-
return
|
|
329
|
+
function paint(stream, env = process6.env) {
|
|
330
|
+
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
331
|
+
}
|
|
332
|
+
function marked(mark, text, stream, detail, env = process6.env) {
|
|
333
|
+
const colors = paint(stream, env);
|
|
334
|
+
let head = MARK_WORDS[mark];
|
|
335
|
+
if (takesControlCodes(stream, env)) {
|
|
336
|
+
const { theme } = activeTheme();
|
|
337
|
+
head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
|
|
338
|
+
}
|
|
339
|
+
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
340
|
+
}
|
|
341
|
+
function problem(text, detail) {
|
|
342
|
+
console.error(marked("problem", text, process6.stderr, detail));
|
|
120
343
|
}
|
|
121
344
|
var STATUS_WORDS = {
|
|
122
345
|
passed: ["passed", "success", "succeeded", "ok"],
|
|
@@ -154,7 +377,7 @@ var ESCAPE = String.fromCharCode(27);
|
|
|
154
377
|
function textWidth(text) {
|
|
155
378
|
return Bun.stringWidth(text);
|
|
156
379
|
}
|
|
157
|
-
function table(rows, { cellWidth, header = false, align = [], fit, stream =
|
|
380
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
|
|
158
381
|
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
159
382
|
if (outputMode(stream, env) === "agent")
|
|
160
383
|
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
@@ -193,7 +416,7 @@ function narrow(rows, widths, limit) {
|
|
|
193
416
|
}
|
|
194
417
|
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
195
418
|
}
|
|
196
|
-
function jsonText(value, replacer, { stream =
|
|
419
|
+
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
197
420
|
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
198
421
|
}
|
|
199
422
|
function printJson(value) {
|
|
@@ -201,27 +424,27 @@ function printJson(value) {
|
|
|
201
424
|
}
|
|
202
425
|
|
|
203
426
|
// ../kit/src/help.ts
|
|
204
|
-
import
|
|
427
|
+
import process8 from "process";
|
|
205
428
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
206
429
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
207
430
|
var FULL_STOP = /\.$/;
|
|
208
|
-
function usageLine(usage, colors = paint(
|
|
431
|
+
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
209
432
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
210
433
|
}
|
|
211
|
-
function helpText(usage, options, colors = paint(
|
|
434
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
212
435
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
213
436
|
`);
|
|
214
437
|
}
|
|
215
|
-
function exitRows(exits, colors = paint(
|
|
438
|
+
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
216
439
|
if (exits.length === 0)
|
|
217
440
|
return [];
|
|
218
441
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
219
442
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
220
443
|
}
|
|
221
|
-
function replacesRows(replaces, colors = paint(
|
|
444
|
+
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
222
445
|
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
223
446
|
}
|
|
224
|
-
function wantsHelpJson(env =
|
|
447
|
+
function wantsHelpJson(env = process8.env) {
|
|
225
448
|
return env.KIT_HELP === "json";
|
|
226
449
|
}
|
|
227
450
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -240,12 +463,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
240
463
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
241
464
|
};
|
|
242
465
|
}
|
|
243
|
-
function exampleRows(examples, colors = paint(
|
|
466
|
+
function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
244
467
|
if (examples.length === 0 || outputMode() === "agent")
|
|
245
468
|
return [];
|
|
246
469
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
247
470
|
}
|
|
248
|
-
function optionRows(options, colors = paint(
|
|
471
|
+
function optionRows(options, colors = paint(process8.stdout)) {
|
|
249
472
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
250
473
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
251
474
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -346,7 +569,7 @@ var OUTPUT_OPTIONS = {
|
|
|
346
569
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
347
570
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
348
571
|
};
|
|
349
|
-
function applyOutput(color, plain, env =
|
|
572
|
+
function applyOutput(color, plain, env = process9.env) {
|
|
350
573
|
const when = plain === true ? "never" : color ?? "auto";
|
|
351
574
|
if (when === "auto")
|
|
352
575
|
return;
|
|
@@ -517,7 +740,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
517
740
|
}
|
|
518
741
|
// ../kit/src/process.ts
|
|
519
742
|
import { constants } from "os";
|
|
520
|
-
import
|
|
743
|
+
import process10 from "process";
|
|
521
744
|
var KILL_GRACE_MS = 2000;
|
|
522
745
|
function exitCodeOf(code, signal) {
|
|
523
746
|
if (code !== null)
|
|
@@ -537,7 +760,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
537
760
|
return;
|
|
538
761
|
try {
|
|
539
762
|
if (grouped)
|
|
540
|
-
|
|
763
|
+
process10.kill(-proc.pid, killing);
|
|
541
764
|
else
|
|
542
765
|
proc.kill(killing);
|
|
543
766
|
} catch {}
|
|
@@ -611,15 +834,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
611
834
|
var RESET_STYLE = `${ESC}[0m`;
|
|
612
835
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
613
836
|
// ../kit/src/cli.ts
|
|
614
|
-
import { readFileSync, realpathSync } from "fs";
|
|
615
|
-
import { dirname as
|
|
616
|
-
import
|
|
837
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
838
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
839
|
+
import process12 from "process";
|
|
617
840
|
|
|
618
841
|
// ../kit/src/usage.ts
|
|
619
842
|
import { appendFileSync, mkdirSync } from "fs";
|
|
620
|
-
import { homedir } from "os";
|
|
621
|
-
import { dirname, isAbsolute, join } from "path";
|
|
622
|
-
import
|
|
843
|
+
import { homedir as homedir3 } from "os";
|
|
844
|
+
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
845
|
+
import process11 from "process";
|
|
623
846
|
|
|
624
847
|
// ../kit/src/logs.ts
|
|
625
848
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -633,14 +856,14 @@ var usageError;
|
|
|
633
856
|
function noteUsageError(message) {
|
|
634
857
|
usageError = message;
|
|
635
858
|
}
|
|
636
|
-
function stateHome(env =
|
|
859
|
+
function stateHome(env = process11.env) {
|
|
637
860
|
const dir = env.XDG_STATE_HOME;
|
|
638
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
861
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
639
862
|
}
|
|
640
|
-
function usagePath(env =
|
|
641
|
-
return
|
|
863
|
+
function usagePath(env = process11.env) {
|
|
864
|
+
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
642
865
|
}
|
|
643
|
-
function usageRecorded(env =
|
|
866
|
+
function usageRecorded(env = process11.env) {
|
|
644
867
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
645
868
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
646
869
|
}
|
|
@@ -654,12 +877,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
654
877
|
usageError = undefined;
|
|
655
878
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
656
879
|
}
|
|
657
|
-
function recordUsage(entry, env =
|
|
880
|
+
function recordUsage(entry, env = process11.env) {
|
|
658
881
|
if (!usageRecorded(env))
|
|
659
882
|
return;
|
|
660
883
|
try {
|
|
661
884
|
const path = usagePath(env);
|
|
662
|
-
mkdirSync(
|
|
885
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
663
886
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
664
887
|
`, { mode: 384 });
|
|
665
888
|
} catch {}
|
|
@@ -745,8 +968,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
745
968
|
`);
|
|
746
969
|
}
|
|
747
970
|
function printError(prefix, message, hint, cause) {
|
|
748
|
-
const colors = paint(
|
|
749
|
-
const styled = takesControlCodes(
|
|
971
|
+
const colors = paint(process12.stderr);
|
|
972
|
+
const styled = takesControlCodes(process12.stderr);
|
|
750
973
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
751
974
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
752
975
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -789,11 +1012,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
789
1012
|
}
|
|
790
1013
|
}
|
|
791
1014
|
if (name === undefined && level.path.length > 1) {
|
|
792
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1015
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process12.stderr));
|
|
793
1016
|
return 2;
|
|
794
1017
|
}
|
|
795
1018
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
796
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1019
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process12.stdout));
|
|
797
1020
|
return 0;
|
|
798
1021
|
}
|
|
799
1022
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -910,17 +1133,17 @@ async function printCandidates(found) {
|
|
|
910
1133
|
return 0;
|
|
911
1134
|
}
|
|
912
1135
|
function packageVersion(entry = Bun.main) {
|
|
913
|
-
for (let dir =
|
|
1136
|
+
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
914
1137
|
try {
|
|
915
|
-
const { version } = JSON.parse(
|
|
1138
|
+
const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
|
|
916
1139
|
if (typeof version === "string")
|
|
917
1140
|
return version;
|
|
918
1141
|
} catch {}
|
|
919
|
-
if (
|
|
1142
|
+
if (dirname3(dir) === dir)
|
|
920
1143
|
return "0.0.0";
|
|
921
1144
|
}
|
|
922
1145
|
}
|
|
923
|
-
async function runCli(cli, argv =
|
|
1146
|
+
async function runCli(cli, argv = process12.argv.slice(2)) {
|
|
924
1147
|
const version = cli.version ?? packageVersion();
|
|
925
1148
|
if (argv[0] === COMPLETE)
|
|
926
1149
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -947,7 +1170,7 @@ function commandPath(scope, argv) {
|
|
|
947
1170
|
}
|
|
948
1171
|
return path.length === 0 ? undefined : path.join(" ");
|
|
949
1172
|
}
|
|
950
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1173
|
+
async function runMain({ name, version, run, redact, usage }, argv = process12.argv.slice(2)) {
|
|
951
1174
|
if (argv[0] === COMPLETE)
|
|
952
1175
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
953
1176
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -991,7 +1214,7 @@ function parseSize(text, bareUnit = 1) {
|
|
|
991
1214
|
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
992
1215
|
}
|
|
993
1216
|
// ../kit/src/watch.ts
|
|
994
|
-
import
|
|
1217
|
+
import process13 from "process";
|
|
995
1218
|
import { format } from "util";
|
|
996
1219
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
997
1220
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1013,7 +1236,7 @@ function withoutWatch(args) {
|
|
|
1013
1236
|
}
|
|
1014
1237
|
return rest;
|
|
1015
1238
|
}
|
|
1016
|
-
async function watching(value, step, stream =
|
|
1239
|
+
async function watching(value, step, stream = process13.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1017
1240
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1018
1241
|
if (!takesControlCodes(stream))
|
|
1019
1242
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1021,12 +1244,12 @@ async function watching(value, step, stream = process10.stdout, sleep = Bun.slee
|
|
|
1021
1244
|
for (let round = 0;round < rounds; round++) {
|
|
1022
1245
|
const held = [];
|
|
1023
1246
|
const { log, info } = console;
|
|
1024
|
-
const write =
|
|
1247
|
+
const write = process13.stdout.write.bind(process13.stdout);
|
|
1025
1248
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1026
1249
|
`);
|
|
1027
1250
|
console.log = hold;
|
|
1028
1251
|
console.info = hold;
|
|
1029
|
-
|
|
1252
|
+
process13.stdout.write = (text) => {
|
|
1030
1253
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1031
1254
|
return true;
|
|
1032
1255
|
};
|
|
@@ -1035,7 +1258,7 @@ async function watching(value, step, stream = process10.stdout, sleep = Bun.slee
|
|
|
1035
1258
|
} finally {
|
|
1036
1259
|
console.log = log;
|
|
1037
1260
|
console.info = info;
|
|
1038
|
-
|
|
1261
|
+
process13.stdout.write = write;
|
|
1039
1262
|
}
|
|
1040
1263
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1041
1264
|
await sleep(interval);
|
|
@@ -1044,10 +1267,10 @@ async function watching(value, step, stream = process10.stdout, sleep = Bun.slee
|
|
|
1044
1267
|
}
|
|
1045
1268
|
// src/ports.ts
|
|
1046
1269
|
import { basename as basename2 } from "path";
|
|
1047
|
-
import
|
|
1270
|
+
import process16 from "process";
|
|
1048
1271
|
|
|
1049
1272
|
// ../kit/src/prompt.ts
|
|
1050
|
-
import
|
|
1273
|
+
import process15 from "process";
|
|
1051
1274
|
|
|
1052
1275
|
// ../kit/src/picker/score.ts
|
|
1053
1276
|
var BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
@@ -1057,7 +1280,9 @@ var NONE = Number.NEGATIVE_INFINITY;
|
|
|
1057
1280
|
var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1058
1281
|
var PASTE_START = "\x1B[200~";
|
|
1059
1282
|
var PASTE_END = "\x1B[201~";
|
|
1060
|
-
var KEY_SEQUENCES = /\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1283
|
+
var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1284
|
+
var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1285
|
+
var WHEEL_LINES = 3;
|
|
1061
1286
|
var KEYS = {
|
|
1062
1287
|
"\x1B[A": "up",
|
|
1063
1288
|
"\x1BOA": "up",
|
|
@@ -1086,9 +1311,15 @@ var KEYS = {
|
|
|
1086
1311
|
"\x1BOP": "help",
|
|
1087
1312
|
"\x1B[11~": "help"
|
|
1088
1313
|
};
|
|
1314
|
+
function repeat(value, count) {
|
|
1315
|
+
return Array.from({ length: count }).fill(value);
|
|
1316
|
+
}
|
|
1089
1317
|
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
1090
1318
|
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
1091
1319
|
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
1320
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
1321
|
+
if (wheel !== undefined)
|
|
1322
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
1092
1323
|
const named = codes.get(sequence);
|
|
1093
1324
|
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1094
1325
|
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
@@ -1131,21 +1362,18 @@ function asking(colors, question, typed, keys) {
|
|
|
1131
1362
|
function answer(colors, question, state, picked) {
|
|
1132
1363
|
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1133
1364
|
}
|
|
1134
|
-
async function ask(question, { hint, terminal =
|
|
1365
|
+
async function ask(question, { hint, terminal = process15 }, render, press) {
|
|
1135
1366
|
const { stdin, stderr } = terminal;
|
|
1136
1367
|
if (!isInteractive(terminal))
|
|
1137
1368
|
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
1138
1369
|
const colors = paint(stderr);
|
|
1139
|
-
let drawn = [];
|
|
1140
1370
|
let current = "asking";
|
|
1141
1371
|
let outcome;
|
|
1142
1372
|
const columns = () => stderr.columns || 80;
|
|
1143
|
-
const draw = (state) => {
|
|
1373
|
+
const draw = (state, last = false) => {
|
|
1144
1374
|
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
`)}`);
|
|
1148
|
-
drawn = frame;
|
|
1375
|
+
stderr.write(`\r\x1B[0J${frame.join(`
|
|
1376
|
+
`)}${last || frame.length < 2 ? "" : `\x1B[${frame.length - 1}A`}${last ? "" : "\r"}`);
|
|
1149
1377
|
current = state;
|
|
1150
1378
|
};
|
|
1151
1379
|
const redraw = () => draw(current);
|
|
@@ -1181,7 +1409,7 @@ async function ask(question, { hint, terminal = process12 }, render, press) {
|
|
|
1181
1409
|
});
|
|
1182
1410
|
} finally {
|
|
1183
1411
|
stderr.off?.("resize", redraw);
|
|
1184
|
-
draw(outcome ?? "cancel");
|
|
1412
|
+
draw(outcome ?? "cancel", true);
|
|
1185
1413
|
stderr.write(`
|
|
1186
1414
|
\x1B[?25h\x1B[?2004l`);
|
|
1187
1415
|
stdin.setRawMode(false);
|
|
@@ -1589,6 +1817,7 @@ var options = {
|
|
|
1589
1817
|
watch: watchOption("the ports"),
|
|
1590
1818
|
force: { type: "boolean", description: "with --kill, SIGKILL what SIGTERM did not stop within --grace" },
|
|
1591
1819
|
yes: { type: "boolean", short: "y", description: "with --kill, do not ask first" },
|
|
1820
|
+
quiet: { type: "boolean", short: "q", description: "with --kill, print nothing about what was stopped" },
|
|
1592
1821
|
grace: { type: "string", description: "with --force, how long SIGTERM gets before SIGKILL (5s)" }
|
|
1593
1822
|
};
|
|
1594
1823
|
function buildRows(sockets, owners, procs, containers) {
|
|
@@ -1630,7 +1859,7 @@ function refusal(row, proc, guard) {
|
|
|
1630
1859
|
return reason === undefined ? undefined : `pid ${row.pid} is ${reason}`;
|
|
1631
1860
|
}
|
|
1632
1861
|
function render(rows) {
|
|
1633
|
-
const colors = paint(
|
|
1862
|
+
const colors = paint(process16.stdout);
|
|
1634
1863
|
const cells = rows.map((row) => [
|
|
1635
1864
|
colors.cyan(String(row.port)),
|
|
1636
1865
|
row.protocol,
|
|
@@ -1642,12 +1871,12 @@ function render(rows) {
|
|
|
1642
1871
|
return table([["PORT", "PROTO", "ADDRESS", "PID", "COMMAND", "CWD"], ...cells], { header: true });
|
|
1643
1872
|
}
|
|
1644
1873
|
async function stop(port, rows, procs, values) {
|
|
1645
|
-
const guard = { uid:
|
|
1874
|
+
const guard = { uid: process16.getuid?.() ?? -1, mine: new Set(ancestry(process16.pid, procs)) };
|
|
1646
1875
|
const targets = new Map;
|
|
1647
1876
|
for (const row of rows) {
|
|
1648
1877
|
const reason = refusal(row, row.pid === undefined ? undefined : procs.get(row.pid), guard);
|
|
1649
1878
|
if (reason !== undefined)
|
|
1650
|
-
|
|
1879
|
+
problem(`port ${port}: ${reason}`);
|
|
1651
1880
|
else if (row.pid !== undefined)
|
|
1652
1881
|
targets.set(row.pid, row);
|
|
1653
1882
|
}
|
|
@@ -1655,16 +1884,16 @@ async function stop(port, rows, procs, values) {
|
|
|
1655
1884
|
return 1;
|
|
1656
1885
|
const names = [...targets].map(([pid, row]) => `${pid} (${truncate(row.command ?? "", 40)})`).join(", ");
|
|
1657
1886
|
if (values.yes !== true) {
|
|
1658
|
-
if (!
|
|
1887
|
+
if (!process16.stdin.isTTY)
|
|
1659
1888
|
fail(`stopping ${names} needs a terminal to ask on: pass --yes`, 2);
|
|
1660
1889
|
if (await confirm(`Stop ${names}?`, { default: false }) !== true)
|
|
1661
1890
|
return 1;
|
|
1662
1891
|
}
|
|
1663
1892
|
const outcome = await terminate([...targets.keys()], { escalate: values.force === true, graceMs: duration(values.grace, "grace", 5000) });
|
|
1664
|
-
for (const pid of [...outcome.terminated, ...outcome.killed])
|
|
1893
|
+
for (const pid of values.quiet === true ? [] : [...outcome.terminated, ...outcome.killed])
|
|
1665
1894
|
console.log(`stopped ${pid}${outcome.killed.includes(pid) ? " (SIGKILL)" : ""}`);
|
|
1666
1895
|
for (const pid of outcome.survived)
|
|
1667
|
-
|
|
1896
|
+
problem(`${pid} is still running${values.force === true ? "" : ", pass --force to SIGKILL it"}`);
|
|
1668
1897
|
return outcome.survived.length === 0 ? 0 : 1;
|
|
1669
1898
|
}
|
|
1670
1899
|
async function ports(args) {
|
|
@@ -1686,7 +1915,7 @@ async function ports(args) {
|
|
|
1686
1915
|
badUsage(`<port> takes a whole number from 1 to 65535, not ${given}`);
|
|
1687
1916
|
if (values.kill === true && port === undefined)
|
|
1688
1917
|
badUsage("--kill takes the port to free: ports <port> --kill");
|
|
1689
|
-
const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot("/proc", (uid) => uid ===
|
|
1918
|
+
const [sockets, owners, procs] = await Promise.all([readSockets(), socketOwners(), snapshot("/proc", (uid) => uid === process16.getuid?.())]);
|
|
1690
1919
|
const byPid = new Map(procs.map((proc) => [proc.pid, proc]));
|
|
1691
1920
|
const wanted = sockets.filter((socket) => port === undefined || socket.port === port);
|
|
1692
1921
|
const needsDocker = wanted.some((socket) => {
|
|
@@ -1695,7 +1924,7 @@ async function ports(args) {
|
|
|
1695
1924
|
});
|
|
1696
1925
|
const rows = buildRows(wanted, owners, byPid, needsDocker ? await dockerContainers() : []);
|
|
1697
1926
|
if (port !== undefined && rows.length === 0) {
|
|
1698
|
-
|
|
1927
|
+
problem(`nothing listens on port ${port}`);
|
|
1699
1928
|
return 1;
|
|
1700
1929
|
}
|
|
1701
1930
|
if (values.kill === true && port !== undefined)
|
|
@@ -1707,9 +1936,9 @@ async function ports(args) {
|
|
|
1707
1936
|
console.log(render(rows));
|
|
1708
1937
|
const unknown = rows.filter((row) => row.pid === undefined && row.container === undefined).length;
|
|
1709
1938
|
if (unknown > 0)
|
|
1710
|
-
console.error(paint(
|
|
1939
|
+
console.error(paint(process16.stderr).dim(`${unknown} ${unknown === 1 ? "port has" : "ports have"} an owner this user cannot read, shown as -`));
|
|
1711
1940
|
return 0;
|
|
1712
1941
|
}
|
|
1713
1942
|
|
|
1714
1943
|
// src/ports-cli.ts
|
|
1715
|
-
|
|
1944
|
+
process17.exitCode = await runMain({ name: "ports", run: ports });
|