@kaynooo/cli-base 0.11.0 → 0.12.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/README.md +3 -3
- package/dist/cli.js +402 -155
- package/package.json +8 -10
- package/dist/proof-cli.js +0 -1559
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,6 +110,9 @@ 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";
|
|
@@ -118,36 +125,18 @@ function configBase(where = {}) {
|
|
|
118
125
|
function userConfigPath(bin, where = {}) {
|
|
119
126
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
120
127
|
}
|
|
128
|
+
var init_user_config = () => {};
|
|
121
129
|
|
|
122
130
|
// ../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+/;
|
|
131
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
132
|
+
import { homedir as homedir2 } from "os";
|
|
133
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
134
|
+
import process5 from "process";
|
|
145
135
|
function isColorSpec(spec) {
|
|
146
136
|
if (typeof spec === "number")
|
|
147
137
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
148
138
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
149
139
|
}
|
|
150
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
151
140
|
function cubeLevel(channel) {
|
|
152
141
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
153
142
|
}
|
|
@@ -252,7 +241,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
252
241
|
function endsWalk(home) {
|
|
253
242
|
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
254
243
|
}
|
|
255
|
-
var warned = new Set;
|
|
256
244
|
function warnOnce(message) {
|
|
257
245
|
if (warned.has(message))
|
|
258
246
|
return;
|
|
@@ -289,8 +277,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
289
277
|
}
|
|
290
278
|
return { theme, sources, preset };
|
|
291
279
|
}
|
|
292
|
-
var current;
|
|
293
|
-
var currentKey = "";
|
|
294
280
|
function activeTheme() {
|
|
295
281
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
296
282
|
if (current === undefined || key !== currentKey) {
|
|
@@ -299,8 +285,38 @@ function activeTheme() {
|
|
|
299
285
|
}
|
|
300
286
|
return current;
|
|
301
287
|
}
|
|
288
|
+
var ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
|
|
289
|
+
var init_theme = __esm(() => {
|
|
290
|
+
init_config();
|
|
291
|
+
init_user_config();
|
|
292
|
+
ENDS = new Map;
|
|
293
|
+
DEFAULT = {
|
|
294
|
+
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" },
|
|
295
|
+
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" },
|
|
296
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
297
|
+
bins: {},
|
|
298
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
299
|
+
};
|
|
300
|
+
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" };
|
|
301
|
+
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" };
|
|
302
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
303
|
+
PRESETS = {
|
|
304
|
+
default: {},
|
|
305
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
306
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
307
|
+
ascii: { glyphs: ASCII }
|
|
308
|
+
};
|
|
309
|
+
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"]);
|
|
310
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
311
|
+
CONTROL = /\p{Cc}/u;
|
|
312
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
313
|
+
SPACES = /\s+/;
|
|
314
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
315
|
+
warned = new Set;
|
|
316
|
+
});
|
|
302
317
|
|
|
303
318
|
// ../kit/src/style.ts
|
|
319
|
+
import process6 from "process";
|
|
304
320
|
function takesControlCodes(stream, env = process6.env) {
|
|
305
321
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
306
322
|
}
|
|
@@ -311,17 +327,23 @@ function role(name, stream, env = process6.env) {
|
|
|
311
327
|
const colors = paint(stream, env);
|
|
312
328
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
313
329
|
}
|
|
314
|
-
var STATUS_WORDS
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
330
|
+
var STATUS_WORDS, STATUS_OF;
|
|
331
|
+
var init_style = __esm(() => {
|
|
332
|
+
init_colors();
|
|
333
|
+
init_mode();
|
|
334
|
+
init_theme();
|
|
335
|
+
STATUS_WORDS = {
|
|
336
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
337
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
338
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
339
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
340
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
341
|
+
};
|
|
342
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
343
|
+
});
|
|
322
344
|
|
|
323
345
|
// ../kit/src/format.ts
|
|
324
|
-
|
|
346
|
+
import process7 from "process";
|
|
325
347
|
function formatSeconds(total) {
|
|
326
348
|
let rest = Math.max(0, Math.round(total));
|
|
327
349
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -342,21 +364,44 @@ function upTo(text, separator) {
|
|
|
342
364
|
const end = text.indexOf(separator);
|
|
343
365
|
return end === -1 ? text : text.slice(0, end);
|
|
344
366
|
}
|
|
345
|
-
var ESCAPE = String.fromCharCode(27);
|
|
346
367
|
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
347
368
|
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
348
369
|
}
|
|
349
370
|
function printJson(value) {
|
|
350
371
|
console.log(jsonText(value));
|
|
351
372
|
}
|
|
373
|
+
var UNITS, ESCAPE;
|
|
374
|
+
var init_format = __esm(() => {
|
|
375
|
+
init_mode();
|
|
376
|
+
init_style();
|
|
377
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
378
|
+
ESCAPE = String.fromCharCode(27);
|
|
379
|
+
});
|
|
352
380
|
|
|
353
381
|
// ../kit/src/help.ts
|
|
354
382
|
import process8 from "process";
|
|
355
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
356
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
357
|
-
var FULL_STOP = /\.$/;
|
|
358
383
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
359
|
-
|
|
384
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
385
|
+
`);
|
|
386
|
+
const blank = lines.indexOf("");
|
|
387
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
388
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
389
|
+
const colon = synopses[0].indexOf(": ");
|
|
390
|
+
const inline = synopses[0].slice(colon + 2);
|
|
391
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
392
|
+
if (colon !== -1)
|
|
393
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
394
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
395
|
+
`)}`;
|
|
396
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
397
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
398
|
+
return [head, ...lead, ...rest].join(`
|
|
399
|
+
`);
|
|
400
|
+
}
|
|
401
|
+
function prose(line, colors) {
|
|
402
|
+
if (colors.cyan("x") === "x")
|
|
403
|
+
return line;
|
|
404
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
360
405
|
}
|
|
361
406
|
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
362
407
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -391,7 +436,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
391
436
|
return [];
|
|
392
437
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
393
438
|
}
|
|
394
|
-
var MAX_INLINE_CHOICES = 24;
|
|
395
439
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
396
440
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
397
441
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -406,6 +450,15 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
406
450
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
407
451
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
408
452
|
}
|
|
453
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
454
|
+
var init_help = __esm(() => {
|
|
455
|
+
init_mode();
|
|
456
|
+
init_style();
|
|
457
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
458
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
459
|
+
FULL_STOP = /\.$/;
|
|
460
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
461
|
+
});
|
|
409
462
|
|
|
410
463
|
// ../kit/src/text.ts
|
|
411
464
|
function distance(a, b) {
|
|
@@ -433,8 +486,9 @@ function closest(name, names) {
|
|
|
433
486
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
434
487
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
435
488
|
}
|
|
489
|
+
var init_text = () => {};
|
|
490
|
+
|
|
436
491
|
// ../kit/src/input.ts
|
|
437
|
-
var WHOLE = /^\d+$/;
|
|
438
492
|
function wholeNumber(value, name, fallback, min = 1) {
|
|
439
493
|
if (value === undefined)
|
|
440
494
|
return fallback;
|
|
@@ -443,8 +497,6 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
443
497
|
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
444
498
|
return number;
|
|
445
499
|
}
|
|
446
|
-
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
447
|
-
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
448
500
|
function duration(value, name, fallback, unit = "s") {
|
|
449
501
|
if (value === undefined)
|
|
450
502
|
return fallback;
|
|
@@ -454,40 +506,27 @@ function duration(value, name, fallback, unit = "s") {
|
|
|
454
506
|
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
455
507
|
return ms;
|
|
456
508
|
}
|
|
509
|
+
var WHOLE, DURATION, UNIT_MS;
|
|
510
|
+
var init_input = __esm(() => {
|
|
511
|
+
init_args();
|
|
512
|
+
WHOLE = /^\d+$/;
|
|
513
|
+
DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
514
|
+
UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
515
|
+
});
|
|
457
516
|
|
|
458
517
|
// ../kit/src/args.ts
|
|
459
|
-
|
|
518
|
+
import process9 from "process";
|
|
519
|
+
import { parseArgs } from "util";
|
|
460
520
|
function jsonOption(holds) {
|
|
461
521
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
462
522
|
}
|
|
463
|
-
class Exit extends Error {
|
|
464
|
-
code;
|
|
465
|
-
hint;
|
|
466
|
-
constructor(message, code, hint) {
|
|
467
|
-
super(message);
|
|
468
|
-
this.code = code;
|
|
469
|
-
this.hint = hint;
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
523
|
function fail(message, code = 2, hint) {
|
|
473
524
|
throw new Exit(message, code, hint);
|
|
474
525
|
}
|
|
475
|
-
|
|
476
|
-
class UsageError extends Exit {
|
|
477
|
-
constructor(message, hint) {
|
|
478
|
-
super(message, 2, hint);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
526
|
function badUsage(message) {
|
|
482
527
|
throw new UsageError(message);
|
|
483
528
|
}
|
|
484
529
|
|
|
485
|
-
class HelpShown extends Exit {
|
|
486
|
-
constructor() {
|
|
487
|
-
super("help shown", 0);
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
|
|
491
530
|
class Completing {
|
|
492
531
|
options;
|
|
493
532
|
positionals;
|
|
@@ -498,11 +537,6 @@ class Completing {
|
|
|
498
537
|
this.candidates = candidates;
|
|
499
538
|
}
|
|
500
539
|
}
|
|
501
|
-
var completion = { active: false };
|
|
502
|
-
var OUTPUT_OPTIONS = {
|
|
503
|
-
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
504
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
505
|
-
};
|
|
506
540
|
function applyOutput(color, plain, env = process9.env) {
|
|
507
541
|
const when = plain === true ? "never" : color ?? "auto";
|
|
508
542
|
if (when === "auto")
|
|
@@ -656,7 +690,6 @@ function parseError(error) {
|
|
|
656
690
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
657
691
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
658
692
|
}
|
|
659
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
660
693
|
function nearestOption(message, options, allowNegative) {
|
|
661
694
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
662
695
|
if (typed === undefined)
|
|
@@ -672,6 +705,61 @@ function nearestOption(message, options, allowNegative) {
|
|
|
672
705
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
673
706
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
674
707
|
}
|
|
708
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
709
|
+
var init_args = __esm(() => {
|
|
710
|
+
init_format();
|
|
711
|
+
init_help();
|
|
712
|
+
init_text();
|
|
713
|
+
init_help();
|
|
714
|
+
init_input();
|
|
715
|
+
DASHES = /^-+/;
|
|
716
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
717
|
+
Exit = class Exit extends Error {
|
|
718
|
+
code;
|
|
719
|
+
hint;
|
|
720
|
+
[EXIT] = true;
|
|
721
|
+
constructor(message, code, hint) {
|
|
722
|
+
super(message);
|
|
723
|
+
this.code = code;
|
|
724
|
+
this.hint = hint;
|
|
725
|
+
}
|
|
726
|
+
static [Symbol.hasInstance](value) {
|
|
727
|
+
if (this !== Exit)
|
|
728
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
729
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
UsageError = class UsageError extends Exit {
|
|
733
|
+
constructor(message, hint) {
|
|
734
|
+
super(message, 2, hint);
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
HelpShown = class HelpShown extends Exit {
|
|
738
|
+
constructor() {
|
|
739
|
+
super("help shown", 0);
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
completion = { active: false };
|
|
743
|
+
OUTPUT_OPTIONS = {
|
|
744
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
745
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
746
|
+
};
|
|
747
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
748
|
+
});
|
|
749
|
+
|
|
750
|
+
// ../kit/src/folders.ts
|
|
751
|
+
var SKIPPED_FOLDERS;
|
|
752
|
+
var init_folders = __esm(() => {
|
|
753
|
+
init_user_config();
|
|
754
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
755
|
+
});
|
|
756
|
+
|
|
757
|
+
// src/cli.ts
|
|
758
|
+
import process20 from "process";
|
|
759
|
+
|
|
760
|
+
// ../kit/src/index.ts
|
|
761
|
+
init_args();
|
|
762
|
+
|
|
675
763
|
// ../kit/src/argv.ts
|
|
676
764
|
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
677
765
|
import { resolve as resolve3 } from "path";
|
|
@@ -696,6 +784,18 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
|
|
|
696
784
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
697
785
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
698
786
|
}
|
|
787
|
+
// ../kit/src/chart.ts
|
|
788
|
+
init_format();
|
|
789
|
+
init_mode();
|
|
790
|
+
init_style();
|
|
791
|
+
init_theme();
|
|
792
|
+
// ../kit/src/ci.ts
|
|
793
|
+
init_args();
|
|
794
|
+
init_format();
|
|
795
|
+
|
|
796
|
+
// ../kit/src/progress.ts
|
|
797
|
+
init_format();
|
|
798
|
+
|
|
699
799
|
// ../kit/src/process.ts
|
|
700
800
|
import { constants } from "os";
|
|
701
801
|
import process11 from "process";
|
|
@@ -739,10 +839,10 @@ function holdSignals(cleanup) {
|
|
|
739
839
|
process11.on(signal, onSignal);
|
|
740
840
|
return held;
|
|
741
841
|
}
|
|
742
|
-
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
842
|
+
async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
743
843
|
const chunks = [];
|
|
744
844
|
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
745
|
-
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
845
|
+
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin: input === undefined ? stdin : new TextEncoder().encode(input), stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
746
846
|
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
747
847
|
const timers = [];
|
|
748
848
|
const killGroup = (killing) => {
|
|
@@ -819,38 +919,152 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
819
919
|
}
|
|
820
920
|
|
|
821
921
|
// ../kit/src/progress.ts
|
|
922
|
+
init_style();
|
|
923
|
+
init_theme();
|
|
822
924
|
var ESC = String.fromCharCode(27);
|
|
823
925
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
824
926
|
var RESET_STYLE = `${ESC}[0m`;
|
|
825
927
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
928
|
+
|
|
929
|
+
// ../kit/src/ci.ts
|
|
930
|
+
init_style();
|
|
931
|
+
|
|
932
|
+
// ../kit/src/tool.ts
|
|
933
|
+
init_format();
|
|
826
934
|
// ../kit/src/cli.ts
|
|
935
|
+
init_args();
|
|
827
936
|
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
828
937
|
import { dirname as dirname3, join as join5 } from "path";
|
|
829
|
-
import
|
|
938
|
+
import process15 from "process";
|
|
830
939
|
|
|
831
|
-
// ../kit/src/
|
|
940
|
+
// ../kit/src/askpass.ts
|
|
832
941
|
import process12 from "process";
|
|
942
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
943
|
+
async function askpassClient(argv) {
|
|
944
|
+
const socketPath = process12.env[SOCKET_VARIABLE];
|
|
945
|
+
if (socketPath === undefined)
|
|
946
|
+
return;
|
|
947
|
+
const request = { prompt: argv[0] ?? "", ...process12.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
948
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
949
|
+
let received = "";
|
|
950
|
+
try {
|
|
951
|
+
await Bun.connect({
|
|
952
|
+
unix: socketPath,
|
|
953
|
+
socket: {
|
|
954
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
955
|
+
`),
|
|
956
|
+
data: (_, chunk) => {
|
|
957
|
+
received += chunk.toString();
|
|
958
|
+
},
|
|
959
|
+
close: () => resolve(received),
|
|
960
|
+
error: () => resolve("")
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
} catch {
|
|
964
|
+
return 1;
|
|
965
|
+
}
|
|
966
|
+
const reply = await promise;
|
|
967
|
+
if (reply === "")
|
|
968
|
+
return 1;
|
|
969
|
+
const { answer } = JSON.parse(reply);
|
|
970
|
+
if (request.notice === true)
|
|
971
|
+
return 0;
|
|
972
|
+
if (answer === undefined)
|
|
973
|
+
return 1;
|
|
974
|
+
process12.stdout.write(`${answer}
|
|
975
|
+
`);
|
|
976
|
+
return 0;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
// ../kit/src/completions.ts
|
|
980
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
981
|
+
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'
|
|
982
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
983
|
+
set -l current (commandline -ct)
|
|
984
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
985
|
+
if test "$line" = __files__
|
|
986
|
+
__fish_complete_path $current
|
|
987
|
+
else
|
|
988
|
+
echo $line
|
|
989
|
+
end
|
|
990
|
+
end
|
|
991
|
+
end`;
|
|
992
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
993
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
994
|
+
local -a lines
|
|
995
|
+
COMPREPLY=()
|
|
996
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
997
|
+
for line in "\${lines[@]}"; do
|
|
998
|
+
if [[ $line == __files__ ]]; then
|
|
999
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
1000
|
+
else
|
|
1001
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
1002
|
+
fi
|
|
1003
|
+
done
|
|
1004
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
1005
|
+
}`;
|
|
1006
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1007
|
+
local line
|
|
1008
|
+
local -a described plain
|
|
1009
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
1010
|
+
if [[ $line == __files__ ]]; then
|
|
1011
|
+
_files
|
|
1012
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
1013
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
1014
|
+
else
|
|
1015
|
+
plain+=("$line")
|
|
1016
|
+
fi
|
|
1017
|
+
done
|
|
1018
|
+
(( \${#described} )) && _describe -V value described
|
|
1019
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
1020
|
+
return 0
|
|
1021
|
+
}`;
|
|
1022
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
1023
|
+
if (shell === "fish")
|
|
1024
|
+
return `${header}
|
|
1025
|
+
${FISH_FUNCTION}
|
|
1026
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
1027
|
+
`).join("")}`;
|
|
1028
|
+
if (shell === "bash")
|
|
1029
|
+
return `${header}
|
|
1030
|
+
${BASH_FUNCTION}
|
|
1031
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1032
|
+
`;
|
|
1033
|
+
return `${header}
|
|
1034
|
+
${ZSH_FUNCTION}
|
|
1035
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1036
|
+
`;
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
// ../kit/src/notify.ts
|
|
1040
|
+
init_format();
|
|
1041
|
+
init_mode();
|
|
1042
|
+
import process13 from "process";
|
|
833
1043
|
var NOTIFY_AFTER_MS = 1e4;
|
|
834
1044
|
var CANCELLED = 130;
|
|
835
1045
|
function base64(text) {
|
|
836
1046
|
return Buffer.from(text).toString("base64");
|
|
837
1047
|
}
|
|
838
|
-
function notification(title, body, env =
|
|
839
|
-
const id = `kit${
|
|
1048
|
+
function notification(title, body, env = process13.env) {
|
|
1049
|
+
const id = `kit${process13.pid}`;
|
|
840
1050
|
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\\`];
|
|
841
1051
|
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
842
1052
|
}
|
|
843
|
-
function notifyEnd(command, code, ms, { stream =
|
|
1053
|
+
function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
|
|
844
1054
|
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
845
1055
|
return;
|
|
846
1056
|
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
847
1057
|
}
|
|
848
1058
|
|
|
1059
|
+
// ../kit/src/cli.ts
|
|
1060
|
+
init_style();
|
|
1061
|
+
init_text();
|
|
1062
|
+
|
|
849
1063
|
// ../kit/src/usage.ts
|
|
850
1064
|
import { appendFileSync, mkdirSync } from "fs";
|
|
851
1065
|
import { homedir as homedir3 } from "os";
|
|
852
1066
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
853
|
-
import
|
|
1067
|
+
import process14 from "process";
|
|
854
1068
|
|
|
855
1069
|
// ../kit/src/logs.ts
|
|
856
1070
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -864,14 +1078,14 @@ var usageError;
|
|
|
864
1078
|
function noteUsageError(message) {
|
|
865
1079
|
usageError = message;
|
|
866
1080
|
}
|
|
867
|
-
function stateHome(env =
|
|
1081
|
+
function stateHome(env = process14.env) {
|
|
868
1082
|
const dir = env.XDG_STATE_HOME;
|
|
869
1083
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
870
1084
|
}
|
|
871
|
-
function usagePath(env =
|
|
1085
|
+
function usagePath(env = process14.env) {
|
|
872
1086
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
873
1087
|
}
|
|
874
|
-
function usageRecorded(env =
|
|
1088
|
+
function usageRecorded(env = process14.env) {
|
|
875
1089
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
876
1090
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
877
1091
|
}
|
|
@@ -880,12 +1094,12 @@ function flagNames(argv) {
|
|
|
880
1094
|
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
881
1095
|
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
882
1096
|
}
|
|
883
|
-
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
1097
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
884
1098
|
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
885
1099
|
usageError = undefined;
|
|
886
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1100
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
887
1101
|
}
|
|
888
|
-
function recordUsage(entry, env =
|
|
1102
|
+
function recordUsage(entry, env = process14.env) {
|
|
889
1103
|
if (!usageRecorded(env))
|
|
890
1104
|
return;
|
|
891
1105
|
try {
|
|
@@ -901,7 +1115,11 @@ var LEVEL_OPTIONS = {
|
|
|
901
1115
|
...OUTPUT_OPTIONS,
|
|
902
1116
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
903
1117
|
};
|
|
904
|
-
var TOP_OPTIONS = {
|
|
1118
|
+
var TOP_OPTIONS = {
|
|
1119
|
+
...LEVEL_OPTIONS,
|
|
1120
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1121
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1122
|
+
};
|
|
905
1123
|
async function commandRows(all, colors) {
|
|
906
1124
|
const commands = shown(all);
|
|
907
1125
|
const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
|
|
@@ -975,8 +1193,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
975
1193
|
`);
|
|
976
1194
|
}
|
|
977
1195
|
function printError(prefix, message, hint, cause) {
|
|
978
|
-
const colors = paint(
|
|
979
|
-
const styled = takesControlCodes(
|
|
1196
|
+
const colors = paint(process15.stderr);
|
|
1197
|
+
const styled = takesControlCodes(process15.stderr);
|
|
980
1198
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
981
1199
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
982
1200
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1019,11 +1237,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1019
1237
|
}
|
|
1020
1238
|
}
|
|
1021
1239
|
if (name === undefined && level.path.length > 1) {
|
|
1022
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1240
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stderr));
|
|
1023
1241
|
return 2;
|
|
1024
1242
|
}
|
|
1025
1243
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1026
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1244
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stdout));
|
|
1027
1245
|
return 0;
|
|
1028
1246
|
}
|
|
1029
1247
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1134,6 +1352,19 @@ async function candidates(scope, defaultCommand, words, before = []) {
|
|
|
1134
1352
|
}
|
|
1135
1353
|
return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
|
|
1136
1354
|
}
|
|
1355
|
+
var COMPLETIONS = "--completions";
|
|
1356
|
+
function flagValue([flag = "", ...rest]) {
|
|
1357
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1358
|
+
}
|
|
1359
|
+
function printCompletionScript(name, args) {
|
|
1360
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1361
|
+
if (shell === undefined || args.length !== 1) {
|
|
1362
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1363
|
+
return 2;
|
|
1364
|
+
}
|
|
1365
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1366
|
+
return 0;
|
|
1367
|
+
}
|
|
1137
1368
|
async function printCandidates(found) {
|
|
1138
1369
|
for (const line of await found)
|
|
1139
1370
|
console.log(line);
|
|
@@ -1156,15 +1387,20 @@ function packageVersion(entry = Bun.main) {
|
|
|
1156
1387
|
}
|
|
1157
1388
|
async function runCli(cli, argv = scriptArgs()) {
|
|
1158
1389
|
const version = cli.version ?? packageVersion();
|
|
1390
|
+
const answered = await askpassClient(argv);
|
|
1391
|
+
if (answered !== undefined)
|
|
1392
|
+
return answered;
|
|
1159
1393
|
if (argv[0] === COMPLETE)
|
|
1160
1394
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1395
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1396
|
+
return printCompletionScript(cli.name, flagValue(argv));
|
|
1161
1397
|
const started = performance.now();
|
|
1162
1398
|
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 });
|
|
1163
1399
|
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
|
1164
1400
|
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1165
1401
|
if (cli.usage !== false) {
|
|
1166
1402
|
try {
|
|
1167
|
-
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
1403
|
+
recordUsage(usageEntry(cli.name, command, argv, code, { ms: performance.now() - started }));
|
|
1168
1404
|
} catch {}
|
|
1169
1405
|
}
|
|
1170
1406
|
return code;
|
|
@@ -1184,44 +1420,55 @@ function commandPath(scope, argv) {
|
|
|
1184
1420
|
}
|
|
1185
1421
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1186
1422
|
}
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
// ../kit/src/folders.ts
|
|
1210
|
-
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1423
|
+
|
|
1424
|
+
// ../kit/src/index.ts
|
|
1425
|
+
init_config();
|
|
1426
|
+
|
|
1427
|
+
// ../kit/src/excerpt.ts
|
|
1428
|
+
init_text();
|
|
1429
|
+
|
|
1430
|
+
// ../kit/src/index.ts
|
|
1431
|
+
init_folders();
|
|
1432
|
+
init_format();
|
|
1433
|
+
|
|
1434
|
+
// ../kit/src/git.ts
|
|
1435
|
+
init_args();
|
|
1436
|
+
// ../kit/src/limit.ts
|
|
1437
|
+
init_args();
|
|
1438
|
+
|
|
1439
|
+
// ../kit/src/index.ts
|
|
1440
|
+
init_mode();
|
|
1441
|
+
|
|
1442
|
+
// ../kit/src/report.ts
|
|
1443
|
+
init_style();
|
|
1444
|
+
init_text();
|
|
1211
1445
|
// ../kit/src/secrets.ts
|
|
1212
1446
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1213
1447
|
// ../kit/src/sessions.ts
|
|
1214
1448
|
var {Glob } = globalThis.Bun;
|
|
1215
1449
|
var SESSION_FILES = new Glob("*.json");
|
|
1216
1450
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1451
|
+
|
|
1452
|
+
// ../kit/src/index.ts
|
|
1453
|
+
init_style();
|
|
1454
|
+
init_text();
|
|
1455
|
+
init_theme();
|
|
1456
|
+
init_user_config();
|
|
1457
|
+
|
|
1458
|
+
// ../kit/src/watch.ts
|
|
1459
|
+
init_args();
|
|
1460
|
+
init_input();
|
|
1461
|
+
init_style();
|
|
1462
|
+
// ../kit/src/workspace-root.ts
|
|
1463
|
+
init_user_config();
|
|
1217
1464
|
// src/base.ts
|
|
1218
|
-
import
|
|
1465
|
+
import process18 from "process";
|
|
1219
1466
|
|
|
1220
1467
|
// src/worktree.ts
|
|
1221
1468
|
import { cpSync, existsSync as existsSync3, lstatSync, mkdirSync as mkdirSync2, mkdtempSync, readdirSync, realpathSync as realpathSync3, rmSync, symlinkSync, unlinkSync } from "fs";
|
|
1222
1469
|
import { tmpdir } from "os";
|
|
1223
1470
|
import { basename, dirname as dirname4, isAbsolute as isAbsolute2, join as join6, relative, resolve as resolve4, sep } from "path";
|
|
1224
|
-
import
|
|
1471
|
+
import process17 from "process";
|
|
1225
1472
|
var WHITESPACE = /\s/;
|
|
1226
1473
|
var ORIGIN_PREFIX = /^origin\//;
|
|
1227
1474
|
var ENV_FILE = /^\.env(?:\..+)?$/;
|
|
@@ -1377,7 +1624,7 @@ async function sweepStale(root) {
|
|
|
1377
1624
|
continue;
|
|
1378
1625
|
const path = join6(tmpdir(), name);
|
|
1379
1626
|
const stat = lstatSync(path, { throwIfNoEntry: false });
|
|
1380
|
-
if (stat?.isDirectory() === true && stat.uid ===
|
|
1627
|
+
if (stat?.isDirectory() === true && stat.uid === process17.getuid?.() && Date.now() - stat.mtimeMs > STALE_AFTER)
|
|
1381
1628
|
rmSync(path, { recursive: true, force: true });
|
|
1382
1629
|
}
|
|
1383
1630
|
await git2(["worktree", "prune"], root);
|
|
@@ -1474,21 +1721,21 @@ ${USAGE}`);
|
|
|
1474
1721
|
if (runsInContainer(given))
|
|
1475
1722
|
fail("a container of the compose project mounts the main checkout, not the temporary worktree, so the command would not run at the ref: run the tool on the host, or check the ref out by hand");
|
|
1476
1723
|
const command = shellCommand(given);
|
|
1477
|
-
const cwd =
|
|
1724
|
+
const cwd = process18.cwd();
|
|
1478
1725
|
const { root, prefix } = await checkout(cwd);
|
|
1479
1726
|
const ref = parsed.values.ref ?? "HEAD";
|
|
1480
1727
|
const sha = await resolveRef(root, ref);
|
|
1481
1728
|
const kept = keptPaths(root, cwd, parsed.values.keep ?? []);
|
|
1482
1729
|
const ran = await inWorktree({ root, prefix, sha, ref, kept, link: parsed.values["no-link"] !== true }, async (runDir, signals) => runIn(runDir, command, signals));
|
|
1483
1730
|
if (!ran.started)
|
|
1484
|
-
console.error(`${role("problem",
|
|
1485
|
-
console.error(`${role("label",
|
|
1731
|
+
console.error(`${role("problem", process18.stderr)("base:")} ${ran.output}`);
|
|
1732
|
+
console.error(`${role("label", process18.stderr)("base:")} ran at ${ref} (${sha.slice(0, 7)}), exit ${ran.code}`);
|
|
1486
1733
|
return ran.code;
|
|
1487
1734
|
}
|
|
1488
1735
|
|
|
1489
1736
|
// src/proof.ts
|
|
1490
|
-
import
|
|
1491
|
-
var USAGE2 = `proof [--ref <rev>] [--runs <n>] [--keep <path>...] [--timeout <duration>] [--no-link] [--json] -- <command> [args...]: runs the command at HEAD or another ref in a temporary worktree, then in the working tree, to show that a test fails before a change and passes after it
|
|
1737
|
+
import process19 from "process";
|
|
1738
|
+
var USAGE2 = `base proof [--ref <rev>] [--runs <n>] [--keep <path>...] [--timeout <duration>] [--no-link] [--json] -- <command> [args...]: runs the command at HEAD or another ref in a temporary worktree, then in the working tree, to show that a test fails before a change and passes after it
|
|
1492
1739
|
|
|
1493
1740
|
The ref defaults to the merge base with the default branch of origin (origin/main unless origin/HEAD names another) when HEAD is on a branch ahead of it, else HEAD. --runs <n> runs the command n times now, for a flaky test, and every run must pass. --timeout kills a run that lasts longer (a hung test), which says nothing about the change and ends with exit 2.`;
|
|
1494
1741
|
var EXITS = [[0, "the command fails before and passes in every run now"], [1, "it passes before too, fails in any run now, or passes before and fails now"], [2, "a usage error, an unknown ref, a command that cannot start, ends with exit 126, 127, 125 or a signal, or runs past --timeout"], [130, "interrupted (128 plus the signal)"]];
|
|
@@ -1529,7 +1776,7 @@ function describe(outcome, at, now) {
|
|
|
1529
1776
|
}
|
|
1530
1777
|
async function proof(argv) {
|
|
1531
1778
|
const bare = argv[0] !== undefined && !argv[0].startsWith("-");
|
|
1532
|
-
const parsed = parse(bare ? [] : argv, USAGE2, OPTIONS2, { rest: true, exits: EXITS, replaces: "running a test, stashing the change and running it again", examples: [["proof --keep tests/fix.test.ts -- bun test tests/fix.test.ts", "the new test fails at HEAD and passes now"], ["proof --ref v1.2.0 --keep tests/fix.test.ts -- bun test tests/fix.test.ts", "the same against a release"]] });
|
|
1779
|
+
const parsed = parse(bare ? [] : argv, USAGE2, OPTIONS2, { rest: true, exits: EXITS, replaces: "running a test, stashing the change and running it again", examples: [["base proof --keep tests/fix.test.ts -- bun test tests/fix.test.ts", "the new test fails at HEAD and passes now"], ["base proof --ref v1.2.0 --keep tests/fix.test.ts -- bun test tests/fix.test.ts", "the same against a release"]] });
|
|
1533
1780
|
const given = bare ? argv : parsed.rest ?? [];
|
|
1534
1781
|
if (given.length === 0 || parsed.positionals.length > 0)
|
|
1535
1782
|
fail(`give the command after --
|
|
@@ -1538,7 +1785,7 @@ ${USAGE2}`);
|
|
|
1538
1785
|
if (runsInContainer(given))
|
|
1539
1786
|
fail("a container of the compose project mounts the main checkout, not the temporary worktree, so the command would not run at the ref: run the tool on the host, or check the ref out by hand");
|
|
1540
1787
|
const command = shellCommand(given);
|
|
1541
|
-
const cwd =
|
|
1788
|
+
const cwd = process19.cwd();
|
|
1542
1789
|
const { root, prefix } = await checkout(cwd);
|
|
1543
1790
|
const runs = wholeNumber(parsed.values.runs, "runs", 1, 1);
|
|
1544
1791
|
const ref = parsed.values.ref ?? await defaultProofRef(root);
|
|
@@ -1578,7 +1825,7 @@ ${folded(run.output)}`}`);
|
|
|
1578
1825
|
printJson({ outcome, proved, ref, sha, before: { code: before.code, output: before.output }, now: { code: now.code, output: now.output }, runs: nowRuns.map((run) => ({ code: run.code })) });
|
|
1579
1826
|
return proved ? 0 : 1;
|
|
1580
1827
|
}
|
|
1581
|
-
console.log(role(proved ? "ok" : "problem",
|
|
1828
|
+
console.log(role(proved ? "ok" : "problem", process19.stdout)(message));
|
|
1582
1829
|
if (runs > 1)
|
|
1583
1830
|
console.log(`now: ${codes.map((code, i) => `run ${i + 1} ${code === 0 ? "passed" : `failed (exit ${code})`}`).join(", ")}`);
|
|
1584
1831
|
const shown = side === "before" ? before : now;
|
|
@@ -1589,7 +1836,7 @@ ${folded(shown.output)}`);
|
|
|
1589
1836
|
}
|
|
1590
1837
|
|
|
1591
1838
|
// src/cli.ts
|
|
1592
|
-
|
|
1839
|
+
process20.exitCode = await runCli({
|
|
1593
1840
|
name: "base",
|
|
1594
1841
|
about: "runs a command at HEAD or another ref in a temporary worktree, the working tree untouched",
|
|
1595
1842
|
replaces: "git stash, a test run, then git stash pop",
|