@kaynooo/cli-stack 0.7.1 → 0.8.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/README.md +2 -19
- package/dist/cli.js +525 -621
- package/package.json +7 -7
package/dist/cli.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
2
|
// @bun
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
var __esm = (fn, res, err) => () => {
|
|
4
|
+
if (fn)
|
|
5
|
+
try {
|
|
6
|
+
res = fn(fn = 0);
|
|
7
|
+
} catch (e) {
|
|
8
|
+
err = [e];
|
|
9
|
+
}
|
|
10
|
+
if (err)
|
|
11
|
+
throw err[0];
|
|
12
|
+
return res;
|
|
13
|
+
};
|
|
12
14
|
|
|
13
15
|
// ../kit/src/mode.ts
|
|
14
16
|
import process2 from "process";
|
|
15
|
-
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
16
|
-
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
17
17
|
function isSet(value) {
|
|
18
18
|
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
19
19
|
}
|
|
@@ -27,12 +27,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
27
27
|
return "terminal";
|
|
28
28
|
return isSet(env.CI) ? "ci" : "pipe";
|
|
29
29
|
}
|
|
30
|
+
var MODES, AGENT_VARIABLES;
|
|
31
|
+
var init_mode = __esm(() => {
|
|
32
|
+
MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
33
|
+
AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
34
|
+
});
|
|
30
35
|
|
|
31
|
-
//
|
|
32
|
-
import process6 from "process";
|
|
33
|
-
|
|
34
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
35
|
-
var G = /^[a-f0-9]+$/i;
|
|
36
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
36
37
|
function b(r) {
|
|
37
38
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
38
39
|
if (!G.test(e))
|
|
@@ -43,11 +44,6 @@ function b(r) {
|
|
|
43
44
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
44
45
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
45
46
|
}
|
|
46
|
-
var B = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
47
|
-
let [l, n, c] = b(r);
|
|
48
|
-
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
49
|
-
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
50
|
-
var h = new Set(["", "1", "2", "3", "true"]);
|
|
51
47
|
function C(r, e = globalThis.process?.env ?? {}) {
|
|
52
48
|
if (e.FORCE_COLOR !== undefined)
|
|
53
49
|
return h.has(e.FORCE_COLOR);
|
|
@@ -84,13 +80,21 @@ function f(r, e = []) {
|
|
|
84
80
|
function Fe(r = {}) {
|
|
85
81
|
return f(r);
|
|
86
82
|
}
|
|
87
|
-
var
|
|
83
|
+
var G, B, h, o;
|
|
84
|
+
var init_chunk_x450vn3m = __esm(() => {
|
|
85
|
+
G = /^[a-f0-9]+$/i;
|
|
86
|
+
B = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
87
|
+
let [l, n, c] = b(r);
|
|
88
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
89
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
90
|
+
h = new Set(["", "1", "2", "3", "true"]);
|
|
91
|
+
o = Fe();
|
|
92
|
+
});
|
|
88
93
|
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
import process5 from "process";
|
|
94
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
|
|
95
|
+
var init_colors = __esm(() => {
|
|
96
|
+
init_chunk_x450vn3m();
|
|
97
|
+
});
|
|
94
98
|
|
|
95
99
|
// ../kit/src/config.ts
|
|
96
100
|
import { existsSync } from "fs";
|
|
@@ -106,48 +110,36 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
106
110
|
return;
|
|
107
111
|
}
|
|
108
112
|
}
|
|
113
|
+
var init_config = __esm(() => {
|
|
114
|
+
init_args();
|
|
115
|
+
});
|
|
109
116
|
|
|
110
117
|
// ../kit/src/user-config.ts
|
|
111
118
|
import { homedir } from "os";
|
|
112
|
-
import { join as join2 } from "path";
|
|
119
|
+
import { isAbsolute, join as join2 } from "path";
|
|
113
120
|
import process4 from "process";
|
|
121
|
+
function xdgFolder(value, fallback) {
|
|
122
|
+
return value !== undefined && isAbsolute(value) ? value : fallback;
|
|
123
|
+
}
|
|
114
124
|
function configBase(where = {}) {
|
|
115
125
|
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
116
|
-
return xdg
|
|
126
|
+
return xdgFolder(xdg, join2(where.home ?? homedir(), ".config"));
|
|
117
127
|
}
|
|
118
128
|
function userConfigPath(bin, where = {}) {
|
|
119
129
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
120
130
|
}
|
|
131
|
+
var init_user_config = () => {};
|
|
121
132
|
|
|
122
133
|
// ../kit/src/theme.ts
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
128
|
-
bins: {},
|
|
129
|
-
gradient: ["#c084fc", "#67e8f9"]
|
|
130
|
-
};
|
|
131
|
-
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" };
|
|
132
|
-
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" };
|
|
133
|
-
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
134
|
-
var PRESETS = {
|
|
135
|
-
default: {},
|
|
136
|
-
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
137
|
-
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
138
|
-
ascii: { glyphs: ASCII }
|
|
139
|
-
};
|
|
140
|
-
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"]);
|
|
141
|
-
var HEX = /^#[0-9a-f]{6}$/i;
|
|
142
|
-
var CONTROL = /\p{Cc}/u;
|
|
143
|
-
var MAX_FILE_BYTES = 64 * 1024;
|
|
144
|
-
var SPACES = /\s+/;
|
|
134
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
135
|
+
import { homedir as homedir2 } from "os";
|
|
136
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
137
|
+
import process5 from "process";
|
|
145
138
|
function isColorSpec(spec) {
|
|
146
139
|
if (typeof spec === "number")
|
|
147
140
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
148
141
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
149
142
|
}
|
|
150
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
151
143
|
function cubeLevel(channel) {
|
|
152
144
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
153
145
|
}
|
|
@@ -252,7 +244,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
252
244
|
function endsWalk(home) {
|
|
253
245
|
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
254
246
|
}
|
|
255
|
-
var warned = new Set;
|
|
256
247
|
function warnOnce(message) {
|
|
257
248
|
if (warned.has(message))
|
|
258
249
|
return;
|
|
@@ -289,8 +280,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
289
280
|
}
|
|
290
281
|
return { theme, sources, preset };
|
|
291
282
|
}
|
|
292
|
-
var current;
|
|
293
|
-
var currentKey = "";
|
|
294
283
|
function activeTheme() {
|
|
295
284
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
296
285
|
if (current === undefined || key !== currentKey) {
|
|
@@ -299,9 +288,38 @@ function activeTheme() {
|
|
|
299
288
|
}
|
|
300
289
|
return current;
|
|
301
290
|
}
|
|
291
|
+
var ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
|
|
292
|
+
var init_theme = __esm(() => {
|
|
293
|
+
init_config();
|
|
294
|
+
init_user_config();
|
|
295
|
+
ENDS = new Map;
|
|
296
|
+
DEFAULT = {
|
|
297
|
+
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" },
|
|
298
|
+
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" },
|
|
299
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
300
|
+
bins: {},
|
|
301
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
302
|
+
};
|
|
303
|
+
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" };
|
|
304
|
+
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" };
|
|
305
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
306
|
+
PRESETS = {
|
|
307
|
+
default: {},
|
|
308
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
309
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
310
|
+
ascii: { glyphs: ASCII }
|
|
311
|
+
};
|
|
312
|
+
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"]);
|
|
313
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
314
|
+
CONTROL = /\p{Cc}/u;
|
|
315
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
316
|
+
SPACES = /\s+/;
|
|
317
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
318
|
+
warned = new Set;
|
|
319
|
+
});
|
|
302
320
|
|
|
303
321
|
// ../kit/src/style.ts
|
|
304
|
-
|
|
322
|
+
import process6 from "process";
|
|
305
323
|
function takesControlCodes(stream, env = process6.env) {
|
|
306
324
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
307
325
|
}
|
|
@@ -320,48 +338,91 @@ function marked(mark, text, stream, detail, env = process6.env) {
|
|
|
320
338
|
function warn(text, detail) {
|
|
321
339
|
console.error(marked("warn", text, process6.stderr, detail));
|
|
322
340
|
}
|
|
323
|
-
var STATUS_WORDS
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
341
|
+
var MARK_WORDS, STATUS_WORDS, STATUS_OF;
|
|
342
|
+
var init_style = __esm(() => {
|
|
343
|
+
init_colors();
|
|
344
|
+
init_mode();
|
|
345
|
+
init_theme();
|
|
346
|
+
MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
347
|
+
STATUS_WORDS = {
|
|
348
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
349
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
350
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
351
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
352
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
353
|
+
};
|
|
354
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
355
|
+
});
|
|
331
356
|
|
|
332
357
|
// ../kit/src/format.ts
|
|
358
|
+
import process7 from "process";
|
|
359
|
+
function formatSeconds(total) {
|
|
360
|
+
let rest = Math.max(0, Math.round(total));
|
|
361
|
+
const amounts = UNITS.map(([unit, size]) => {
|
|
362
|
+
const amount = Math.floor(rest / size);
|
|
363
|
+
rest -= amount * size;
|
|
364
|
+
return `${amount}${unit}`;
|
|
365
|
+
});
|
|
366
|
+
const first = amounts.findIndex((amount) => !amount.startsWith("0"));
|
|
367
|
+
if (first === -1)
|
|
368
|
+
return "0s";
|
|
369
|
+
const next = amounts[first + 1];
|
|
370
|
+
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
371
|
+
}
|
|
372
|
+
function formatDuration(ms) {
|
|
373
|
+
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
374
|
+
}
|
|
333
375
|
function upTo(text, separator) {
|
|
334
376
|
const end = text.indexOf(separator);
|
|
335
377
|
return end === -1 ? text : text.slice(0, end);
|
|
336
378
|
}
|
|
337
|
-
var ESCAPE = String.fromCharCode(27);
|
|
338
379
|
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
339
380
|
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
340
381
|
}
|
|
341
382
|
function printJson(value) {
|
|
342
383
|
console.log(jsonText(value));
|
|
343
384
|
}
|
|
385
|
+
var UNITS, ESCAPE;
|
|
386
|
+
var init_format = __esm(() => {
|
|
387
|
+
init_mode();
|
|
388
|
+
init_style();
|
|
389
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
390
|
+
ESCAPE = String.fromCharCode(27);
|
|
391
|
+
});
|
|
344
392
|
|
|
345
393
|
// ../kit/src/help.ts
|
|
346
394
|
import process8 from "process";
|
|
347
|
-
var OPTIONAL = /\[[^\]]+\]/g;
|
|
348
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
349
|
-
var FULL_STOP = /\.$/;
|
|
350
395
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
351
|
-
|
|
396
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
397
|
+
`);
|
|
398
|
+
const blank = lines.indexOf("");
|
|
399
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
400
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
401
|
+
const colon = synopses[0].indexOf(": ");
|
|
402
|
+
const inline = synopses[0].slice(colon + 2);
|
|
403
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
404
|
+
if (colon !== -1)
|
|
405
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
406
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
407
|
+
`)}`;
|
|
408
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
409
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
410
|
+
return [head, ...lead, ...rest].join(`
|
|
411
|
+
`);
|
|
412
|
+
}
|
|
413
|
+
function prose(line, colors) {
|
|
414
|
+
if (colors.cyan("x") === "x")
|
|
415
|
+
return line;
|
|
416
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
352
417
|
}
|
|
353
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [],
|
|
354
|
-
return [usageLine(usage, colors),
|
|
418
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
419
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
355
420
|
`);
|
|
356
421
|
}
|
|
357
422
|
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
358
423
|
if (exits.length === 0)
|
|
359
424
|
return [];
|
|
360
|
-
|
|
361
|
-
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
362
|
-
}
|
|
363
|
-
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
364
|
-
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
425
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
365
426
|
}
|
|
366
427
|
function wantsHelpJson(env = process8.env) {
|
|
367
428
|
return env.KIT_HELP === "json";
|
|
@@ -390,26 +451,45 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
390
451
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
391
452
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
392
453
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
393
|
-
const
|
|
454
|
+
const choices = option.choices?.join("|");
|
|
455
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
456
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
394
457
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
395
458
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
396
|
-
|
|
459
|
+
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
460
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
397
461
|
});
|
|
398
462
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
399
463
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
400
464
|
}
|
|
465
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
466
|
+
var init_help = __esm(() => {
|
|
467
|
+
init_mode();
|
|
468
|
+
init_style();
|
|
469
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
470
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
471
|
+
FULL_STOP = /\.$/;
|
|
472
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
473
|
+
});
|
|
401
474
|
|
|
402
475
|
// ../kit/src/text.ts
|
|
403
|
-
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
404
476
|
function distance(a, b) {
|
|
405
|
-
|
|
406
|
-
|
|
477
|
+
const left = [...a];
|
|
478
|
+
const right = [...b];
|
|
479
|
+
let before = [];
|
|
480
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
481
|
+
for (const [i, x] of left.entries()) {
|
|
407
482
|
const current = [i + 1];
|
|
408
|
-
for (const [j,
|
|
409
|
-
|
|
483
|
+
for (const [j, y] of right.entries()) {
|
|
484
|
+
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
485
|
+
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
486
|
+
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
487
|
+
current.push(cost);
|
|
488
|
+
}
|
|
489
|
+
before = previous;
|
|
410
490
|
previous = current;
|
|
411
491
|
}
|
|
412
|
-
return previous[
|
|
492
|
+
return previous[right.length] ?? 0;
|
|
413
493
|
}
|
|
414
494
|
function closest(name, names) {
|
|
415
495
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -418,8 +498,9 @@ function closest(name, names) {
|
|
|
418
498
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
419
499
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
420
500
|
}
|
|
501
|
+
var init_text = () => {};
|
|
502
|
+
|
|
421
503
|
// ../kit/src/input.ts
|
|
422
|
-
var WHOLE = /^\d+$/;
|
|
423
504
|
function wholeNumber(value, name, fallback, min = 1) {
|
|
424
505
|
if (value === undefined)
|
|
425
506
|
return fallback;
|
|
@@ -428,40 +509,25 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
428
509
|
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
429
510
|
return number;
|
|
430
511
|
}
|
|
512
|
+
var WHOLE;
|
|
513
|
+
var init_input = __esm(() => {
|
|
514
|
+
init_args();
|
|
515
|
+
WHOLE = /^\d+$/;
|
|
516
|
+
});
|
|
431
517
|
|
|
432
518
|
// ../kit/src/args.ts
|
|
433
|
-
|
|
519
|
+
import process9 from "process";
|
|
520
|
+
import { parseArgs } from "util";
|
|
434
521
|
function jsonOption(holds) {
|
|
435
522
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
436
523
|
}
|
|
437
|
-
class Exit extends Error {
|
|
438
|
-
code;
|
|
439
|
-
hint;
|
|
440
|
-
constructor(message, code, hint) {
|
|
441
|
-
super(message);
|
|
442
|
-
this.code = code;
|
|
443
|
-
this.hint = hint;
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
524
|
function fail(message, code = 2, hint) {
|
|
447
525
|
throw new Exit(message, code, hint);
|
|
448
526
|
}
|
|
449
|
-
|
|
450
|
-
class UsageError extends Exit {
|
|
451
|
-
constructor(message, hint) {
|
|
452
|
-
super(message, 2, hint);
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
527
|
function badUsage(message) {
|
|
456
528
|
throw new UsageError(message);
|
|
457
529
|
}
|
|
458
530
|
|
|
459
|
-
class HelpShown extends Exit {
|
|
460
|
-
constructor() {
|
|
461
|
-
super("help shown", 0);
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
531
|
class Completing {
|
|
466
532
|
options;
|
|
467
533
|
positionals;
|
|
@@ -472,11 +538,6 @@ class Completing {
|
|
|
472
538
|
this.candidates = candidates;
|
|
473
539
|
}
|
|
474
540
|
}
|
|
475
|
-
var completion = { active: false };
|
|
476
|
-
var OUTPUT_OPTIONS = {
|
|
477
|
-
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
478
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
479
|
-
};
|
|
480
541
|
function applyOutput(color, plain, env = process9.env) {
|
|
481
542
|
const when = plain === true ? "never" : color ?? "auto";
|
|
482
543
|
if (when === "auto")
|
|
@@ -630,7 +691,6 @@ function parseError(error) {
|
|
|
630
691
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
631
692
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
632
693
|
}
|
|
633
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
634
694
|
function nearestOption(message, options, allowNegative) {
|
|
635
695
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
636
696
|
if (typed === undefined)
|
|
@@ -646,27 +706,255 @@ function nearestOption(message, options, allowNegative) {
|
|
|
646
706
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
647
707
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
648
708
|
}
|
|
709
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
710
|
+
var init_args = __esm(() => {
|
|
711
|
+
init_format();
|
|
712
|
+
init_help();
|
|
713
|
+
init_text();
|
|
714
|
+
init_help();
|
|
715
|
+
init_input();
|
|
716
|
+
DASHES = /^-+/;
|
|
717
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
718
|
+
Exit = class Exit extends Error {
|
|
719
|
+
code;
|
|
720
|
+
hint;
|
|
721
|
+
[EXIT] = true;
|
|
722
|
+
constructor(message, code, hint) {
|
|
723
|
+
super(message);
|
|
724
|
+
this.code = code;
|
|
725
|
+
this.hint = hint;
|
|
726
|
+
}
|
|
727
|
+
static [Symbol.hasInstance](value) {
|
|
728
|
+
if (this !== Exit)
|
|
729
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
730
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
UsageError = class UsageError extends Exit {
|
|
734
|
+
constructor(message, hint) {
|
|
735
|
+
super(message, 2, hint);
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
HelpShown = class HelpShown extends Exit {
|
|
739
|
+
constructor() {
|
|
740
|
+
super("help shown", 0);
|
|
741
|
+
}
|
|
742
|
+
};
|
|
743
|
+
completion = { active: false };
|
|
744
|
+
OUTPUT_OPTIONS = {
|
|
745
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
746
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
747
|
+
};
|
|
748
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
749
|
+
});
|
|
750
|
+
|
|
751
|
+
// ../kit/src/folders.ts
|
|
752
|
+
var SKIPPED_FOLDERS;
|
|
753
|
+
var init_folders = __esm(() => {
|
|
754
|
+
init_user_config();
|
|
755
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
// src/cli.ts
|
|
759
|
+
import process16 from "process";
|
|
760
|
+
|
|
761
|
+
// ../kit/src/index.ts
|
|
762
|
+
init_args();
|
|
763
|
+
|
|
764
|
+
// ../kit/src/argv.ts
|
|
765
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
766
|
+
import { resolve as resolve3 } from "path";
|
|
767
|
+
import process10 from "process";
|
|
768
|
+
function commandLine() {
|
|
769
|
+
try {
|
|
770
|
+
return readFileSync2("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
771
|
+
} catch {
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
function realPath(word) {
|
|
776
|
+
try {
|
|
777
|
+
return realpathSync(resolve3(word));
|
|
778
|
+
} catch {
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
|
|
783
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
784
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
785
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
786
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
787
|
+
}
|
|
788
|
+
// ../kit/src/chart.ts
|
|
789
|
+
init_format();
|
|
790
|
+
init_mode();
|
|
791
|
+
init_style();
|
|
792
|
+
init_theme();
|
|
793
|
+
// ../kit/src/ci.ts
|
|
794
|
+
init_args();
|
|
795
|
+
init_format();
|
|
796
|
+
|
|
797
|
+
// ../kit/src/progress.ts
|
|
798
|
+
init_format();
|
|
799
|
+
|
|
800
|
+
// ../kit/src/process.ts
|
|
801
|
+
var GROUP_SIGNALS = new Set(["SIGINT", "SIGHUP"]);
|
|
802
|
+
|
|
649
803
|
// ../kit/src/progress.ts
|
|
804
|
+
init_style();
|
|
805
|
+
init_theme();
|
|
650
806
|
var ESC = String.fromCharCode(27);
|
|
651
807
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
652
808
|
var RESET_STYLE = `${ESC}[0m`;
|
|
653
809
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
810
|
+
|
|
811
|
+
// ../kit/src/ci.ts
|
|
812
|
+
init_style();
|
|
813
|
+
|
|
814
|
+
// ../kit/src/tool.ts
|
|
815
|
+
init_format();
|
|
654
816
|
// ../kit/src/cli.ts
|
|
655
|
-
|
|
817
|
+
init_args();
|
|
818
|
+
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
656
819
|
import { dirname as dirname3, join as join5 } from "path";
|
|
820
|
+
import process14 from "process";
|
|
821
|
+
|
|
822
|
+
// ../kit/src/askpass.ts
|
|
657
823
|
import process11 from "process";
|
|
824
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
825
|
+
async function askpassClient(argv) {
|
|
826
|
+
const socketPath = process11.env[SOCKET_VARIABLE];
|
|
827
|
+
if (socketPath === undefined)
|
|
828
|
+
return;
|
|
829
|
+
const request = { prompt: argv[0] ?? "", ...process11.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
830
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
831
|
+
let received = "";
|
|
832
|
+
try {
|
|
833
|
+
await Bun.connect({
|
|
834
|
+
unix: socketPath,
|
|
835
|
+
socket: {
|
|
836
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
837
|
+
`),
|
|
838
|
+
data: (_, chunk) => {
|
|
839
|
+
received += chunk.toString();
|
|
840
|
+
},
|
|
841
|
+
close: () => resolve(received),
|
|
842
|
+
error: () => resolve("")
|
|
843
|
+
}
|
|
844
|
+
});
|
|
845
|
+
} catch {
|
|
846
|
+
return 1;
|
|
847
|
+
}
|
|
848
|
+
const reply = await promise;
|
|
849
|
+
if (reply === "")
|
|
850
|
+
return 1;
|
|
851
|
+
const { answer } = JSON.parse(reply);
|
|
852
|
+
if (request.notice === true)
|
|
853
|
+
return 0;
|
|
854
|
+
if (answer === undefined)
|
|
855
|
+
return 1;
|
|
856
|
+
process11.stdout.write(`${answer}
|
|
857
|
+
`);
|
|
858
|
+
return 0;
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// ../kit/src/completions.ts
|
|
862
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
863
|
+
var FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
|
|
864
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
865
|
+
set -l current (commandline -ct)
|
|
866
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
867
|
+
if test "$line" = __files__
|
|
868
|
+
__fish_complete_path $current
|
|
869
|
+
else
|
|
870
|
+
echo $line
|
|
871
|
+
end
|
|
872
|
+
end
|
|
873
|
+
end`;
|
|
874
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
875
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
876
|
+
local -a lines
|
|
877
|
+
COMPREPLY=()
|
|
878
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
879
|
+
for line in "\${lines[@]}"; do
|
|
880
|
+
if [[ $line == __files__ ]]; then
|
|
881
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
882
|
+
else
|
|
883
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
884
|
+
fi
|
|
885
|
+
done
|
|
886
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
887
|
+
}`;
|
|
888
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
889
|
+
local line
|
|
890
|
+
local -a described plain
|
|
891
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
892
|
+
if [[ $line == __files__ ]]; then
|
|
893
|
+
_files
|
|
894
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
895
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
896
|
+
else
|
|
897
|
+
plain+=("$line")
|
|
898
|
+
fi
|
|
899
|
+
done
|
|
900
|
+
(( \${#described} )) && _describe -V value described
|
|
901
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
902
|
+
return 0
|
|
903
|
+
}`;
|
|
904
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
905
|
+
if (shell === "fish")
|
|
906
|
+
return `${header}
|
|
907
|
+
${FISH_FUNCTION}
|
|
908
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
909
|
+
`).join("")}`;
|
|
910
|
+
if (shell === "bash")
|
|
911
|
+
return `${header}
|
|
912
|
+
${BASH_FUNCTION}
|
|
913
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
914
|
+
`;
|
|
915
|
+
return `${header}
|
|
916
|
+
${ZSH_FUNCTION}
|
|
917
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
918
|
+
`;
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// ../kit/src/notify.ts
|
|
922
|
+
init_format();
|
|
923
|
+
init_mode();
|
|
924
|
+
import process12 from "process";
|
|
925
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
926
|
+
var CANCELLED = 130;
|
|
927
|
+
function base64(text) {
|
|
928
|
+
return Buffer.from(text).toString("base64");
|
|
929
|
+
}
|
|
930
|
+
function notification(title, body, env = process12.env) {
|
|
931
|
+
const id = `kit${process12.pid}`;
|
|
932
|
+
const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
|
|
933
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
934
|
+
}
|
|
935
|
+
function notifyEnd(command, code, ms, { stream = process12.stderr, env = process12.env } = {}) {
|
|
936
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
937
|
+
return;
|
|
938
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
// ../kit/src/cli.ts
|
|
942
|
+
init_style();
|
|
943
|
+
init_text();
|
|
658
944
|
|
|
659
945
|
// ../kit/src/usage.ts
|
|
660
946
|
import { appendFileSync, mkdirSync } from "fs";
|
|
661
947
|
import { homedir as homedir3 } from "os";
|
|
662
|
-
import { dirname as dirname2,
|
|
663
|
-
import
|
|
948
|
+
import { dirname as dirname2, join as join4 } from "path";
|
|
949
|
+
import process13 from "process";
|
|
664
950
|
|
|
665
951
|
// ../kit/src/logs.ts
|
|
952
|
+
init_user_config();
|
|
666
953
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
667
954
|
var CLI_FOLDER = "kaynooo-cli";
|
|
668
955
|
|
|
669
956
|
// ../kit/src/usage.ts
|
|
957
|
+
init_user_config();
|
|
670
958
|
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
671
959
|
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
672
960
|
var LONGEST_NAME = 40;
|
|
@@ -674,14 +962,13 @@ var usageError;
|
|
|
674
962
|
function noteUsageError(message) {
|
|
675
963
|
usageError = message;
|
|
676
964
|
}
|
|
677
|
-
function stateHome(env =
|
|
678
|
-
|
|
679
|
-
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
965
|
+
function stateHome(env = process13.env) {
|
|
966
|
+
return xdgFolder(env.XDG_STATE_HOME, join4(homedir3(), ".local", "state"));
|
|
680
967
|
}
|
|
681
|
-
function usagePath(env =
|
|
968
|
+
function usagePath(env = process13.env) {
|
|
682
969
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
683
970
|
}
|
|
684
|
-
function usageRecorded(env =
|
|
971
|
+
function usageRecorded(env = process13.env) {
|
|
685
972
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
686
973
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
687
974
|
}
|
|
@@ -690,12 +977,12 @@ function flagNames(argv) {
|
|
|
690
977
|
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
691
978
|
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
692
979
|
}
|
|
693
|
-
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
980
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
694
981
|
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
695
982
|
usageError = undefined;
|
|
696
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
983
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
697
984
|
}
|
|
698
|
-
function recordUsage(entry, env =
|
|
985
|
+
function recordUsage(entry, env = process13.env) {
|
|
699
986
|
if (!usageRecorded(env))
|
|
700
987
|
return;
|
|
701
988
|
try {
|
|
@@ -711,7 +998,11 @@ var LEVEL_OPTIONS = {
|
|
|
711
998
|
...OUTPUT_OPTIONS,
|
|
712
999
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
713
1000
|
};
|
|
714
|
-
var TOP_OPTIONS = {
|
|
1001
|
+
var TOP_OPTIONS = {
|
|
1002
|
+
...LEVEL_OPTIONS,
|
|
1003
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1004
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1005
|
+
};
|
|
715
1006
|
async function commandRows(all, colors) {
|
|
716
1007
|
const commands = shown(all);
|
|
717
1008
|
const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
|
|
@@ -746,6 +1037,10 @@ function takeOutputFlags(argv) {
|
|
|
746
1037
|
async function resolveSummary(summary) {
|
|
747
1038
|
return typeof summary === "string" ? summary : summary();
|
|
748
1039
|
}
|
|
1040
|
+
function lookup({ commands, aliases }, word) {
|
|
1041
|
+
const name = aliases !== undefined && Object.hasOwn(aliases, word) ? aliases[word] ?? word : word;
|
|
1042
|
+
return Object.hasOwn(commands, name) ? commands[name] : undefined;
|
|
1043
|
+
}
|
|
749
1044
|
function scopeOf(commands, extra, aliases) {
|
|
750
1045
|
return { commands: typeof commands === "function" ? {} : commands, lazy: [...typeof commands === "function" ? [commands] : [], ...extra === undefined ? [] : [extra]], aliases };
|
|
751
1046
|
}
|
|
@@ -772,7 +1067,6 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
772
1067
|
header(colors, summary),
|
|
773
1068
|
"",
|
|
774
1069
|
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
775
|
-
...replacesRows(replaces, colors),
|
|
776
1070
|
"",
|
|
777
1071
|
...await commandRows(commands, colors),
|
|
778
1072
|
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
@@ -786,8 +1080,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
786
1080
|
`);
|
|
787
1081
|
}
|
|
788
1082
|
function printError(prefix, message, hint, cause) {
|
|
789
|
-
const colors = paint(
|
|
790
|
-
const styled = takesControlCodes(
|
|
1083
|
+
const colors = paint(process14.stderr);
|
|
1084
|
+
const styled = takesControlCodes(process14.stderr);
|
|
791
1085
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
792
1086
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
793
1087
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -830,23 +1124,23 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
830
1124
|
}
|
|
831
1125
|
}
|
|
832
1126
|
if (name === undefined && level.path.length > 1) {
|
|
833
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1127
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stderr));
|
|
834
1128
|
return 2;
|
|
835
1129
|
}
|
|
836
1130
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
837
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1131
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stdout));
|
|
838
1132
|
return 0;
|
|
839
1133
|
}
|
|
840
1134
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
841
1135
|
console.log(version);
|
|
842
1136
|
return 0;
|
|
843
1137
|
}
|
|
844
|
-
let command = level
|
|
1138
|
+
let command = lookup(level, name);
|
|
845
1139
|
let rest = args;
|
|
846
1140
|
let ran = name;
|
|
847
1141
|
if (command === undefined && level.lazy.length > 0) {
|
|
848
1142
|
level = await expand(level, [...level.path.slice(1), ...argv]);
|
|
849
|
-
command = level
|
|
1143
|
+
command = lookup(level, name);
|
|
850
1144
|
}
|
|
851
1145
|
if (command === undefined && level.defaultCommand !== undefined) {
|
|
852
1146
|
command = level.commands[level.defaultCommand];
|
|
@@ -890,24 +1184,24 @@ function candidateLine(candidate) {
|
|
|
890
1184
|
}
|
|
891
1185
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
892
1186
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
893
|
-
|
|
1187
|
+
const typed = [];
|
|
894
1188
|
let at = 0;
|
|
895
1189
|
while (at < before.length) {
|
|
896
1190
|
const word = before[at];
|
|
897
1191
|
if (word === "--") {
|
|
898
|
-
|
|
1192
|
+
typed.push(...before.slice(at + 1));
|
|
899
1193
|
break;
|
|
900
1194
|
}
|
|
901
1195
|
if (!word.startsWith("-"))
|
|
902
|
-
|
|
1196
|
+
typed.push(word);
|
|
903
1197
|
else if (takesValue(word))
|
|
904
1198
|
at++;
|
|
905
1199
|
at++;
|
|
906
1200
|
}
|
|
907
1201
|
const last = positionals.at(-1);
|
|
908
|
-
if (
|
|
909
|
-
return positionals[
|
|
910
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1202
|
+
if (typed.length < positionals.length)
|
|
1203
|
+
return { name: positionals[typed.length], typed };
|
|
1204
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
911
1205
|
}
|
|
912
1206
|
async function leafCandidates(run, words) {
|
|
913
1207
|
const completing = await completingOf(run);
|
|
@@ -915,29 +1209,30 @@ async function leafCandidates(run, words) {
|
|
|
915
1209
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
916
1210
|
const flag = words.at(-2);
|
|
917
1211
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1212
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
918
1213
|
if (option?.type === "string") {
|
|
919
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1214
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
920
1215
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
921
1216
|
}
|
|
922
|
-
const
|
|
923
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1217
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
924
1218
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
925
1219
|
}
|
|
926
1220
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
927
1221
|
const [word = "", ...rest] = words;
|
|
928
1222
|
const listing = rest.length === 0 && !word.startsWith("-");
|
|
929
|
-
let { commands
|
|
930
|
-
let command =
|
|
1223
|
+
let { commands } = scope;
|
|
1224
|
+
let command = lookup(scope, word);
|
|
931
1225
|
if (listing || command === undefined) {
|
|
932
|
-
|
|
933
|
-
|
|
1226
|
+
const expanded = await expand(scope, [...before, ...words]);
|
|
1227
|
+
commands = expanded.commands;
|
|
1228
|
+
command = lookup(expanded, word);
|
|
934
1229
|
}
|
|
935
1230
|
if (listing) {
|
|
936
1231
|
const own = await Promise.all(Object.entries(shown(commands)).map(async ([name, { summary }]) => `${name} ${await resolveSummary(summary)}`));
|
|
937
1232
|
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
938
1233
|
const values = fallback !== undefined && "run" in fallback ? await leafCandidates(fallback.run, [word]) : [];
|
|
939
1234
|
const valueOf = (line) => line.slice(0, line.includes("\t") ? line.indexOf("\t") : undefined);
|
|
940
|
-
return [...own, ...values.filter((line) => line !== FILES && !(valueOf(line)
|
|
1235
|
+
return [...own, ...values.filter((line) => line !== FILES && !Object.hasOwn(commands, valueOf(line)))];
|
|
941
1236
|
}
|
|
942
1237
|
if (command === undefined) {
|
|
943
1238
|
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
@@ -945,15 +1240,32 @@ async function candidates(scope, defaultCommand, words, before = []) {
|
|
|
945
1240
|
}
|
|
946
1241
|
return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
|
|
947
1242
|
}
|
|
1243
|
+
var COMPLETIONS = "--completions";
|
|
1244
|
+
function flagValue([flag = "", ...rest]) {
|
|
1245
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1246
|
+
}
|
|
1247
|
+
function printCompletionScript(name, args) {
|
|
1248
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1249
|
+
if (shell === undefined || args.length !== 1) {
|
|
1250
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1251
|
+
return 2;
|
|
1252
|
+
}
|
|
1253
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1254
|
+
return 0;
|
|
1255
|
+
}
|
|
948
1256
|
async function printCandidates(found) {
|
|
949
1257
|
for (const line of await found)
|
|
950
1258
|
console.log(line);
|
|
951
1259
|
return 0;
|
|
952
1260
|
}
|
|
953
1261
|
function packageVersion(entry = Bun.main) {
|
|
954
|
-
|
|
1262
|
+
let resolved = entry;
|
|
1263
|
+
try {
|
|
1264
|
+
resolved = realpathSync2(entry);
|
|
1265
|
+
} catch {}
|
|
1266
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
955
1267
|
try {
|
|
956
|
-
const { version } = JSON.parse(
|
|
1268
|
+
const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
|
|
957
1269
|
if (typeof version === "string")
|
|
958
1270
|
return version;
|
|
959
1271
|
} catch {}
|
|
@@ -961,14 +1273,22 @@ function packageVersion(entry = Bun.main) {
|
|
|
961
1273
|
return "0.0.0";
|
|
962
1274
|
}
|
|
963
1275
|
}
|
|
964
|
-
async function runCli(cli, argv =
|
|
1276
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
965
1277
|
const version = cli.version ?? packageVersion();
|
|
1278
|
+
const answered = await askpassClient(argv);
|
|
1279
|
+
if (answered !== undefined)
|
|
1280
|
+
return answered;
|
|
966
1281
|
if (argv[0] === COMPLETE)
|
|
967
1282
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1283
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1284
|
+
return printCompletionScript(cli.name, flagValue(argv));
|
|
1285
|
+
const started = performance.now();
|
|
968
1286
|
const code = await dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(version)} ${about}`, summary: cli.about, ...scopeOf(cli.commands, cli.extraCommands, cli.aliases), defaultCommand: cli.defaultCommand, runBare: cli.runBare === true, examples: cli.examples, replaces: cli.replaces }, argv, { version, redact: cli.redact });
|
|
1287
|
+
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
|
1288
|
+
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
969
1289
|
if (cli.usage !== false) {
|
|
970
1290
|
try {
|
|
971
|
-
recordUsage(usageEntry(cli.name,
|
|
1291
|
+
recordUsage(usageEntry(cli.name, command, argv, code, { ms: performance.now() - started }));
|
|
972
1292
|
} catch {}
|
|
973
1293
|
}
|
|
974
1294
|
return code;
|
|
@@ -977,8 +1297,7 @@ function commandPath(scope, argv) {
|
|
|
977
1297
|
const path = [];
|
|
978
1298
|
let level = scope;
|
|
979
1299
|
for (const word of argv.filter((each) => !each.startsWith("-"))) {
|
|
980
|
-
const
|
|
981
|
-
const command = Object.hasOwn(level.commands, name) ? level.commands[name] : undefined;
|
|
1300
|
+
const command = lookup(level, word);
|
|
982
1301
|
if (command === undefined)
|
|
983
1302
|
break;
|
|
984
1303
|
path.push(word);
|
|
@@ -988,465 +1307,59 @@ function commandPath(scope, argv) {
|
|
|
988
1307
|
}
|
|
989
1308
|
return path.length === 0 ? undefined : path.join(" ");
|
|
990
1309
|
}
|
|
991
|
-
// ../kit/src/compose.ts
|
|
992
|
-
async function captureOutput(argv, { cwd, env } = {}) {
|
|
993
|
-
const run = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, env: { ...process.env, ...env }, stdin: "ignore", stdout: "pipe", stderr: "pipe" });
|
|
994
|
-
const [stdout, stderr, code] = await Promise.all([new Response(run.stdout).text(), new Response(run.stderr).text(), run.exited]);
|
|
995
|
-
return { code, stdout, stderr };
|
|
996
|
-
}
|
|
997
|
-
async function compose(args, { flags = [], ...options } = {}) {
|
|
998
|
-
return captureOutput(["docker", "compose", ...flags, ...args], options);
|
|
999
|
-
}
|
|
1000
|
-
function composeError({ code, stderr }) {
|
|
1001
|
-
const last = stderr.trim().split(`
|
|
1002
|
-
`).at(-1) ?? "";
|
|
1003
|
-
return last === "" ? `exit ${code}` : last;
|
|
1004
|
-
}
|
|
1005
|
-
// ../kit/src/folders.ts
|
|
1006
|
-
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1007
|
-
// ../kit/src/limit.ts
|
|
1008
|
-
function limitOptions(fallback) {
|
|
1009
|
-
return {
|
|
1010
|
-
limit: { type: "string", short: "n", description: `show at most this many rows, the rest counted (${fallback})` },
|
|
1011
|
-
full: { type: "boolean", description: "show every row" }
|
|
1012
|
-
};
|
|
1013
|
-
}
|
|
1014
|
-
function limitOf(values, fallback) {
|
|
1015
|
-
if (values.full === true && values.limit !== undefined)
|
|
1016
|
-
badUsage("--limit and --full exclude each other");
|
|
1017
|
-
if (values.full === true || values.json === true && values.limit === undefined)
|
|
1018
|
-
return Number.POSITIVE_INFINITY;
|
|
1019
|
-
return wholeNumber(values.limit, "limit", fallback);
|
|
1020
|
-
}
|
|
1021
|
-
function moreFooter(more) {
|
|
1022
|
-
return `${more} more, rerun with --full`;
|
|
1023
|
-
}
|
|
1024
|
-
function capped(rows, limit) {
|
|
1025
|
-
const more = rows.length - limit;
|
|
1026
|
-
return more > 0 ? { shown: rows.slice(0, limit), footer: moreFooter(more) } : { shown: [...rows], footer: undefined };
|
|
1027
|
-
}
|
|
1028
|
-
// ../kit/src/secrets.ts
|
|
1029
|
-
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1030
|
-
// ../kit/src/sessions.ts
|
|
1031
|
-
var {Glob } = globalThis.Bun;
|
|
1032
|
-
var SESSION_FILES = new Glob("*.json");
|
|
1033
|
-
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1034
|
-
// src/commands/audit.ts
|
|
1035
|
-
import { homedir as homedir4 } from "os";
|
|
1036
|
-
import { resolve as resolve4 } from "path";
|
|
1037
|
-
import process14 from "process";
|
|
1038
1310
|
|
|
1039
|
-
// src/
|
|
1040
|
-
|
|
1041
|
-
var dockerCompose = async (root, files) => {
|
|
1042
|
-
const result = await compose(["config", "--no-interpolate", "--format", "json"], { flags: ["--project-directory", root, ...files.flatMap((file) => ["-f", join6(root, file)])], env: { COMPOSE_FILE: "" } });
|
|
1043
|
-
if (result.code !== 0)
|
|
1044
|
-
throw new Error(composeError(result));
|
|
1045
|
-
return JSON.parse(result.stdout);
|
|
1046
|
-
};
|
|
1311
|
+
// ../kit/src/index.ts
|
|
1312
|
+
init_config();
|
|
1047
1313
|
|
|
1048
|
-
// src/
|
|
1049
|
-
|
|
1050
|
-
import process13 from "process";
|
|
1051
|
-
var line = (finding) => ` ${marked(finding.level === "error" ? "problem" : "warn", `[${finding.check}] ${finding.message}`, process13.stdout)}`;
|
|
1052
|
-
function errorsOf(result) {
|
|
1053
|
-
return result.findings.filter((finding) => finding.level === "error");
|
|
1054
|
-
}
|
|
1055
|
-
function section2(heading, findings, limit) {
|
|
1056
|
-
const { shown, footer } = capped(findings, limit);
|
|
1057
|
-
return findings.length === 0 ? [] : [heading, ...shown.map(line), ...footer === undefined ? [] : [` ${footer}`], ""];
|
|
1058
|
-
}
|
|
1059
|
-
function render(result, limit = Number.POSITIVE_INFINITY) {
|
|
1060
|
-
const errors = errorsOf(result);
|
|
1061
|
-
const warnings = result.findings.filter((finding) => finding.level === "warn");
|
|
1062
|
-
if (result.findings.length === 0)
|
|
1063
|
-
return marked("ok", `${basename(result.root)}: compose ${result.composeFiles.join(", ")} and release.config.ts agree.`, process13.stdout);
|
|
1064
|
-
return [
|
|
1065
|
-
...section2("Errors", errors, limit),
|
|
1066
|
-
...section2("Warnings", warnings, limit),
|
|
1067
|
-
`${errors.length} error(s), ${warnings.length} warning(s)`
|
|
1068
|
-
].join(`
|
|
1069
|
-
`);
|
|
1070
|
-
}
|
|
1314
|
+
// ../kit/src/excerpt.ts
|
|
1315
|
+
init_text();
|
|
1071
1316
|
|
|
1072
|
-
// src/
|
|
1073
|
-
|
|
1074
|
-
|
|
1317
|
+
// ../kit/src/index.ts
|
|
1318
|
+
init_folders();
|
|
1319
|
+
init_format();
|
|
1075
1320
|
|
|
1076
|
-
// src/
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
var REQUIRED_OPERATOR = /^\s*:?\?/;
|
|
1081
|
-
var COMMENT_START = /(?:^|\s)#.*$/;
|
|
1082
|
-
var QUOTES = /['"]/g;
|
|
1083
|
-
var YAML_FILE = /\.ya?ml$/;
|
|
1084
|
-
var LEADING_DOT_SLASH = /^\.\//;
|
|
1085
|
-
var SERVICES_KEY = /^services:/m;
|
|
1086
|
-
var EXEC_SERVICE = /\{compose\}(?:\s+--\S+)*\s+(?:exec|run)\s+(?:-\S+\s+)*([\w-]+)/;
|
|
1087
|
-
var services = (model) => Object.entries(model?.services ?? {});
|
|
1088
|
-
function before(text, separator) {
|
|
1089
|
-
const at = text.indexOf(separator);
|
|
1090
|
-
return at < 0 ? text : text.slice(0, at);
|
|
1091
|
-
}
|
|
1092
|
-
var stripDotSlash = (file) => file.replace(LEADING_DOT_SLASH, "");
|
|
1093
|
-
function composeLayout(root, config) {
|
|
1094
|
-
const composeFiles = (config.deploySyncFiles ?? []).map(stripDotSlash).filter((file) => YAML_FILE.test(file) && existsSync3(join7(root, file)));
|
|
1095
|
-
const [base] = composeFiles.toSorted((a, b) => a.length - b.length);
|
|
1096
|
-
return { composeFiles, base, overlays: composeFiles.filter((file) => file !== base) };
|
|
1097
|
-
}
|
|
1098
|
-
function syncFindings(root, config) {
|
|
1099
|
-
return (config.deploySyncFiles ?? []).filter((file) => !existsSync3(join7(root, stripDotSlash(file)))).map((file) => ({ level: "error", check: "sync", message: `deploySyncFiles entry does not exist: ${file}` }));
|
|
1100
|
-
}
|
|
1101
|
-
function buildFindings(root, releases, env, home) {
|
|
1102
|
-
const findings = [];
|
|
1103
|
-
const missing = (release, key) => {
|
|
1104
|
-
const path = release[key];
|
|
1105
|
-
if (path !== undefined && path !== "" && !existsSync3(join7(root, path)))
|
|
1106
|
-
findings.push({ level: "error", check: "build", message: `${release.slug}: ${key} does not exist: ${path}` });
|
|
1107
|
-
};
|
|
1108
|
-
for (const release of releases) {
|
|
1109
|
-
missing(release, "sourceDir");
|
|
1110
|
-
missing(release, "buildContext");
|
|
1111
|
-
missing(release, "dockerfile");
|
|
1112
|
-
for (const secret of release.buildSecrets ?? []) {
|
|
1113
|
-
if (secret.src !== undefined && secret.src !== "") {
|
|
1114
|
-
const path = secret.src.startsWith("~") ? join7(home, secret.src.slice(1)) : resolve3(root, secret.src);
|
|
1115
|
-
if (!existsSync3(path))
|
|
1116
|
-
findings.push({ level: "error", check: "build", message: `${release.slug}: buildSecret "${secret.id}" src does not exist: ${secret.src}` });
|
|
1117
|
-
}
|
|
1118
|
-
if (secret.env !== undefined && secret.env !== "" && (env[secret.env] ?? "") === "")
|
|
1119
|
-
findings.push({ level: "warn", check: "build", message: `${release.slug}: buildSecret "${secret.id}" reads $${secret.env}, unset in this shell` });
|
|
1120
|
-
}
|
|
1121
|
-
}
|
|
1122
|
-
return findings;
|
|
1123
|
-
}
|
|
1124
|
-
function withoutComment(line) {
|
|
1125
|
-
const comment = COMMENT_START.exec(line);
|
|
1126
|
-
if (comment === null || (line.slice(0, comment.index).match(QUOTES)?.length ?? 0) % 2 === 1)
|
|
1127
|
-
return line;
|
|
1128
|
-
return line.slice(0, comment.index);
|
|
1129
|
-
}
|
|
1130
|
-
function envRefs(root, composeFiles) {
|
|
1131
|
-
return composeFiles.flatMap((file) => {
|
|
1132
|
-
const text = readFileSync3(join7(root, file), "utf8").split(`
|
|
1133
|
-
`).map(withoutComment).join(`
|
|
1134
|
-
`);
|
|
1135
|
-
return [...text.matchAll(ENV_REF)].map((match) => ({ name: match[1] ?? match[3], defaulted: match[2] !== undefined && !REQUIRED_OPERATOR.test(match[2]), file }));
|
|
1136
|
-
});
|
|
1137
|
-
}
|
|
1138
|
-
function envFindings(refs, required) {
|
|
1139
|
-
const findings = [];
|
|
1140
|
-
const level = required.length > 0 ? "error" : "warn";
|
|
1141
|
-
for (const name of new Set(refs.filter((ref) => !ref.defaulted).map((ref) => ref.name))) {
|
|
1142
|
-
if (!name.endsWith("_VERSION") && !required.includes(name))
|
|
1143
|
-
findings.push({ level, check: "env", message: `\${${name}} has no default in ${refs.find((ref) => ref.name === name)?.file} and is not in requiredServerEnv` });
|
|
1144
|
-
}
|
|
1145
|
-
for (const name of required) {
|
|
1146
|
-
if (!refs.some((ref) => ref.name === name))
|
|
1147
|
-
findings.push({ level: "warn", check: "env", message: `requiredServerEnv lists ${name}, which no compose file references` });
|
|
1148
|
-
}
|
|
1149
|
-
return findings;
|
|
1150
|
-
}
|
|
1151
|
-
function versionFindings(refs, releases) {
|
|
1152
|
-
const findings = [];
|
|
1153
|
-
const inCompose = new Set(refs.filter((ref) => ref.name.endsWith("_VERSION")).map((ref) => ref.name));
|
|
1154
|
-
const inConfig = new Set(releases.map((release) => release.versionEnv).filter((name) => typeof name === "string" && name !== ""));
|
|
1155
|
-
for (const name of inConfig) {
|
|
1156
|
-
if (!inCompose.has(name))
|
|
1157
|
-
findings.push({ level: "error", check: "version", message: `versionEnv ${name} is never interpolated by a compose file` });
|
|
1158
|
-
}
|
|
1159
|
-
for (const name of inCompose) {
|
|
1160
|
-
if (!inConfig.has(name))
|
|
1161
|
-
findings.push({ level: "error", check: "version", message: `compose interpolates \${${name}}, which no release declares as versionEnv` });
|
|
1162
|
-
}
|
|
1163
|
-
return findings;
|
|
1164
|
-
}
|
|
1165
|
-
function imageFindings(config, releases, model) {
|
|
1166
|
-
const registry = config.registry ?? "";
|
|
1167
|
-
if (registry === "")
|
|
1168
|
-
return [];
|
|
1169
|
-
const declared = new Set(releases.filter((release) => release.image !== undefined && release.image !== "").map((release) => `${registry}/${release.image}`));
|
|
1170
|
-
const findings = [];
|
|
1171
|
-
for (const [name, service] of services(model)) {
|
|
1172
|
-
const repo = service.image === undefined ? undefined : before(service.image, ":");
|
|
1173
|
-
if (repo !== undefined && repo.startsWith(registry) && !declared.has(repo))
|
|
1174
|
-
findings.push({ level: "warn", check: "image", message: `service "${name}" pulls ${repo}, which no release in this config builds` });
|
|
1175
|
-
}
|
|
1176
|
-
return findings;
|
|
1177
|
-
}
|
|
1178
|
-
function restartFindings(config, releases, model, base) {
|
|
1179
|
-
if (model === undefined)
|
|
1180
|
-
return [];
|
|
1181
|
-
const known = new Set(Object.keys(model.services ?? {}));
|
|
1182
|
-
const findings = [];
|
|
1183
|
-
for (const release of releases) {
|
|
1184
|
-
for (const service of release.restartServices ?? []) {
|
|
1185
|
-
if (!known.has(service))
|
|
1186
|
-
findings.push({ level: "error", check: "restart", message: `${release.slug}: restartServices names "${service}", absent from ${base}` });
|
|
1187
|
-
}
|
|
1188
|
-
}
|
|
1189
|
-
for (const server of config.servers ?? []) {
|
|
1190
|
-
for (const [slug, override] of Object.entries(server.releaseOverrides ?? {})) {
|
|
1191
|
-
for (const service of override.restartServices ?? []) {
|
|
1192
|
-
if (!known.has(service))
|
|
1193
|
-
findings.push({ level: "error", check: "restart", message: `server ${server.name}: releaseOverrides.${slug} names service "${service}", absent from ${base}` });
|
|
1194
|
-
}
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
return findings;
|
|
1198
|
-
}
|
|
1199
|
-
function postDeployFindings(releases, model, base) {
|
|
1200
|
-
if (model === undefined)
|
|
1201
|
-
return [];
|
|
1202
|
-
const known = new Set(Object.keys(model.services ?? {}));
|
|
1203
|
-
const findings = [];
|
|
1204
|
-
for (const release of releases) {
|
|
1205
|
-
for (const command of release.postDeployCommands ?? []) {
|
|
1206
|
-
const target = EXEC_SERVICE.exec(command)?.[1];
|
|
1207
|
-
if (target !== undefined && !known.has(target))
|
|
1208
|
-
findings.push({ level: "warn", check: "post-deploy", message: `${release.slug}: post-deploy command targets service "${target}", absent from ${base}` });
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
return findings;
|
|
1212
|
-
}
|
|
1213
|
-
var gatedServices = (releases) => new Set(releases.flatMap((release) => release.restartServices ?? []));
|
|
1214
|
-
function healthFindings(gated, model) {
|
|
1215
|
-
return [...gated].filter((name) => {
|
|
1216
|
-
const service = model?.services?.[name];
|
|
1217
|
-
return service !== undefined && (service.healthcheck === undefined || service.healthcheck === null);
|
|
1218
|
-
}).map((name) => ({ level: "warn", check: "health", message: `service "${name}" is restarted by a release but declares no healthcheck, so --wait will not gate it` }));
|
|
1219
|
-
}
|
|
1220
|
-
function routingFindings(config, gated, model, base, overlays) {
|
|
1221
|
-
if (overlays.length === 0)
|
|
1222
|
-
return [];
|
|
1223
|
-
const findings = [];
|
|
1224
|
-
for (const name of gated) {
|
|
1225
|
-
const service = model?.services?.[name];
|
|
1226
|
-
if (service === undefined)
|
|
1227
|
-
continue;
|
|
1228
|
-
if (service.ports !== undefined && service.ports.length > 0)
|
|
1229
|
-
findings.push({ level: "error", check: "routing", message: `service "${name}" publishes ports in ${base}; publishing belongs in an overlay` });
|
|
1230
|
-
if (Object.keys(service.labels ?? {}).some((key) => key.startsWith("traefik.")))
|
|
1231
|
-
findings.push({ level: "error", check: "routing", message: `service "${name}" carries traefik labels in ${base}; routing belongs in an overlay` });
|
|
1232
|
-
}
|
|
1233
|
-
const composeArgs = config.composeArgs ?? [];
|
|
1234
|
-
if (composeArgs.length > 0)
|
|
1235
|
-
findings.push({ level: "error", check: "routing", message: `composeArgs is set (${composeArgs.join(" ")}) while ${overlays.length} overlay(s) exist: -f overrides each server's COMPOSE_FILE and drops them` });
|
|
1236
|
-
for (const server of config.servers ?? []) {
|
|
1237
|
-
if (server.composeArgs !== undefined && server.composeArgs.length > 0)
|
|
1238
|
-
findings.push({ level: "warn", check: "routing", message: `server ${server.name} sets composeArgs; prefer its own COMPOSE_FILE` });
|
|
1239
|
-
}
|
|
1240
|
-
return findings;
|
|
1241
|
-
}
|
|
1242
|
-
var SOURCE_END = /:(?![-+?=])/;
|
|
1243
|
-
var DEFAULTED_VARIABLE = /\$\{[A-Z_]\w*:?-([^}$]*)\}/gi;
|
|
1244
|
-
function relativeSource(root, written) {
|
|
1245
|
-
const source = written?.replaceAll(DEFAULTED_VARIABLE, "$1");
|
|
1246
|
-
if (source === undefined || source.includes("$"))
|
|
1247
|
-
return;
|
|
1248
|
-
if (source.startsWith("."))
|
|
1249
|
-
return source;
|
|
1250
|
-
const inRoot = relative(resolve3(root), source);
|
|
1251
|
-
return isAbsolute2(source) && inRoot !== "" && !inRoot.startsWith("..") ? `./${inRoot}` : undefined;
|
|
1252
|
-
}
|
|
1253
|
-
function layoutFindings(root, base, model) {
|
|
1254
|
-
if (base === undefined)
|
|
1255
|
-
return [];
|
|
1256
|
-
const header = readFileSync3(join7(root, base), "utf8").split(SERVICES_KEY)[0] ?? "";
|
|
1257
|
-
const findings = [];
|
|
1258
|
-
for (const [name, service] of services(model)) {
|
|
1259
|
-
for (const volume of service.volumes ?? []) {
|
|
1260
|
-
const source = relativeSource(root, typeof volume === "string" ? volume.split(SOURCE_END)[0] : volume.source);
|
|
1261
|
-
if (source !== undefined && !header.includes(stripDotSlash(source)))
|
|
1262
|
-
findings.push({ level: "warn", check: "layout", message: `service "${name}" bind-mounts ${source}, absent from the header's expected server layout` });
|
|
1263
|
-
}
|
|
1264
|
-
}
|
|
1265
|
-
return findings;
|
|
1266
|
-
}
|
|
1267
|
-
function gitignoreFindings(root) {
|
|
1268
|
-
const path = join7(root, ".gitignore");
|
|
1269
|
-
const text = existsSync3(path) ? readFileSync3(path, "utf8") : "";
|
|
1270
|
-
return [".release-logs", ".release-worktrees"].filter((entry) => !text.includes(entry)).map((entry) => ({ level: "warn", check: "gitignore", message: `${entry}/ is not in .gitignore` }));
|
|
1271
|
-
}
|
|
1321
|
+
// ../kit/src/git.ts
|
|
1322
|
+
init_args();
|
|
1323
|
+
// ../kit/src/limit.ts
|
|
1324
|
+
init_args();
|
|
1272
1325
|
|
|
1273
|
-
// src/
|
|
1274
|
-
|
|
1275
|
-
import { basename as basename2, join as join8 } from "path";
|
|
1276
|
-
var CAMEL_BOUNDARY = /([a-z0-9])([A-Z])/g;
|
|
1277
|
-
var KEY = /([A-Z_]\w*)\s*(?:\?\s*)?:/gi;
|
|
1278
|
-
var OPENS_BRACE = /^\s*\{/;
|
|
1279
|
-
var envVarFor = (key) => key.replace(CAMEL_BOUNDARY, "$1_$2").toUpperCase();
|
|
1280
|
-
function braceBody(text, from) {
|
|
1281
|
-
const open = text.indexOf("{", from);
|
|
1282
|
-
if (open < 0)
|
|
1283
|
-
return;
|
|
1284
|
-
let depth = 0;
|
|
1285
|
-
for (let i = open;i < text.length; i++) {
|
|
1286
|
-
if (text[i] === "{")
|
|
1287
|
-
depth++;
|
|
1288
|
-
else if (text[i] === "}" && --depth === 0)
|
|
1289
|
-
return { body: text.slice(open + 1, i), end: i };
|
|
1290
|
-
}
|
|
1291
|
-
return;
|
|
1292
|
-
}
|
|
1293
|
-
function leafPaths(body, prefix = []) {
|
|
1294
|
-
const paths = [];
|
|
1295
|
-
const key = new RegExp(KEY);
|
|
1296
|
-
for (let match = key.exec(body);match !== null; match = key.exec(body)) {
|
|
1297
|
-
const name = match[1];
|
|
1298
|
-
const after = match.index + match[0].length;
|
|
1299
|
-
if (OPENS_BRACE.test(body.slice(after))) {
|
|
1300
|
-
const inner = braceBody(body, after);
|
|
1301
|
-
if (inner === undefined)
|
|
1302
|
-
continue;
|
|
1303
|
-
paths.push(...leafPaths(inner.body, [...prefix, name]));
|
|
1304
|
-
key.lastIndex = inner.end + 1;
|
|
1305
|
-
} else {
|
|
1306
|
-
paths.push([...prefix, name]);
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
return paths;
|
|
1310
|
-
}
|
|
1311
|
-
function schemaEnvNames(schema, iface, prefix) {
|
|
1312
|
-
const at = schema.indexOf(`interface ${iface}`);
|
|
1313
|
-
const body = at < 0 ? undefined : braceBody(schema, at);
|
|
1314
|
-
return body === undefined ? [] : leafPaths(body.body).map((path) => prefix + path.map(envVarFor).join("_"));
|
|
1315
|
-
}
|
|
1316
|
-
function nuxtFindings(root, releases, model) {
|
|
1317
|
-
const findings = [];
|
|
1318
|
-
const dirs = [...new Set(releases.map((release) => release.buildContext).filter((context) => context !== undefined && context !== ""))].map((dir) => join8(root, dir)).filter((dir) => existsSync4(join8(dir, "nuxt.config.ts")));
|
|
1319
|
-
for (const dir of dirs) {
|
|
1320
|
-
const schemaPath = [join8(dir, ".nuxt/types/schema.d.ts"), join8(dir, ".nuxt/types/runtime-config.d.ts")].find((path) => existsSync4(path));
|
|
1321
|
-
let allowed;
|
|
1322
|
-
let level = "error";
|
|
1323
|
-
let source;
|
|
1324
|
-
if (schemaPath !== undefined) {
|
|
1325
|
-
const schema = readFileSync4(schemaPath, "utf8");
|
|
1326
|
-
allowed = new Set([
|
|
1327
|
-
...schemaEnvNames(schema, "SharedRuntimeConfig", "NUXT_"),
|
|
1328
|
-
...schemaEnvNames(schema, "SharedPublicRuntimeConfig", "NUXT_PUBLIC_")
|
|
1329
|
-
]);
|
|
1330
|
-
source = `${basename2(dir)}/${schemaPath.slice(dir.length + 1)}`;
|
|
1331
|
-
} else {
|
|
1332
|
-
const config = readFileSync4(join8(dir, "nuxt.config.ts"), "utf8");
|
|
1333
|
-
const at = config.indexOf("runtimeConfig:");
|
|
1334
|
-
const block = at < 0 ? undefined : braceBody(config, at);
|
|
1335
|
-
if (block === undefined)
|
|
1336
|
-
continue;
|
|
1337
|
-
allowed = new Set(leafPaths(block.body).map((path) => path[0] === "public" ? `NUXT_PUBLIC_${path.slice(1).map(envVarFor).join("_")}` : `NUXT_${path.map(envVarFor).join("_")}`));
|
|
1338
|
-
level = "warn";
|
|
1339
|
-
source = `${basename2(dir)}/nuxt.config.ts (run \`nuxt prepare\` in ${basename2(dir)} for the resolved config, modules included)`;
|
|
1340
|
-
}
|
|
1341
|
-
for (const [name, service] of Object.entries(model?.services ?? {})) {
|
|
1342
|
-
for (const key of Object.keys(service.environment ?? {})) {
|
|
1343
|
-
if (key.startsWith("NUXT_") && !allowed.has(key))
|
|
1344
|
-
findings.push({ level, check: "nuxt", message: `service "${name}" sets ${key}, which matches no runtimeConfig key in ${source}` });
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
return findings;
|
|
1349
|
-
}
|
|
1326
|
+
// ../kit/src/index.ts
|
|
1327
|
+
init_mode();
|
|
1350
1328
|
|
|
1351
|
-
// src/
|
|
1352
|
-
|
|
1353
|
-
var DEFINE_CONFIG_IMPORT = /import\s*\{[^}]*\bdefineConfig\b[^}]*\}\s*from\s*['"]([^'"]+)['"]/;
|
|
1354
|
-
function installed(specifier, root) {
|
|
1329
|
+
// ../kit/src/port.ts
|
|
1330
|
+
function isListening(port) {
|
|
1355
1331
|
try {
|
|
1356
|
-
Bun.
|
|
1357
|
-
|
|
1358
|
-
|
|
1332
|
+
Bun.listen({ hostname: "0.0.0.0", port, socket: { data: () => {
|
|
1333
|
+
return;
|
|
1334
|
+
} } }).stop(true);
|
|
1359
1335
|
return false;
|
|
1336
|
+
} catch (error) {
|
|
1337
|
+
return error.code === "EADDRINUSE";
|
|
1360
1338
|
}
|
|
1361
1339
|
}
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
const config = (await import(join9(root, CONFIG_FILE))).default;
|
|
1373
|
-
if (config === undefined)
|
|
1374
|
-
fail(`${CONFIG_FILE} has no default export`);
|
|
1375
|
-
return config;
|
|
1376
|
-
}
|
|
1377
|
-
async function composeModels(options, base, overlays) {
|
|
1378
|
-
const findings = [];
|
|
1379
|
-
const load = async (files) => {
|
|
1380
|
-
try {
|
|
1381
|
-
return await options.loadCompose(options.root, files);
|
|
1382
|
-
} catch (error) {
|
|
1383
|
-
findings.push({ level: "error", check: "compose", message: `docker compose config failed for ${files.join(" + ")}: ${error instanceof Error ? error.message : String(error)}` });
|
|
1384
|
-
return;
|
|
1385
|
-
}
|
|
1386
|
-
};
|
|
1387
|
-
if (base === undefined) {
|
|
1388
|
-
findings.push({ level: "warn", check: "compose", message: "no compose file among deploySyncFiles, so every check that reads the compose model was skipped" });
|
|
1389
|
-
return { model: undefined, findings };
|
|
1390
|
-
}
|
|
1391
|
-
const model = await load([base]);
|
|
1392
|
-
for (const overlay of overlays)
|
|
1393
|
-
await load([base, overlay]);
|
|
1394
|
-
return { model, findings };
|
|
1395
|
-
}
|
|
1396
|
-
async function audit(config, options) {
|
|
1397
|
-
const { root } = options;
|
|
1398
|
-
const releases = config.releases ?? [];
|
|
1399
|
-
const required = config.requiredServerEnv ?? [];
|
|
1400
|
-
const { composeFiles, base, overlays } = composeLayout(root, config);
|
|
1401
|
-
const compose = await composeModels(options, base, overlays);
|
|
1402
|
-
const refs = envRefs(root, composeFiles);
|
|
1403
|
-
const gated = gatedServices(releases);
|
|
1404
|
-
const findings = [
|
|
1405
|
-
...syncFindings(root, config),
|
|
1406
|
-
...buildFindings(root, releases, options.env, options.home),
|
|
1407
|
-
...compose.findings,
|
|
1408
|
-
...envFindings(refs, required),
|
|
1409
|
-
...versionFindings(refs, releases),
|
|
1410
|
-
...imageFindings(config, releases, compose.model),
|
|
1411
|
-
...restartFindings(config, releases, compose.model, base),
|
|
1412
|
-
...postDeployFindings(releases, compose.model, base),
|
|
1413
|
-
...healthFindings(gated, compose.model),
|
|
1414
|
-
...routingFindings(config, gated, compose.model, base, overlays),
|
|
1415
|
-
...layoutFindings(root, base, compose.model),
|
|
1416
|
-
...nuxtFindings(root, releases, compose.model),
|
|
1417
|
-
...gitignoreFindings(root)
|
|
1418
|
-
];
|
|
1419
|
-
return { root, composeFiles, findings };
|
|
1420
|
-
}
|
|
1421
|
-
var hasConfig = (root) => existsSync5(join9(root, CONFIG_FILE));
|
|
1422
|
-
|
|
1423
|
-
// src/commands/audit.ts
|
|
1424
|
-
var usage2 = `stack audit [dir]
|
|
1340
|
+
// ../kit/src/report.ts
|
|
1341
|
+
init_style();
|
|
1342
|
+
init_text();
|
|
1343
|
+
// ../kit/src/secrets.ts
|
|
1344
|
+
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1345
|
+
var NOT_PASSWORDS = new Set(["compass", "encompass", "bypass", "overpass", "underpass", "surpass", "trespass"]);
|
|
1346
|
+
// ../kit/src/sessions.ts
|
|
1347
|
+
var {Glob } = globalThis.Bun;
|
|
1348
|
+
var SESSION_FILES = new Glob("*.json");
|
|
1349
|
+
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1425
1350
|
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
var AUDIT_LIMIT = 25;
|
|
1432
|
-
var options = {
|
|
1433
|
-
...limitOptions(AUDIT_LIMIT),
|
|
1434
|
-
json: jsonOption("{ root, composeFiles, findings }")
|
|
1435
|
-
};
|
|
1436
|
-
async function audit2(args, overrides = {}) {
|
|
1437
|
-
const parsed = parse(args, usage2, options);
|
|
1438
|
-
const root = resolve4(parsed.positionals[0] ?? ".");
|
|
1439
|
-
if (!hasConfig(root)) {
|
|
1440
|
-
fail(`no ${CONFIG_FILE} in ${root}`);
|
|
1441
|
-
}
|
|
1442
|
-
const result = await audit(await loadConfig(root), { root, loadCompose: dockerCompose, env: process14.env, home: homedir4(), ...overrides });
|
|
1443
|
-
if (parsed.values.json === true)
|
|
1444
|
-
printJson(result);
|
|
1445
|
-
else
|
|
1446
|
-
console.log(render(result, limitOf(parsed.values, AUDIT_LIMIT)));
|
|
1447
|
-
return errorsOf(result).length > 0 ? 1 : 0;
|
|
1448
|
-
}
|
|
1351
|
+
// ../kit/src/index.ts
|
|
1352
|
+
init_style();
|
|
1353
|
+
init_text();
|
|
1354
|
+
init_theme();
|
|
1355
|
+
init_user_config();
|
|
1449
1356
|
|
|
1357
|
+
// ../kit/src/watch.ts
|
|
1358
|
+
init_args();
|
|
1359
|
+
init_input();
|
|
1360
|
+
init_style();
|
|
1361
|
+
// ../kit/src/workspace-root.ts
|
|
1362
|
+
init_user_config();
|
|
1450
1363
|
// src/port.ts
|
|
1451
1364
|
var MIN_PORT = 1024;
|
|
1452
1365
|
var MAX_PORT = 65535;
|
|
@@ -1459,36 +1372,28 @@ function stringToPort(name, min = MIN_PORT, max = DEFAULT_MAX_PORT) {
|
|
|
1459
1372
|
}
|
|
1460
1373
|
return min + hash % (max - min + 1);
|
|
1461
1374
|
}
|
|
1462
|
-
function isListening(port) {
|
|
1463
|
-
try {
|
|
1464
|
-
Bun.listen({ hostname: "0.0.0.0", port, socket: { data: () => {
|
|
1465
|
-
return;
|
|
1466
|
-
} } }).stop(true);
|
|
1467
|
-
return false;
|
|
1468
|
-
} catch (error) {
|
|
1469
|
-
return error.code === "EADDRINUSE";
|
|
1470
|
-
}
|
|
1471
|
-
}
|
|
1472
1375
|
|
|
1473
1376
|
// src/commands/port.ts
|
|
1474
|
-
var
|
|
1377
|
+
var usage2 = `stack port <name>
|
|
1475
1378
|
|
|
1476
1379
|
Prints the port a name always hashes to (32-bit FNV-1a, ${MIN_PORT}-${DEFAULT_MAX_PORT} by default, below Linux's ephemeral range), so a service keeps the same port on every machine.
|
|
1477
1380
|
Says on stderr when something already listens on it; the exit code stays 0.
|
|
1478
1381
|
|
|
1479
1382
|
Exits 0 when it printed the port, 2 on a usage error.`;
|
|
1480
|
-
var
|
|
1383
|
+
var options = {
|
|
1481
1384
|
min: { type: "string", description: `lowest port (${MIN_PORT}, nothing lower is allowed)` },
|
|
1482
|
-
max: { type: "string", description: `highest port (${DEFAULT_MAX_PORT}, up to ${MAX_PORT})` },
|
|
1385
|
+
max: { type: "string", description: `highest port (${DEFAULT_MAX_PORT}, or ${MAX_PORT} when --min reaches it, up to ${MAX_PORT})` },
|
|
1483
1386
|
json: jsonOption("{name, port, listening}")
|
|
1484
1387
|
};
|
|
1485
|
-
async function
|
|
1486
|
-
const parsed = parse(args,
|
|
1388
|
+
async function port2(args) {
|
|
1389
|
+
const parsed = parse(args, usage2, options);
|
|
1487
1390
|
const [name] = parsed.positionals;
|
|
1488
1391
|
if (name === undefined)
|
|
1489
1392
|
fail("a name is needed");
|
|
1490
1393
|
const min = wholeNumber(parsed.values.min, "min", MIN_PORT, MIN_PORT);
|
|
1491
|
-
|
|
1394
|
+
if (min > MAX_PORT)
|
|
1395
|
+
fail(`--min goes up to ${MAX_PORT}, not ${min}`);
|
|
1396
|
+
const max = wholeNumber(parsed.values.max, "max", min < DEFAULT_MAX_PORT ? DEFAULT_MAX_PORT : MAX_PORT, min);
|
|
1492
1397
|
if (max > MAX_PORT)
|
|
1493
1398
|
fail(`--max goes up to ${MAX_PORT}, not ${max}`);
|
|
1494
1399
|
const number = stringToPort(name, min, max);
|
|
@@ -1503,13 +1408,12 @@ async function port(args) {
|
|
|
1503
1408
|
}
|
|
1504
1409
|
|
|
1505
1410
|
// src/cli.ts
|
|
1506
|
-
|
|
1411
|
+
process16.exitCode = await runCli({
|
|
1507
1412
|
name: "stack",
|
|
1508
|
-
about: "a stable port per service name
|
|
1509
|
-
replaces: "picking a free host port by hand
|
|
1510
|
-
examples: ["stack port api", ["stack
|
|
1413
|
+
about: "a stable port per service name",
|
|
1414
|
+
replaces: "picking a free host port by hand",
|
|
1415
|
+
examples: ["stack port api", ["stack port api --json", "the port and whether something listens on it"]],
|
|
1511
1416
|
commands: {
|
|
1512
|
-
port: { run:
|
|
1513
|
-
audit: { run: audit2, summary: "cross-check release.config.ts against its compose files" }
|
|
1417
|
+
port: { run: port2, summary: "the port a name always hashes to, with a warning when something already listens on it" }
|
|
1514
1418
|
}
|
|
1515
1419
|
});
|