@kaynooo/cli-edit 0.11.2 → 0.11.3
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 -0
- package/dist/cli.js +355 -156
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -35,3 +35,5 @@ EOF
|
|
|
35
35
|
- `--quiet` prints nothing on success. Each written file prints `<path>: N replacements on lines L, +added -removed`; `--diff` adds its unified diff (through the system's `diff`), `--dry-run` shows the same without writing.
|
|
36
36
|
- The file is rewritten in place, so its mode, owner and missing trailing newline stay.
|
|
37
37
|
- Exit codes: 0 written, 1 a replacement did not match as expected, 2 a usage error.
|
|
38
|
+
- A folder given as a file is walked, `.gitignore` respected and binary files left out; a file in it where nothing matches is skipped and listed (`--skip-missing`), the count checks holding for the others.
|
|
39
|
+
- A producer silent on stdin for 3 s is taken for no heredoc at all, so write a slow one to a file first.
|
package/dist/cli.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
2
|
// @bun
|
|
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
|
+
};
|
|
3
14
|
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
import { normalize, resolve as resolve4 } from "path";
|
|
7
|
-
import process17 from "process";
|
|
8
|
-
// ../kit/src/args.ts
|
|
9
|
-
import process10 from "process";
|
|
10
|
-
import { parseArgs } from "util";
|
|
11
|
-
|
|
12
|
-
// ../kit/src/format.ts
|
|
13
|
-
import process7 from "process";
|
|
14
|
-
|
|
15
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
16
|
-
var ct = /[aeiou]y$/;
|
|
17
|
-
var N = new Map;
|
|
18
|
-
var Ot = /(?:leaf|loaf|thief|wolf|half|calf|elf|sheaf|scarf|dwarf|hoof|wharf)$/;
|
|
19
|
-
var Gt = /(?:knife|life|wife)$/;
|
|
20
|
-
function K(t, e, { plural: r, zero: n = "singular" } = {}) {
|
|
15
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rkhsft4a.js
|
|
16
|
+
function G(t, e, { plural: r, zero: n = "singular" } = {}) {
|
|
21
17
|
if (e === 1 || e === 0 && n === "singular")
|
|
22
18
|
return t;
|
|
23
19
|
if (r !== undefined)
|
|
@@ -30,16 +26,26 @@ function K(t, e, { plural: r, zero: n = "singular" } = {}) {
|
|
|
30
26
|
return `${t.slice(0, -1)}ves`;
|
|
31
27
|
return Gt.test(t) ? `${t.slice(0, -2)}ves` : `${t}s`;
|
|
32
28
|
}
|
|
33
|
-
function
|
|
34
|
-
return `${t} ${
|
|
35
|
-
}
|
|
36
|
-
var
|
|
37
|
-
var
|
|
29
|
+
function bo(t, e, { zero: r = "plural", ...n } = {}) {
|
|
30
|
+
return `${t} ${G(e, t, { ...n, zero: r })}`;
|
|
31
|
+
}
|
|
32
|
+
var ct, N, Ot, Gt, be, W;
|
|
33
|
+
var init_chunk_rkhsft4a = __esm(() => {
|
|
34
|
+
ct = /[aeiou]y$/;
|
|
35
|
+
N = new Map;
|
|
36
|
+
Ot = /(?:leaf|loaf|thief|wolf|half|calf|elf|sheaf|scarf|dwarf|hoof|wharf)$/;
|
|
37
|
+
Gt = /(?:knife|life|wife)$/;
|
|
38
|
+
be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
39
|
+
W = new Map;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
|
|
43
|
+
var init_text = __esm(() => {
|
|
44
|
+
init_chunk_rkhsft4a();
|
|
45
|
+
});
|
|
38
46
|
|
|
39
47
|
// ../kit/src/mode.ts
|
|
40
48
|
import process2 from "process";
|
|
41
|
-
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
42
|
-
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
43
49
|
function isSet(value) {
|
|
44
50
|
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
45
51
|
}
|
|
@@ -53,12 +59,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
53
59
|
return "terminal";
|
|
54
60
|
return isSet(env.CI) ? "ci" : "pipe";
|
|
55
61
|
}
|
|
62
|
+
var MODES, AGENT_VARIABLES;
|
|
63
|
+
var init_mode = __esm(() => {
|
|
64
|
+
MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
65
|
+
AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
66
|
+
});
|
|
56
67
|
|
|
57
|
-
//
|
|
58
|
-
import process6 from "process";
|
|
59
|
-
|
|
60
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
61
|
-
var G2 = /^[a-f0-9]+$/i;
|
|
68
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
62
69
|
function b(r) {
|
|
63
70
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
64
71
|
if (!G2.test(e))
|
|
@@ -69,11 +76,6 @@ function b(r) {
|
|
|
69
76
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
70
77
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
71
78
|
}
|
|
72
|
-
var B2 = { 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") => {
|
|
73
|
-
let [l, n, c] = b(r);
|
|
74
|
-
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
75
|
-
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
76
|
-
var h = new Set(["", "1", "2", "3", "true"]);
|
|
77
79
|
function C(r, e = globalThis.process?.env ?? {}) {
|
|
78
80
|
if (e.FORCE_COLOR !== undefined)
|
|
79
81
|
return h.has(e.FORCE_COLOR);
|
|
@@ -87,7 +89,7 @@ function f(r, e = []) {
|
|
|
87
89
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
88
90
|
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
89
91
|
return new Proxy(c, { get(t, i) {
|
|
90
|
-
let a =
|
|
92
|
+
let a = B[i];
|
|
91
93
|
if (Array.isArray(a)) {
|
|
92
94
|
let s = g.get(i);
|
|
93
95
|
if (s === undefined)
|
|
@@ -110,13 +112,21 @@ function f(r, e = []) {
|
|
|
110
112
|
function Fe(r = {}) {
|
|
111
113
|
return f(r);
|
|
112
114
|
}
|
|
113
|
-
var
|
|
115
|
+
var G2, B, h, o;
|
|
116
|
+
var init_chunk_x450vn3m = __esm(() => {
|
|
117
|
+
G2 = /^[a-f0-9]+$/i;
|
|
118
|
+
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") => {
|
|
119
|
+
let [l, n, c] = b(r);
|
|
120
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
121
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
122
|
+
h = new Set(["", "1", "2", "3", "true"]);
|
|
123
|
+
o = Fe();
|
|
124
|
+
});
|
|
114
125
|
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
import process5 from "process";
|
|
126
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
|
|
127
|
+
var init_colors = __esm(() => {
|
|
128
|
+
init_chunk_x450vn3m();
|
|
129
|
+
});
|
|
120
130
|
|
|
121
131
|
// ../kit/src/config.ts
|
|
122
132
|
import { existsSync } from "fs";
|
|
@@ -132,6 +142,9 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
132
142
|
return;
|
|
133
143
|
}
|
|
134
144
|
}
|
|
145
|
+
var init_config = __esm(() => {
|
|
146
|
+
init_args();
|
|
147
|
+
});
|
|
135
148
|
|
|
136
149
|
// ../kit/src/user-config.ts
|
|
137
150
|
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
@@ -163,36 +176,18 @@ function readUserConfig(bin, where = {}, legacy = []) {
|
|
|
163
176
|
return {};
|
|
164
177
|
}
|
|
165
178
|
}
|
|
179
|
+
var init_user_config = () => {};
|
|
166
180
|
|
|
167
181
|
// ../kit/src/theme.ts
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
173
|
-
bins: {},
|
|
174
|
-
gradient: ["#c084fc", "#67e8f9"]
|
|
175
|
-
};
|
|
176
|
-
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" };
|
|
177
|
-
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" };
|
|
178
|
-
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
179
|
-
var PRESETS = {
|
|
180
|
-
default: {},
|
|
181
|
-
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
182
|
-
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
183
|
-
ascii: { glyphs: ASCII }
|
|
184
|
-
};
|
|
185
|
-
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"]);
|
|
186
|
-
var HEX = /^#[0-9a-f]{6}$/i;
|
|
187
|
-
var CONTROL = /\p{Cc}/u;
|
|
188
|
-
var MAX_FILE_BYTES = 64 * 1024;
|
|
189
|
-
var SPACES = /\s+/;
|
|
182
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
183
|
+
import { homedir as homedir2 } from "os";
|
|
184
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
185
|
+
import process5 from "process";
|
|
190
186
|
function isColorSpec(spec) {
|
|
191
187
|
if (typeof spec === "number")
|
|
192
188
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
193
189
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
194
190
|
}
|
|
195
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
196
191
|
function cubeLevel(channel) {
|
|
197
192
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
198
193
|
}
|
|
@@ -297,7 +292,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
297
292
|
function endsWalk(home) {
|
|
298
293
|
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
299
294
|
}
|
|
300
|
-
var warned = new Set;
|
|
301
295
|
function warnOnce(message) {
|
|
302
296
|
if (warned.has(message))
|
|
303
297
|
return;
|
|
@@ -334,8 +328,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
334
328
|
}
|
|
335
329
|
return { theme, sources, preset };
|
|
336
330
|
}
|
|
337
|
-
var current;
|
|
338
|
-
var currentKey = "";
|
|
339
331
|
function activeTheme() {
|
|
340
332
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
341
333
|
if (current === undefined || key !== currentKey) {
|
|
@@ -344,8 +336,38 @@ function activeTheme() {
|
|
|
344
336
|
}
|
|
345
337
|
return current;
|
|
346
338
|
}
|
|
339
|
+
var ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
|
|
340
|
+
var init_theme = __esm(() => {
|
|
341
|
+
init_config();
|
|
342
|
+
init_user_config();
|
|
343
|
+
ENDS = new Map;
|
|
344
|
+
DEFAULT = {
|
|
345
|
+
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" },
|
|
346
|
+
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" },
|
|
347
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
348
|
+
bins: {},
|
|
349
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
350
|
+
};
|
|
351
|
+
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" };
|
|
352
|
+
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" };
|
|
353
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
354
|
+
PRESETS = {
|
|
355
|
+
default: {},
|
|
356
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
357
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
358
|
+
ascii: { glyphs: ASCII }
|
|
359
|
+
};
|
|
360
|
+
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"]);
|
|
361
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
362
|
+
CONTROL = /\p{Cc}/u;
|
|
363
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
364
|
+
SPACES = /\s+/;
|
|
365
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
366
|
+
warned = new Set;
|
|
367
|
+
});
|
|
347
368
|
|
|
348
369
|
// ../kit/src/style.ts
|
|
370
|
+
import process6 from "process";
|
|
349
371
|
function takesControlCodes(stream, env = process6.env) {
|
|
350
372
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
351
373
|
}
|
|
@@ -356,17 +378,23 @@ function role(name, stream, env = process6.env) {
|
|
|
356
378
|
const colors = paint(stream, env);
|
|
357
379
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
358
380
|
}
|
|
359
|
-
var STATUS_WORDS
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
381
|
+
var STATUS_WORDS, STATUS_OF;
|
|
382
|
+
var init_style = __esm(() => {
|
|
383
|
+
init_colors();
|
|
384
|
+
init_mode();
|
|
385
|
+
init_theme();
|
|
386
|
+
STATUS_WORDS = {
|
|
387
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
388
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
389
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
390
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
391
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
392
|
+
};
|
|
393
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
394
|
+
});
|
|
367
395
|
|
|
368
396
|
// ../kit/src/format.ts
|
|
369
|
-
|
|
397
|
+
import process7 from "process";
|
|
370
398
|
function formatSeconds(total) {
|
|
371
399
|
let rest = Math.max(0, Math.round(total));
|
|
372
400
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -387,21 +415,44 @@ function upTo(text, separator) {
|
|
|
387
415
|
const end = text.indexOf(separator);
|
|
388
416
|
return end === -1 ? text : text.slice(0, end);
|
|
389
417
|
}
|
|
390
|
-
var ESCAPE = String.fromCharCode(27);
|
|
391
418
|
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
392
419
|
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
393
420
|
}
|
|
394
421
|
function printJson(value) {
|
|
395
422
|
console.log(jsonText(value));
|
|
396
423
|
}
|
|
424
|
+
var UNITS, ESCAPE;
|
|
425
|
+
var init_format = __esm(() => {
|
|
426
|
+
init_mode();
|
|
427
|
+
init_style();
|
|
428
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
429
|
+
ESCAPE = String.fromCharCode(27);
|
|
430
|
+
});
|
|
397
431
|
|
|
398
432
|
// ../kit/src/help.ts
|
|
399
433
|
import process8 from "process";
|
|
400
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
401
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
402
|
-
var FULL_STOP = /\.$/;
|
|
403
434
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
404
|
-
|
|
435
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
436
|
+
`);
|
|
437
|
+
const blank = lines.indexOf("");
|
|
438
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
439
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
440
|
+
const colon = synopses[0].indexOf(": ");
|
|
441
|
+
const inline = synopses[0].slice(colon + 2);
|
|
442
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
443
|
+
if (colon !== -1)
|
|
444
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
445
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
446
|
+
`)}`;
|
|
447
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
448
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
449
|
+
return [head, ...lead, ...rest].join(`
|
|
450
|
+
`);
|
|
451
|
+
}
|
|
452
|
+
function prose(line, colors) {
|
|
453
|
+
if (colors.cyan("x") === "x")
|
|
454
|
+
return line;
|
|
455
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
405
456
|
}
|
|
406
457
|
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
407
458
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -436,7 +487,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
436
487
|
return [];
|
|
437
488
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
438
489
|
}
|
|
439
|
-
var MAX_INLINE_CHOICES = 24;
|
|
440
490
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
441
491
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
442
492
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -451,6 +501,15 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
451
501
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
452
502
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
453
503
|
}
|
|
504
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
505
|
+
var init_help = __esm(() => {
|
|
506
|
+
init_mode();
|
|
507
|
+
init_style();
|
|
508
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
509
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
510
|
+
FULL_STOP = /\.$/;
|
|
511
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
512
|
+
});
|
|
454
513
|
|
|
455
514
|
// ../kit/src/text.ts
|
|
456
515
|
function distance(a, b) {
|
|
@@ -478,9 +537,10 @@ function closest(name, names) {
|
|
|
478
537
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
479
538
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
480
539
|
}
|
|
540
|
+
var init_text2 = () => {};
|
|
541
|
+
|
|
481
542
|
// ../kit/src/input.ts
|
|
482
543
|
import process9 from "process";
|
|
483
|
-
var WHOLE = /^\d+$/;
|
|
484
544
|
function wholeNumber(value, name, fallback, min = 1) {
|
|
485
545
|
if (value === undefined)
|
|
486
546
|
return fallback;
|
|
@@ -500,40 +560,25 @@ async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
|
500
560
|
fail(`no file ${path}`);
|
|
501
561
|
return file.text();
|
|
502
562
|
}
|
|
563
|
+
var WHOLE;
|
|
564
|
+
var init_input = __esm(() => {
|
|
565
|
+
init_args();
|
|
566
|
+
WHOLE = /^\d+$/;
|
|
567
|
+
});
|
|
503
568
|
|
|
504
569
|
// ../kit/src/args.ts
|
|
505
|
-
|
|
570
|
+
import process10 from "process";
|
|
571
|
+
import { parseArgs } from "util";
|
|
506
572
|
function jsonOption(holds) {
|
|
507
573
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
508
574
|
}
|
|
509
|
-
class Exit extends Error {
|
|
510
|
-
code;
|
|
511
|
-
hint;
|
|
512
|
-
constructor(message, code, hint) {
|
|
513
|
-
super(message);
|
|
514
|
-
this.code = code;
|
|
515
|
-
this.hint = hint;
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
575
|
function fail(message, code = 2, hint) {
|
|
519
576
|
throw new Exit(message, code, hint);
|
|
520
577
|
}
|
|
521
|
-
|
|
522
|
-
class UsageError extends Exit {
|
|
523
|
-
constructor(message, hint) {
|
|
524
|
-
super(message, 2, hint);
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
578
|
function badUsage(message) {
|
|
528
579
|
throw new UsageError(message);
|
|
529
580
|
}
|
|
530
581
|
|
|
531
|
-
class HelpShown extends Exit {
|
|
532
|
-
constructor() {
|
|
533
|
-
super("help shown", 0);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
|
|
537
582
|
class Completing {
|
|
538
583
|
options;
|
|
539
584
|
positionals;
|
|
@@ -544,11 +589,6 @@ class Completing {
|
|
|
544
589
|
this.candidates = candidates;
|
|
545
590
|
}
|
|
546
591
|
}
|
|
547
|
-
var completion = { active: false };
|
|
548
|
-
var OUTPUT_OPTIONS = {
|
|
549
|
-
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
550
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
551
|
-
};
|
|
552
592
|
function applyOutput(color, plain, env = process10.env) {
|
|
553
593
|
const when = plain === true ? "never" : color ?? "auto";
|
|
554
594
|
if (when === "auto")
|
|
@@ -702,7 +742,6 @@ function parseError(error) {
|
|
|
702
742
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
703
743
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
704
744
|
}
|
|
705
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
706
745
|
function nearestOption(message, options, allowNegative) {
|
|
707
746
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
708
747
|
if (typed === undefined)
|
|
@@ -718,6 +757,68 @@ function nearestOption(message, options, allowNegative) {
|
|
|
718
757
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
719
758
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
720
759
|
}
|
|
760
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
761
|
+
var init_args = __esm(() => {
|
|
762
|
+
init_format();
|
|
763
|
+
init_help();
|
|
764
|
+
init_text2();
|
|
765
|
+
init_help();
|
|
766
|
+
init_input();
|
|
767
|
+
DASHES = /^-+/;
|
|
768
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
769
|
+
Exit = class Exit extends Error {
|
|
770
|
+
code;
|
|
771
|
+
hint;
|
|
772
|
+
[EXIT] = true;
|
|
773
|
+
constructor(message, code, hint) {
|
|
774
|
+
super(message);
|
|
775
|
+
this.code = code;
|
|
776
|
+
this.hint = hint;
|
|
777
|
+
}
|
|
778
|
+
static [Symbol.hasInstance](value) {
|
|
779
|
+
if (this !== Exit)
|
|
780
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
781
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
UsageError = class UsageError extends Exit {
|
|
785
|
+
constructor(message, hint) {
|
|
786
|
+
super(message, 2, hint);
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
HelpShown = class HelpShown extends Exit {
|
|
790
|
+
constructor() {
|
|
791
|
+
super("help shown", 0);
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
completion = { active: false };
|
|
795
|
+
OUTPUT_OPTIONS = {
|
|
796
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
797
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
798
|
+
};
|
|
799
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
// ../kit/src/folders.ts
|
|
803
|
+
function ignoredFolders(extra = [], where = {}) {
|
|
804
|
+
const configured = readUserConfig("config", where).ignore;
|
|
805
|
+
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
806
|
+
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
807
|
+
}
|
|
808
|
+
var SKIPPED_FOLDERS;
|
|
809
|
+
var init_folders = __esm(() => {
|
|
810
|
+
init_user_config();
|
|
811
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
// src/cli.ts
|
|
815
|
+
import { accessSync, chmodSync, constants as constants2, existsSync as existsSync5, readFileSync as readFileSync5, realpathSync as realpathSync3, renameSync, rmSync as rmSync2, statSync as statSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
816
|
+
import { normalize, resolve as resolve4 } from "path";
|
|
817
|
+
import process18 from "process";
|
|
818
|
+
|
|
819
|
+
// ../kit/src/index.ts
|
|
820
|
+
init_args();
|
|
821
|
+
|
|
721
822
|
// ../kit/src/argv.ts
|
|
722
823
|
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
723
824
|
import { resolve as resolve3 } from "path";
|
|
@@ -742,6 +843,18 @@ function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), scr
|
|
|
742
843
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
743
844
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
744
845
|
}
|
|
846
|
+
// ../kit/src/chart.ts
|
|
847
|
+
init_format();
|
|
848
|
+
init_mode();
|
|
849
|
+
init_style();
|
|
850
|
+
init_theme();
|
|
851
|
+
// ../kit/src/ci.ts
|
|
852
|
+
init_args();
|
|
853
|
+
init_format();
|
|
854
|
+
|
|
855
|
+
// ../kit/src/progress.ts
|
|
856
|
+
init_format();
|
|
857
|
+
|
|
745
858
|
// ../kit/src/process.ts
|
|
746
859
|
import { constants } from "os";
|
|
747
860
|
import process12 from "process";
|
|
@@ -753,10 +866,10 @@ function exitCodeOf(code, signal) {
|
|
|
753
866
|
return 128 + signal;
|
|
754
867
|
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
755
868
|
}
|
|
756
|
-
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
869
|
+
async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
757
870
|
const chunks = [];
|
|
758
871
|
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
759
|
-
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
872
|
+
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 } : {} });
|
|
760
873
|
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
761
874
|
const timers = [];
|
|
762
875
|
const killGroup = (killing) => {
|
|
@@ -833,14 +946,62 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
833
946
|
}
|
|
834
947
|
|
|
835
948
|
// ../kit/src/progress.ts
|
|
949
|
+
init_style();
|
|
950
|
+
init_theme();
|
|
836
951
|
var ESC = String.fromCharCode(27);
|
|
837
952
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
838
953
|
var RESET_STYLE = `${ESC}[0m`;
|
|
839
954
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
955
|
+
|
|
956
|
+
// ../kit/src/ci.ts
|
|
957
|
+
init_style();
|
|
958
|
+
|
|
959
|
+
// ../kit/src/tool.ts
|
|
960
|
+
init_format();
|
|
840
961
|
// ../kit/src/cli.ts
|
|
962
|
+
init_args();
|
|
841
963
|
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
842
964
|
import { dirname as dirname3, join as join5 } from "path";
|
|
843
|
-
import
|
|
965
|
+
import process16 from "process";
|
|
966
|
+
|
|
967
|
+
// ../kit/src/askpass.ts
|
|
968
|
+
import process13 from "process";
|
|
969
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
970
|
+
async function askpassClient(argv) {
|
|
971
|
+
const socketPath = process13.env[SOCKET_VARIABLE];
|
|
972
|
+
if (socketPath === undefined)
|
|
973
|
+
return;
|
|
974
|
+
const request = { prompt: argv[0] ?? "", ...process13.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
975
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
976
|
+
let received = "";
|
|
977
|
+
try {
|
|
978
|
+
await Bun.connect({
|
|
979
|
+
unix: socketPath,
|
|
980
|
+
socket: {
|
|
981
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
982
|
+
`),
|
|
983
|
+
data: (_, chunk) => {
|
|
984
|
+
received += chunk.toString();
|
|
985
|
+
},
|
|
986
|
+
close: () => resolve(received),
|
|
987
|
+
error: () => resolve("")
|
|
988
|
+
}
|
|
989
|
+
});
|
|
990
|
+
} catch {
|
|
991
|
+
return 1;
|
|
992
|
+
}
|
|
993
|
+
const reply = await promise;
|
|
994
|
+
if (reply === "")
|
|
995
|
+
return 1;
|
|
996
|
+
const { answer } = JSON.parse(reply);
|
|
997
|
+
if (request.notice === true)
|
|
998
|
+
return 0;
|
|
999
|
+
if (answer === undefined)
|
|
1000
|
+
return 1;
|
|
1001
|
+
process13.stdout.write(`${answer}
|
|
1002
|
+
`);
|
|
1003
|
+
return 0;
|
|
1004
|
+
}
|
|
844
1005
|
|
|
845
1006
|
// ../kit/src/completions.ts
|
|
846
1007
|
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
@@ -903,28 +1064,34 @@ compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
|
903
1064
|
}
|
|
904
1065
|
|
|
905
1066
|
// ../kit/src/notify.ts
|
|
906
|
-
|
|
1067
|
+
init_format();
|
|
1068
|
+
init_mode();
|
|
1069
|
+
import process14 from "process";
|
|
907
1070
|
var NOTIFY_AFTER_MS = 1e4;
|
|
908
1071
|
var CANCELLED = 130;
|
|
909
1072
|
function base64(text) {
|
|
910
1073
|
return Buffer.from(text).toString("base64");
|
|
911
1074
|
}
|
|
912
|
-
function notification(title, body, env =
|
|
913
|
-
const id = `kit${
|
|
1075
|
+
function notification(title, body, env = process14.env) {
|
|
1076
|
+
const id = `kit${process14.pid}`;
|
|
914
1077
|
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\\`];
|
|
915
1078
|
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
916
1079
|
}
|
|
917
|
-
function notifyEnd(command, code, ms, { stream =
|
|
1080
|
+
function notifyEnd(command, code, ms, { stream = process14.stderr, env = process14.env } = {}) {
|
|
918
1081
|
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
919
1082
|
return;
|
|
920
1083
|
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
921
1084
|
}
|
|
922
1085
|
|
|
1086
|
+
// ../kit/src/cli.ts
|
|
1087
|
+
init_style();
|
|
1088
|
+
init_text2();
|
|
1089
|
+
|
|
923
1090
|
// ../kit/src/usage.ts
|
|
924
1091
|
import { appendFileSync, mkdirSync } from "fs";
|
|
925
1092
|
import { homedir as homedir3 } from "os";
|
|
926
1093
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
927
|
-
import
|
|
1094
|
+
import process15 from "process";
|
|
928
1095
|
|
|
929
1096
|
// ../kit/src/logs.ts
|
|
930
1097
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -938,14 +1105,14 @@ var usageError;
|
|
|
938
1105
|
function noteUsageError(message) {
|
|
939
1106
|
usageError = message;
|
|
940
1107
|
}
|
|
941
|
-
function stateHome(env =
|
|
1108
|
+
function stateHome(env = process15.env) {
|
|
942
1109
|
const dir = env.XDG_STATE_HOME;
|
|
943
1110
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
944
1111
|
}
|
|
945
|
-
function usagePath(env =
|
|
1112
|
+
function usagePath(env = process15.env) {
|
|
946
1113
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
947
1114
|
}
|
|
948
|
-
function usageRecorded(env =
|
|
1115
|
+
function usageRecorded(env = process15.env) {
|
|
949
1116
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
950
1117
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
951
1118
|
}
|
|
@@ -954,12 +1121,12 @@ function flagNames(argv) {
|
|
|
954
1121
|
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
955
1122
|
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
956
1123
|
}
|
|
957
|
-
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
1124
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
958
1125
|
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
959
1126
|
usageError = undefined;
|
|
960
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1127
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
961
1128
|
}
|
|
962
|
-
function recordUsage(entry, env =
|
|
1129
|
+
function recordUsage(entry, env = process15.env) {
|
|
963
1130
|
if (!usageRecorded(env))
|
|
964
1131
|
return;
|
|
965
1132
|
try {
|
|
@@ -981,8 +1148,8 @@ var TOP_OPTIONS = {
|
|
|
981
1148
|
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
982
1149
|
};
|
|
983
1150
|
function printError(prefix, message, hint, cause) {
|
|
984
|
-
const colors = paint(
|
|
985
|
-
const styled = takesControlCodes(
|
|
1151
|
+
const colors = paint(process16.stderr);
|
|
1152
|
+
const styled = takesControlCodes(process16.stderr);
|
|
986
1153
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
987
1154
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
988
1155
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1093,6 +1260,9 @@ function packageVersion(entry = Bun.main) {
|
|
|
1093
1260
|
}
|
|
1094
1261
|
}
|
|
1095
1262
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1263
|
+
const answered = await askpassClient(argv);
|
|
1264
|
+
if (answered !== undefined)
|
|
1265
|
+
return answered;
|
|
1096
1266
|
if (argv[0] === COMPLETE)
|
|
1097
1267
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1098
1268
|
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
@@ -1111,24 +1281,55 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
1111
1281
|
notifyEnd(name, code, performance.now() - started);
|
|
1112
1282
|
if (usage !== false) {
|
|
1113
1283
|
try {
|
|
1114
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1284
|
+
recordUsage(usageEntry(name, undefined, argv, code, { ms: performance.now() - started }));
|
|
1115
1285
|
} catch {}
|
|
1116
1286
|
}
|
|
1117
1287
|
return code;
|
|
1118
1288
|
}
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1289
|
+
|
|
1290
|
+
// ../kit/src/index.ts
|
|
1291
|
+
init_config();
|
|
1292
|
+
|
|
1293
|
+
// ../kit/src/excerpt.ts
|
|
1294
|
+
init_text2();
|
|
1295
|
+
|
|
1296
|
+
// ../kit/src/index.ts
|
|
1297
|
+
init_folders();
|
|
1298
|
+
init_format();
|
|
1299
|
+
|
|
1300
|
+
// ../kit/src/git.ts
|
|
1301
|
+
init_args();
|
|
1302
|
+
// ../kit/src/limit.ts
|
|
1303
|
+
init_args();
|
|
1304
|
+
|
|
1305
|
+
// ../kit/src/index.ts
|
|
1306
|
+
init_mode();
|
|
1307
|
+
|
|
1308
|
+
// ../kit/src/report.ts
|
|
1309
|
+
init_style();
|
|
1310
|
+
init_text2();
|
|
1126
1311
|
// ../kit/src/secrets.ts
|
|
1127
1312
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1128
1313
|
// ../kit/src/sessions.ts
|
|
1129
1314
|
var {Glob } = globalThis.Bun;
|
|
1130
1315
|
var SESSION_FILES = new Glob("*.json");
|
|
1131
1316
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1317
|
+
|
|
1318
|
+
// ../kit/src/index.ts
|
|
1319
|
+
init_style();
|
|
1320
|
+
init_text2();
|
|
1321
|
+
init_theme();
|
|
1322
|
+
init_user_config();
|
|
1323
|
+
|
|
1324
|
+
// ../kit/src/watch.ts
|
|
1325
|
+
init_args();
|
|
1326
|
+
init_input();
|
|
1327
|
+
init_style();
|
|
1328
|
+
// ../kit/src/workspace-root.ts
|
|
1329
|
+
init_user_config();
|
|
1330
|
+
// src/cli.ts
|
|
1331
|
+
init_text();
|
|
1332
|
+
|
|
1132
1333
|
// src/blocks.ts
|
|
1133
1334
|
var LINE_BREAK = /\r?\n/;
|
|
1134
1335
|
var OPENER = /^(<{7,}) SEARCH$/;
|
|
@@ -1211,6 +1412,7 @@ async function diffTexts(path, before, after) {
|
|
|
1211
1412
|
}
|
|
1212
1413
|
|
|
1213
1414
|
// src/replace.ts
|
|
1415
|
+
init_text();
|
|
1214
1416
|
var CRLF = /\r?\n/g;
|
|
1215
1417
|
var BRACED_GROUP = /\$\$|\$\{(\w+)\}/g;
|
|
1216
1418
|
var DIGITS = /^\d+$/;
|
|
@@ -1247,7 +1449,7 @@ function firstLineHint(text, from) {
|
|
|
1247
1449
|
return "";
|
|
1248
1450
|
const lines = text.split(`
|
|
1249
1451
|
`).flatMap((line, i) => line.includes(first) ? [i + 1] : []);
|
|
1250
|
-
return lines.length === 0 ? "" : ` (its first line is on ${
|
|
1452
|
+
return lines.length === 0 ? "" : ` (its first line is on ${G("line", lines.length)} ${listLines(lines)})`;
|
|
1251
1453
|
}
|
|
1252
1454
|
function compile(source, { ignoreCase, dotAll } = {}) {
|
|
1253
1455
|
return new RegExp(source, `gm${ignoreCase === true ? "i" : ""}${dotAll === true ? "s" : ""}`);
|
|
@@ -1293,7 +1495,7 @@ function applyPairs(original, pairs) {
|
|
|
1293
1495
|
let where = ` on lines ${listLines(found)}: add context to --from, or pass --count ${indexes.length} or --all`;
|
|
1294
1496
|
if (indexes.length === 0)
|
|
1295
1497
|
where = pattern === undefined ? firstLineHint(text, from) : "";
|
|
1296
|
-
problems.push(`${label}matched ${
|
|
1498
|
+
problems.push(`${label}matched ${bo(indexes.length, "time")}, expected ${wanted}${where}`);
|
|
1297
1499
|
continue;
|
|
1298
1500
|
}
|
|
1299
1501
|
lines.push(...found);
|
|
@@ -1339,9 +1541,9 @@ async function filesIn(dir) {
|
|
|
1339
1541
|
// src/cli.ts
|
|
1340
1542
|
var USAGE = `sub [options] <file>...: replaces text in files, writing nothing unless every replacement matches as often as expected
|
|
1341
1543
|
|
|
1342
|
-
A folder given as a file is walked, .gitignore respected and binary files left out
|
|
1544
|
+
A folder given as a file is walked, .gitignore respected and binary files left out.
|
|
1343
1545
|
|
|
1344
|
-
Multi-line text: give no --from, --to or --pairs and pipe SEARCH/REPLACE blocks on stdin from a quoted heredoc, which needs no escaping
|
|
1546
|
+
Multi-line text: give no --from, --to or --pairs and pipe SEARCH/REPLACE blocks on stdin from a quoted heredoc, which needs no escaping. The blocks apply in order to the files on the command line, each matching exactly once unless --count or --all says otherwise:
|
|
1345
1547
|
|
|
1346
1548
|
sub src/a.php <<'EOF'
|
|
1347
1549
|
<<<<<<< SEARCH
|
|
@@ -1351,7 +1553,7 @@ new lines
|
|
|
1351
1553
|
>>>>>>> REPLACE
|
|
1352
1554
|
EOF
|
|
1353
1555
|
|
|
1354
|
-
A line naming a file before a block makes it apply to that file alone,
|
|
1556
|
+
A line naming a file before a block makes it apply to that file alone, and an empty REPLACE deletes the SEARCH text.`;
|
|
1355
1557
|
var EXITS = [[0, "it wrote every replacement"], [1, "one did not match or a file cannot be written (nothing is written)"], [2, "a usage error"]];
|
|
1356
1558
|
var OPTIONS = {
|
|
1357
1559
|
from: { type: "string", short: "f", description: "text to find, taken literally" },
|
|
@@ -1390,7 +1592,7 @@ function pairFrom(item, i, defaults) {
|
|
|
1390
1592
|
const { from, to, count, all, regex, ignoreCase, dotAll, ...rest } = item;
|
|
1391
1593
|
const unknown = Object.keys(rest);
|
|
1392
1594
|
if (unknown.length > 0)
|
|
1393
|
-
fail(`${label}unknown ${
|
|
1595
|
+
fail(`${label}unknown ${G("key", unknown.length)} ${unknown.join(", ")}, known: ${PAIR_KEYS.join(", ")}`);
|
|
1394
1596
|
if (typeof from !== "string" || typeof to !== "string")
|
|
1395
1597
|
fail(`${label}from and to must both be strings`);
|
|
1396
1598
|
if (count !== undefined && (typeof count !== "number" || !Number.isInteger(count) || count < 1))
|
|
@@ -1450,7 +1652,7 @@ function dedupe(paths) {
|
|
|
1450
1652
|
}
|
|
1451
1653
|
function writeAtomic(path, text) {
|
|
1452
1654
|
const target = realpathSync3(path);
|
|
1453
|
-
const temp = `${target}.sub-${
|
|
1655
|
+
const temp = `${target}.sub-${process18.pid}`;
|
|
1454
1656
|
try {
|
|
1455
1657
|
writeFileSync2(temp, text);
|
|
1456
1658
|
chmodSync(temp, (statSync2(target, { throwIfNoEntry: false })?.mode ?? 420) & 4095);
|
|
@@ -1469,23 +1671,23 @@ async function blocksOnStdin(files) {
|
|
|
1469
1671
|
const hint = `${strings}give --from and --to, or pipe SEARCH/REPLACE blocks on stdin from a heredoc
|
|
1470
1672
|
|
|
1471
1673
|
${USAGE}`;
|
|
1472
|
-
if (
|
|
1674
|
+
if (process18.stdin.isTTY)
|
|
1473
1675
|
fail(hint);
|
|
1474
1676
|
return new Promise((resolve) => {
|
|
1475
1677
|
const chunks = [];
|
|
1476
1678
|
const timer = setTimeout(() => {
|
|
1477
1679
|
console.error(`error: sub: ${hint}`);
|
|
1478
|
-
|
|
1680
|
+
process18.exit(2);
|
|
1479
1681
|
}, STDIN_SILENCE_MS);
|
|
1480
|
-
|
|
1682
|
+
process18.stdin.on("data", (chunk) => {
|
|
1481
1683
|
clearTimeout(timer);
|
|
1482
1684
|
chunks.push(chunk);
|
|
1483
1685
|
});
|
|
1484
|
-
|
|
1686
|
+
process18.stdin.on("end", () => {
|
|
1485
1687
|
clearTimeout(timer);
|
|
1486
1688
|
if (chunks.length === 0 && extra.length > 0) {
|
|
1487
1689
|
console.error(`error: sub: ${hint}`);
|
|
1488
|
-
|
|
1690
|
+
process18.exit(2);
|
|
1489
1691
|
}
|
|
1490
1692
|
resolve(Buffer.concat(chunks).toString("utf8"));
|
|
1491
1693
|
});
|
|
@@ -1587,10 +1789,7 @@ async function main(argv) {
|
|
|
1587
1789
|
if (skipped.length > 0 && changes.length === 0 && problems.length === 0)
|
|
1588
1790
|
problems.push({ path: skipped.join(", "), problem: "no match in any file" });
|
|
1589
1791
|
if (problems.length > 0) {
|
|
1590
|
-
|
|
1591
|
-
console.error(JSON.stringify({ error: "nothing written", failures: problems }));
|
|
1592
|
-
else
|
|
1593
|
-
console.error(`${role("problem", process17.stderr)("sub: nothing written")}
|
|
1792
|
+
console.error(json ? JSON.stringify({ error: "nothing written", failures: problems }) : `${role("problem", process18.stderr)("sub: nothing written")}
|
|
1594
1793
|
${problems.map(({ path, problem }) => `${path}: ${problem}`).join(`
|
|
1595
1794
|
`)}`);
|
|
1596
1795
|
return 1;
|
|
@@ -1599,7 +1798,7 @@ ${problems.map(({ path, problem }) => `${path}: ${problem}`).join(`
|
|
|
1599
1798
|
for (const change of changes)
|
|
1600
1799
|
change.diff = await diffTexts(change.path, change.before, change.after);
|
|
1601
1800
|
} catch (error) {
|
|
1602
|
-
console.error(`${role("problem",
|
|
1801
|
+
console.error(`${role("problem", process18.stderr)("sub: nothing written")}
|
|
1603
1802
|
${error instanceof Error ? error.message : String(error)}`);
|
|
1604
1803
|
return 1;
|
|
1605
1804
|
}
|
|
@@ -1614,16 +1813,16 @@ ${error instanceof Error ? error.message : String(error)}`);
|
|
|
1614
1813
|
continue;
|
|
1615
1814
|
}
|
|
1616
1815
|
if (values.quiet !== true)
|
|
1617
|
-
console.log(`${role("path",
|
|
1816
|
+
console.log(`${role("path", process18.stdout)(path)}: ${bo(lines.length, "replacement")} on ${G("line", lines.length, { zero: "plural" })} ${listLines(lines)}, ${role(diff.added === 0 ? "label" : "ok", process18.stdout)(`+${diff.added}`)} ${role(diff.removed === 0 ? "label" : "problem", process18.stdout)(`-${diff.removed}`)}`);
|
|
1618
1817
|
if (values.diff === true && diff.unified !== "")
|
|
1619
|
-
|
|
1818
|
+
process18.stdout.write(diff.unified);
|
|
1620
1819
|
}
|
|
1621
1820
|
if (json)
|
|
1622
1821
|
printJson({ dryRun: values["dry-run"] === true, files: done, ...values["skip-missing"] === true ? { skipped } : {} });
|
|
1623
1822
|
else if (values.quiet !== true && skipped.length > 0)
|
|
1624
|
-
console.log(`skipped ${
|
|
1823
|
+
console.log(`skipped ${bo(skipped.length, "file")} with no match: ${skipped.join(", ")}`);
|
|
1625
1824
|
if (!json && values["dry-run"] === true && values.quiet !== true)
|
|
1626
1825
|
console.log("dry run: nothing written");
|
|
1627
1826
|
return 0;
|
|
1628
1827
|
}
|
|
1629
|
-
|
|
1828
|
+
process18.exitCode = await runMain({ name: "sub", run: main });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-edit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.11.
|
|
4
|
+
"version": "0.11.3",
|
|
5
5
|
"description": "sub: text replaced in files for Claude Code, written only when every replacement matches as often as expected.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"sub": "$npm_execpath src/cli.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@kaynooo/utils": "3.
|
|
39
|
+
"@kaynooo/utils": "3.1.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@kaynooo/cli-kit": "0.
|
|
42
|
+
"@kaynooo/cli-kit": "0.45.1"
|
|
43
43
|
}
|
|
44
44
|
}
|