@kaynooo/cli-env 0.14.1 → 0.15.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 +10 -8
- package/dist/ev.js +994 -777
- package/package.json +9 -11
- package/src/commands/audit.ts +3 -4
- package/src/commands/edit.ts +3 -1
- package/src/commands/pins.ts +2 -4
- package/src/commands/read.ts +13 -7
- package/src/commands/redact.ts +4 -4
- package/src/files.ts +35 -3
- package/src/guard-names.ts +1 -1
- package/src/guard-pipes.ts +1 -1
- package/src/guard.ts +6 -4
- package/dist/redact.js +0 -1917
- package/src/redact.ts +0 -7
package/dist/ev.js
CHANGED
|
@@ -1,20 +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
|
-
// ../kit/src/args.ts
|
|
7
|
-
import process10 from "process";
|
|
8
|
-
import { parseArgs } from "util";
|
|
9
|
-
|
|
10
|
-
// ../kit/src/format.ts
|
|
11
|
-
import process7 from "process";
|
|
12
|
-
|
|
13
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
14
|
-
var N = new Map;
|
|
15
|
-
var Nt = /\s+\S*$/;
|
|
16
|
-
var Y = /\s/;
|
|
17
|
-
function ko(t, e, r = "...") {
|
|
15
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rkhsft4a.js
|
|
16
|
+
function Ao(t, e, r = "...") {
|
|
18
17
|
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
19
18
|
if (t.length <= e)
|
|
20
19
|
return t;
|
|
@@ -25,13 +24,22 @@ function ko(t, e, r = "...") {
|
|
|
25
24
|
c = c.trimEnd();
|
|
26
25
|
return s ? (c + n).slice(0, l) : c + n;
|
|
27
26
|
}
|
|
28
|
-
var
|
|
29
|
-
var
|
|
27
|
+
var N, Nt, Y, be, W;
|
|
28
|
+
var init_chunk_rkhsft4a = __esm(() => {
|
|
29
|
+
N = new Map;
|
|
30
|
+
Nt = /\s+\S*$/;
|
|
31
|
+
Y = /\s/;
|
|
32
|
+
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));
|
|
33
|
+
W = new Map;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
|
|
37
|
+
var init_text = __esm(() => {
|
|
38
|
+
init_chunk_rkhsft4a();
|
|
39
|
+
});
|
|
30
40
|
|
|
31
41
|
// ../kit/src/mode.ts
|
|
32
42
|
import process2 from "process";
|
|
33
|
-
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
34
|
-
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
35
43
|
function isSet(value) {
|
|
36
44
|
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
37
45
|
}
|
|
@@ -48,12 +56,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
48
56
|
function isInteractive(streams = process2) {
|
|
49
57
|
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
50
58
|
}
|
|
59
|
+
var MODES, AGENT_VARIABLES;
|
|
60
|
+
var init_mode = __esm(() => {
|
|
61
|
+
MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
62
|
+
AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
63
|
+
});
|
|
51
64
|
|
|
52
|
-
//
|
|
53
|
-
import process6 from "process";
|
|
54
|
-
|
|
55
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
56
|
-
var G2 = /^[a-f0-9]+$/i;
|
|
65
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
57
66
|
function b(r) {
|
|
58
67
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
59
68
|
if (!G2.test(e))
|
|
@@ -64,11 +73,6 @@ function b(r) {
|
|
|
64
73
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
65
74
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
66
75
|
}
|
|
67
|
-
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") => {
|
|
68
|
-
let [l, n, c] = b(r);
|
|
69
|
-
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
70
|
-
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
71
|
-
var h = new Set(["", "1", "2", "3", "true"]);
|
|
72
76
|
function C(r, e = globalThis.process?.env ?? {}) {
|
|
73
77
|
if (e.FORCE_COLOR !== undefined)
|
|
74
78
|
return h.has(e.FORCE_COLOR);
|
|
@@ -82,7 +86,7 @@ function f(r, e = []) {
|
|
|
82
86
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
83
87
|
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
84
88
|
return new Proxy(c, { get(t, i) {
|
|
85
|
-
let a =
|
|
89
|
+
let a = B[i];
|
|
86
90
|
if (Array.isArray(a)) {
|
|
87
91
|
let s = g.get(i);
|
|
88
92
|
if (s === undefined)
|
|
@@ -105,13 +109,21 @@ function f(r, e = []) {
|
|
|
105
109
|
function Fe(r = {}) {
|
|
106
110
|
return f(r);
|
|
107
111
|
}
|
|
108
|
-
var
|
|
112
|
+
var G2, B, h, o;
|
|
113
|
+
var init_chunk_x450vn3m = __esm(() => {
|
|
114
|
+
G2 = /^[a-f0-9]+$/i;
|
|
115
|
+
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") => {
|
|
116
|
+
let [l, n, c] = b(r);
|
|
117
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
118
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
119
|
+
h = new Set(["", "1", "2", "3", "true"]);
|
|
120
|
+
o = Fe();
|
|
121
|
+
});
|
|
109
122
|
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
import process5 from "process";
|
|
123
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
|
|
124
|
+
var init_colors = __esm(() => {
|
|
125
|
+
init_chunk_x450vn3m();
|
|
126
|
+
});
|
|
115
127
|
|
|
116
128
|
// ../kit/src/config.ts
|
|
117
129
|
import { existsSync } from "fs";
|
|
@@ -127,6 +139,9 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
127
139
|
return;
|
|
128
140
|
}
|
|
129
141
|
}
|
|
142
|
+
var init_config = __esm(() => {
|
|
143
|
+
init_args();
|
|
144
|
+
});
|
|
130
145
|
|
|
131
146
|
// ../kit/src/user-config.ts
|
|
132
147
|
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
@@ -158,36 +173,18 @@ function readUserConfig(bin, where = {}, legacy = []) {
|
|
|
158
173
|
return {};
|
|
159
174
|
}
|
|
160
175
|
}
|
|
176
|
+
var init_user_config = () => {};
|
|
161
177
|
|
|
162
178
|
// ../kit/src/theme.ts
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
168
|
-
bins: {},
|
|
169
|
-
gradient: ["#c084fc", "#67e8f9"]
|
|
170
|
-
};
|
|
171
|
-
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" };
|
|
172
|
-
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" };
|
|
173
|
-
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
174
|
-
var PRESETS = {
|
|
175
|
-
default: {},
|
|
176
|
-
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
177
|
-
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
178
|
-
ascii: { glyphs: ASCII }
|
|
179
|
-
};
|
|
180
|
-
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"]);
|
|
181
|
-
var HEX = /^#[0-9a-f]{6}$/i;
|
|
182
|
-
var CONTROL = /\p{Cc}/u;
|
|
183
|
-
var MAX_FILE_BYTES = 64 * 1024;
|
|
184
|
-
var SPACES = /\s+/;
|
|
179
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
180
|
+
import { homedir as homedir2 } from "os";
|
|
181
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
182
|
+
import process5 from "process";
|
|
185
183
|
function isColorSpec(spec) {
|
|
186
184
|
if (typeof spec === "number")
|
|
187
185
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
188
186
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
189
187
|
}
|
|
190
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
191
188
|
function cubeLevel(channel) {
|
|
192
189
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
193
190
|
}
|
|
@@ -292,7 +289,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
292
289
|
function endsWalk(home) {
|
|
293
290
|
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
294
291
|
}
|
|
295
|
-
var warned = new Set;
|
|
296
292
|
function warnOnce(message) {
|
|
297
293
|
if (warned.has(message))
|
|
298
294
|
return;
|
|
@@ -329,8 +325,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
329
325
|
}
|
|
330
326
|
return { theme, sources, preset };
|
|
331
327
|
}
|
|
332
|
-
var current;
|
|
333
|
-
var currentKey = "";
|
|
334
328
|
function activeTheme() {
|
|
335
329
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
336
330
|
if (current === undefined || key !== currentKey) {
|
|
@@ -339,9 +333,38 @@ function activeTheme() {
|
|
|
339
333
|
}
|
|
340
334
|
return current;
|
|
341
335
|
}
|
|
336
|
+
var ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
|
|
337
|
+
var init_theme = __esm(() => {
|
|
338
|
+
init_config();
|
|
339
|
+
init_user_config();
|
|
340
|
+
ENDS = new Map;
|
|
341
|
+
DEFAULT = {
|
|
342
|
+
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" },
|
|
343
|
+
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" },
|
|
344
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
345
|
+
bins: {},
|
|
346
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
347
|
+
};
|
|
348
|
+
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" };
|
|
349
|
+
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" };
|
|
350
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
351
|
+
PRESETS = {
|
|
352
|
+
default: {},
|
|
353
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
354
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
355
|
+
ascii: { glyphs: ASCII }
|
|
356
|
+
};
|
|
357
|
+
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"]);
|
|
358
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
359
|
+
CONTROL = /\p{Cc}/u;
|
|
360
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
361
|
+
SPACES = /\s+/;
|
|
362
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
363
|
+
warned = new Set;
|
|
364
|
+
});
|
|
342
365
|
|
|
343
366
|
// ../kit/src/style.ts
|
|
344
|
-
|
|
367
|
+
import process6 from "process";
|
|
345
368
|
function takesControlCodes(stream, env = process6.env) {
|
|
346
369
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
347
370
|
}
|
|
@@ -367,17 +390,24 @@ function role(name, stream, env = process6.env) {
|
|
|
367
390
|
const colors = paint(stream, env);
|
|
368
391
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
369
392
|
}
|
|
370
|
-
var STATUS_WORDS
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
393
|
+
var MARK_WORDS, STATUS_WORDS, STATUS_OF;
|
|
394
|
+
var init_style = __esm(() => {
|
|
395
|
+
init_colors();
|
|
396
|
+
init_mode();
|
|
397
|
+
init_theme();
|
|
398
|
+
MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
399
|
+
STATUS_WORDS = {
|
|
400
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
401
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
402
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
403
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
404
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
405
|
+
};
|
|
406
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
407
|
+
});
|
|
378
408
|
|
|
379
409
|
// ../kit/src/format.ts
|
|
380
|
-
|
|
410
|
+
import process7 from "process";
|
|
381
411
|
function formatSeconds(total) {
|
|
382
412
|
let rest = Math.max(0, Math.round(total));
|
|
383
413
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -399,10 +429,8 @@ function upTo(text, separator) {
|
|
|
399
429
|
return end === -1 ? text : text.slice(0, end);
|
|
400
430
|
}
|
|
401
431
|
function truncate(text, width) {
|
|
402
|
-
return
|
|
432
|
+
return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
403
433
|
}
|
|
404
|
-
var LINE_BREAKS = /\s*\n\s*/g;
|
|
405
|
-
var ESCAPE = String.fromCharCode(27);
|
|
406
434
|
function textWidth(text) {
|
|
407
435
|
return Bun.stringWidth(text);
|
|
408
436
|
}
|
|
@@ -451,14 +479,40 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
|
|
|
451
479
|
function printJson(value) {
|
|
452
480
|
console.log(jsonText(value));
|
|
453
481
|
}
|
|
482
|
+
var UNITS, LINE_BREAKS, ESCAPE;
|
|
483
|
+
var init_format = __esm(() => {
|
|
484
|
+
init_text();
|
|
485
|
+
init_mode();
|
|
486
|
+
init_style();
|
|
487
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
488
|
+
LINE_BREAKS = /\s*\n\s*/g;
|
|
489
|
+
ESCAPE = String.fromCharCode(27);
|
|
490
|
+
});
|
|
454
491
|
|
|
455
492
|
// ../kit/src/help.ts
|
|
456
493
|
import process8 from "process";
|
|
457
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
458
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
459
|
-
var FULL_STOP = /\.$/;
|
|
460
494
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
461
|
-
|
|
495
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
496
|
+
`);
|
|
497
|
+
const blank = lines.indexOf("");
|
|
498
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
499
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
500
|
+
const colon = synopses[0].indexOf(": ");
|
|
501
|
+
const inline = synopses[0].slice(colon + 2);
|
|
502
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
503
|
+
if (colon !== -1)
|
|
504
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
505
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
506
|
+
`)}`;
|
|
507
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
508
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
509
|
+
return [head, ...lead, ...rest].join(`
|
|
510
|
+
`);
|
|
511
|
+
}
|
|
512
|
+
function prose(line, colors) {
|
|
513
|
+
if (colors.cyan("x") === "x")
|
|
514
|
+
return line;
|
|
515
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
462
516
|
}
|
|
463
517
|
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
464
518
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -493,7 +547,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
493
547
|
return [];
|
|
494
548
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
495
549
|
}
|
|
496
|
-
var MAX_INLINE_CHOICES = 24;
|
|
497
550
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
498
551
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
499
552
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -508,6 +561,15 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
508
561
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
509
562
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
510
563
|
}
|
|
564
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
565
|
+
var init_help = __esm(() => {
|
|
566
|
+
init_mode();
|
|
567
|
+
init_style();
|
|
568
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
569
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
570
|
+
FULL_STOP = /\.$/;
|
|
571
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
572
|
+
});
|
|
511
573
|
|
|
512
574
|
// ../kit/src/text.ts
|
|
513
575
|
function distance(a, b) {
|
|
@@ -535,6 +597,8 @@ function closest(name, names) {
|
|
|
535
597
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
536
598
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
537
599
|
}
|
|
600
|
+
var init_text2 = () => {};
|
|
601
|
+
|
|
538
602
|
// ../kit/src/input.ts
|
|
539
603
|
import process9 from "process";
|
|
540
604
|
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
@@ -548,40 +612,23 @@ async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
|
548
612
|
fail(`no file ${path}`);
|
|
549
613
|
return file.text();
|
|
550
614
|
}
|
|
615
|
+
var init_input = __esm(() => {
|
|
616
|
+
init_args();
|
|
617
|
+
});
|
|
551
618
|
|
|
552
619
|
// ../kit/src/args.ts
|
|
553
|
-
|
|
620
|
+
import process10 from "process";
|
|
621
|
+
import { parseArgs } from "util";
|
|
554
622
|
function jsonOption(holds) {
|
|
555
623
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
556
624
|
}
|
|
557
|
-
class Exit extends Error {
|
|
558
|
-
code;
|
|
559
|
-
hint;
|
|
560
|
-
constructor(message, code, hint) {
|
|
561
|
-
super(message);
|
|
562
|
-
this.code = code;
|
|
563
|
-
this.hint = hint;
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
625
|
function fail(message, code = 2, hint) {
|
|
567
626
|
throw new Exit(message, code, hint);
|
|
568
627
|
}
|
|
569
|
-
|
|
570
|
-
class UsageError extends Exit {
|
|
571
|
-
constructor(message, hint) {
|
|
572
|
-
super(message, 2, hint);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
628
|
function badUsage(message) {
|
|
576
629
|
throw new UsageError(message);
|
|
577
630
|
}
|
|
578
631
|
|
|
579
|
-
class HelpShown extends Exit {
|
|
580
|
-
constructor() {
|
|
581
|
-
super("help shown", 0);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
|
|
585
632
|
class Completing {
|
|
586
633
|
options;
|
|
587
634
|
positionals;
|
|
@@ -592,11 +639,6 @@ class Completing {
|
|
|
592
639
|
this.candidates = candidates;
|
|
593
640
|
}
|
|
594
641
|
}
|
|
595
|
-
var completion = { active: false };
|
|
596
|
-
var OUTPUT_OPTIONS = {
|
|
597
|
-
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
598
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
599
|
-
};
|
|
600
642
|
function applyOutput(color, plain, env = process10.env) {
|
|
601
643
|
const when = plain === true ? "never" : color ?? "auto";
|
|
602
644
|
if (when === "auto")
|
|
@@ -750,7 +792,6 @@ function parseError(error) {
|
|
|
750
792
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
751
793
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
752
794
|
}
|
|
753
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
754
795
|
function nearestOption(message, options, allowNegative) {
|
|
755
796
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
756
797
|
if (typed === undefined)
|
|
@@ -766,158 +807,716 @@ function nearestOption(message, options, allowNegative) {
|
|
|
766
807
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
767
808
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
768
809
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
810
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
811
|
+
var init_args = __esm(() => {
|
|
812
|
+
init_format();
|
|
813
|
+
init_help();
|
|
814
|
+
init_text2();
|
|
815
|
+
init_help();
|
|
816
|
+
init_input();
|
|
817
|
+
DASHES = /^-+/;
|
|
818
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
819
|
+
Exit = class Exit extends Error {
|
|
820
|
+
code;
|
|
821
|
+
hint;
|
|
822
|
+
[EXIT] = true;
|
|
823
|
+
constructor(message, code, hint) {
|
|
824
|
+
super(message);
|
|
825
|
+
this.code = code;
|
|
826
|
+
this.hint = hint;
|
|
827
|
+
}
|
|
828
|
+
static [Symbol.hasInstance](value) {
|
|
829
|
+
if (this !== Exit)
|
|
830
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
831
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
UsageError = class UsageError extends Exit {
|
|
835
|
+
constructor(message, hint) {
|
|
836
|
+
super(message, 2, hint);
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
HelpShown = class HelpShown extends Exit {
|
|
840
|
+
constructor() {
|
|
841
|
+
super("help shown", 0);
|
|
842
|
+
}
|
|
843
|
+
};
|
|
844
|
+
completion = { active: false };
|
|
845
|
+
OUTPUT_OPTIONS = {
|
|
846
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
847
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
848
|
+
};
|
|
849
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
// ../kit/src/folders.ts
|
|
853
|
+
import { homedir as homedir4 } from "os";
|
|
854
|
+
import { join as join6 } from "path";
|
|
855
|
+
import process16 from "process";
|
|
856
|
+
function ignoredFolders(extra = [], where = {}) {
|
|
857
|
+
const configured = readUserConfig("config", where).ignore;
|
|
858
|
+
const names = Array.isArray(configured) ? configured.filter((name) => typeof name === "string" && name !== "") : [];
|
|
859
|
+
return new Set([...SKIPPED_FOLDERS, ...extra, ...names]);
|
|
779
860
|
}
|
|
780
|
-
function
|
|
861
|
+
function cacheFolder({ home = homedir4(), env = process16.env } = {}) {
|
|
862
|
+
return env.XDG_CACHE_HOME ?? join6(home, ".cache");
|
|
863
|
+
}
|
|
864
|
+
var SKIPPED_FOLDERS;
|
|
865
|
+
var init_folders = __esm(() => {
|
|
866
|
+
init_user_config();
|
|
867
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
// ../kit/src/answers.ts
|
|
871
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync } from "fs";
|
|
872
|
+
import { dirname as dirname7, join as join10 } from "path";
|
|
873
|
+
function answersFile() {
|
|
874
|
+
return join10(cacheFolder(), "kaynooo-cli", "answers.json");
|
|
875
|
+
}
|
|
876
|
+
function stored() {
|
|
781
877
|
try {
|
|
782
|
-
|
|
878
|
+
const parsed = JSON.parse(readFileSync5(answersFile(), "utf-8"));
|
|
879
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
880
|
+
return {};
|
|
881
|
+
return Object.fromEntries(Object.entries(parsed).filter((entry) => Array.isArray(entry[1]) && entry[1].every((answer) => typeof answer === "string")));
|
|
783
882
|
} catch {
|
|
784
|
-
return;
|
|
883
|
+
return {};
|
|
785
884
|
}
|
|
786
885
|
}
|
|
787
|
-
function
|
|
788
|
-
|
|
789
|
-
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
790
|
-
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
791
|
-
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
886
|
+
function earlierAnswers(key) {
|
|
887
|
+
return stored()[key] ?? [];
|
|
792
888
|
}
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
import process14 from "process";
|
|
802
|
-
|
|
803
|
-
// ../kit/src/completions.ts
|
|
804
|
-
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
805
|
-
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'
|
|
806
|
-
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
807
|
-
set -l current (commandline -ct)
|
|
808
|
-
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
809
|
-
if test "$line" = __files__
|
|
810
|
-
__fish_complete_path $current
|
|
811
|
-
else
|
|
812
|
-
echo $line
|
|
813
|
-
end
|
|
814
|
-
end
|
|
815
|
-
end`;
|
|
816
|
-
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
817
|
-
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
818
|
-
local -a lines
|
|
819
|
-
COMPREPLY=()
|
|
820
|
-
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
821
|
-
for line in "\${lines[@]}"; do
|
|
822
|
-
if [[ $line == __files__ ]]; then
|
|
823
|
-
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
824
|
-
else
|
|
825
|
-
words+="\${line%%$'\\t'*}"$'\\n'
|
|
826
|
-
fi
|
|
827
|
-
done
|
|
828
|
-
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
829
|
-
}`;
|
|
830
|
-
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
831
|
-
local line
|
|
832
|
-
local -a described plain
|
|
833
|
-
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
834
|
-
if [[ $line == __files__ ]]; then
|
|
835
|
-
_files
|
|
836
|
-
elif [[ $line == *$'\\t'* ]]; then
|
|
837
|
-
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
838
|
-
else
|
|
839
|
-
plain+=("$line")
|
|
840
|
-
fi
|
|
841
|
-
done
|
|
842
|
-
(( \${#described} )) && _describe -V value described
|
|
843
|
-
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
844
|
-
return 0
|
|
845
|
-
}`;
|
|
846
|
-
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
847
|
-
if (shell === "fish")
|
|
848
|
-
return `${header}
|
|
849
|
-
${FISH_FUNCTION}
|
|
850
|
-
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
851
|
-
`).join("")}`;
|
|
852
|
-
if (shell === "bash")
|
|
853
|
-
return `${header}
|
|
854
|
-
${BASH_FUNCTION}
|
|
855
|
-
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
856
|
-
`;
|
|
857
|
-
return `${header}
|
|
858
|
-
${ZSH_FUNCTION}
|
|
859
|
-
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
860
|
-
`;
|
|
889
|
+
function rememberAnswer(key, answer) {
|
|
890
|
+
const all = stored();
|
|
891
|
+
const file = answersFile();
|
|
892
|
+
all[key] = [answer, ...(all[key] ?? []).filter((earlier) => earlier !== answer)].slice(0, KEPT);
|
|
893
|
+
try {
|
|
894
|
+
mkdirSync2(dirname7(file), { recursive: true });
|
|
895
|
+
writeFileSync(file, JSON.stringify(all));
|
|
896
|
+
} catch {}
|
|
861
897
|
}
|
|
898
|
+
var KEPT = 50;
|
|
899
|
+
var init_answers = __esm(() => {
|
|
900
|
+
init_folders();
|
|
901
|
+
});
|
|
862
902
|
|
|
863
|
-
// ../kit/src/
|
|
864
|
-
import
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
function base64(text) {
|
|
868
|
-
return Buffer.from(text).toString("base64");
|
|
869
|
-
}
|
|
870
|
-
function notification(title, body, env = process12.env) {
|
|
871
|
-
const id = `kit${process12.pid}`;
|
|
872
|
-
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\\`];
|
|
873
|
-
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
874
|
-
}
|
|
875
|
-
function notifyEnd(command, code, ms, { stream = process12.stderr, env = process12.env } = {}) {
|
|
876
|
-
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
877
|
-
return;
|
|
878
|
-
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
903
|
+
// ../kit/src/job.ts
|
|
904
|
+
import process20 from "process";
|
|
905
|
+
function stopJob() {
|
|
906
|
+
process20.kill(0, "SIGTSTP");
|
|
879
907
|
}
|
|
908
|
+
var init_job = () => {};
|
|
880
909
|
|
|
881
|
-
// ../kit/src/
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
885
|
-
import process13 from "process";
|
|
886
|
-
|
|
887
|
-
// ../kit/src/logs.ts
|
|
888
|
-
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
889
|
-
var CLI_FOLDER = "kaynooo-cli";
|
|
890
|
-
|
|
891
|
-
// ../kit/src/usage.ts
|
|
892
|
-
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
893
|
-
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
894
|
-
var LONGEST_NAME = 40;
|
|
895
|
-
var usageError;
|
|
896
|
-
function noteUsageError(message) {
|
|
897
|
-
usageError = message;
|
|
910
|
+
// ../kit/src/picker/line.ts
|
|
911
|
+
function isEditKey(key) {
|
|
912
|
+
return EDIT_KEYS.has(key);
|
|
898
913
|
}
|
|
899
|
-
function
|
|
900
|
-
|
|
901
|
-
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
914
|
+
function endsKills(key) {
|
|
915
|
+
return typeof key !== "object" && !isEditKey(key);
|
|
902
916
|
}
|
|
903
|
-
function
|
|
904
|
-
return
|
|
917
|
+
function isWord(char) {
|
|
918
|
+
return char !== undefined && WORD_CHARACTER.test(char);
|
|
905
919
|
}
|
|
906
|
-
function
|
|
907
|
-
|
|
908
|
-
|
|
920
|
+
function wordStart(chars, from) {
|
|
921
|
+
let at = from;
|
|
922
|
+
while (at > 0 && !isWord(chars[at - 1]))
|
|
923
|
+
at--;
|
|
924
|
+
while (at > 0 && isWord(chars[at - 1]))
|
|
925
|
+
at--;
|
|
926
|
+
return at;
|
|
909
927
|
}
|
|
910
|
-
function
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
928
|
+
function wordEnd(chars, from) {
|
|
929
|
+
let at = from;
|
|
930
|
+
while (at < chars.length && !isWord(chars[at]))
|
|
931
|
+
at++;
|
|
932
|
+
while (at < chars.length && isWord(chars[at]))
|
|
933
|
+
at++;
|
|
934
|
+
return at;
|
|
914
935
|
}
|
|
915
|
-
function
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
936
|
+
function spacedStart(chars, from) {
|
|
937
|
+
let at = from;
|
|
938
|
+
while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
|
|
939
|
+
at--;
|
|
940
|
+
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
941
|
+
at--;
|
|
942
|
+
return at;
|
|
943
|
+
}
|
|
944
|
+
function cut(chars, from, to) {
|
|
945
|
+
return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
|
|
946
|
+
}
|
|
947
|
+
function insert(chars, at, text) {
|
|
948
|
+
const typed = [...text];
|
|
949
|
+
return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
|
|
950
|
+
}
|
|
951
|
+
function editLine(line, key) {
|
|
952
|
+
const { killed = "", chained = false } = line;
|
|
953
|
+
const chars = [...line.text];
|
|
954
|
+
const at = Math.min(Math.max(line.caret, 0), chars.length);
|
|
955
|
+
const edited = edit(chars, at, key, killed);
|
|
956
|
+
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
957
|
+
return line.killed === undefined ? edited : { ...edited, killed };
|
|
958
|
+
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
959
|
+
if (taken === "")
|
|
960
|
+
return { ...edited, killed, chained };
|
|
961
|
+
if (!chained)
|
|
962
|
+
return { ...edited, killed: taken, chained: true };
|
|
963
|
+
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
964
|
+
}
|
|
965
|
+
function edit(chars, at, key, killed) {
|
|
966
|
+
const text = chars.join("");
|
|
967
|
+
if (typeof key === "object")
|
|
968
|
+
return insert(chars, at, key.text);
|
|
969
|
+
switch (key) {
|
|
970
|
+
case "left":
|
|
971
|
+
return { text, caret: Math.max(at - 1, 0) };
|
|
972
|
+
case "right":
|
|
973
|
+
return { text, caret: Math.min(at + 1, chars.length) };
|
|
974
|
+
case "wordleft":
|
|
975
|
+
return { text, caret: wordStart(chars, at) };
|
|
976
|
+
case "wordright":
|
|
977
|
+
return { text, caret: wordEnd(chars, at) };
|
|
978
|
+
case "linestart":
|
|
979
|
+
return { text, caret: 0 };
|
|
980
|
+
case "lineend":
|
|
981
|
+
return { text, caret: chars.length };
|
|
982
|
+
case "erase":
|
|
983
|
+
return cut(chars, Math.max(at - 1, 0), at);
|
|
984
|
+
case "delete":
|
|
985
|
+
return cut(chars, at, Math.min(at + 1, chars.length));
|
|
986
|
+
case "word":
|
|
987
|
+
return cut(chars, spacedStart(chars, at), at);
|
|
988
|
+
case "killword":
|
|
989
|
+
return cut(chars, wordStart(chars, at), at);
|
|
990
|
+
case "killnext":
|
|
991
|
+
return cut(chars, at, wordEnd(chars, at));
|
|
992
|
+
case "clear":
|
|
993
|
+
return cut(chars, 0, at);
|
|
994
|
+
case "killend":
|
|
995
|
+
return cut(chars, at, chars.length);
|
|
996
|
+
case "yank":
|
|
997
|
+
return insert(chars, at, killed);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
function visible({ text, caret }, room) {
|
|
1001
|
+
const chars = [...text];
|
|
1002
|
+
const at = Math.min(Math.max(caret, 0), chars.length);
|
|
1003
|
+
const cells = at === chars.length ? [...chars, " "] : chars;
|
|
1004
|
+
const widths = cells.map((char) => Bun.stringWidth(char));
|
|
1005
|
+
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
1006
|
+
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
1007
|
+
let start = at;
|
|
1008
|
+
let end = at + 1;
|
|
1009
|
+
while (start > 0 && fits(start - 1, end))
|
|
1010
|
+
start--;
|
|
1011
|
+
while (end < cells.length && fits(start, end + 1))
|
|
1012
|
+
end++;
|
|
1013
|
+
const left = start > 0 ? "\u2026" : "";
|
|
1014
|
+
const right = end < cells.length ? "\u2026" : "";
|
|
1015
|
+
return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
|
|
1016
|
+
}
|
|
1017
|
+
var EDIT_KEYS, BACKWARD_KILLS, FORWARD_KILLS, WORD_CHARACTER, SPACE;
|
|
1018
|
+
var init_line = __esm(() => {
|
|
1019
|
+
EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
1020
|
+
BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
1021
|
+
FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
1022
|
+
WORD_CHARACTER = /[\p{L}\p{N}_]/u;
|
|
1023
|
+
SPACE = /\s/;
|
|
1024
|
+
});
|
|
1025
|
+
|
|
1026
|
+
// ../kit/src/picker/score.ts
|
|
1027
|
+
var BOUNDARY_AFTER, NONE;
|
|
1028
|
+
var init_score = __esm(() => {
|
|
1029
|
+
BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
1030
|
+
NONE = Number.NEGATIVE_INFINITY;
|
|
1031
|
+
});
|
|
1032
|
+
|
|
1033
|
+
// ../kit/src/picker/state.ts
|
|
1034
|
+
function repeat(value, count) {
|
|
1035
|
+
return Array.from({ length: count }).fill(value);
|
|
1036
|
+
}
|
|
1037
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
1038
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
1039
|
+
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
1040
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
1041
|
+
if (wheel !== undefined)
|
|
1042
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
1043
|
+
const named = codes.get(sequence);
|
|
1044
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1045
|
+
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
1046
|
+
paste.active = sequence === PASTE_START;
|
|
1047
|
+
return [];
|
|
1048
|
+
}
|
|
1049
|
+
if (paste.active && (sequence === "\r" || sequence === `
|
|
1050
|
+
`))
|
|
1051
|
+
return [];
|
|
1052
|
+
if (key !== undefined)
|
|
1053
|
+
return [key];
|
|
1054
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
var IS_CONTROL, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, MOUSE, WHEEL_LINES = 3, KEYS;
|
|
1058
|
+
var init_state = __esm(() => {
|
|
1059
|
+
init_text2();
|
|
1060
|
+
init_line();
|
|
1061
|
+
init_score();
|
|
1062
|
+
IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1063
|
+
KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1064
|
+
MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1065
|
+
KEYS = {
|
|
1066
|
+
"\x1B[A": "up",
|
|
1067
|
+
"\x1BOA": "up",
|
|
1068
|
+
"\x10": "up",
|
|
1069
|
+
"\x1B[B": "down",
|
|
1070
|
+
"\x1BOB": "down",
|
|
1071
|
+
"\x0E": "down",
|
|
1072
|
+
"\x1B[5~": "pageup",
|
|
1073
|
+
"\x1B[6~": "pagedown",
|
|
1074
|
+
"\x1B[H": "home",
|
|
1075
|
+
"\x1B[1~": "home",
|
|
1076
|
+
"\x1BOH": "home",
|
|
1077
|
+
"\x1B[F": "end",
|
|
1078
|
+
"\x1B[4~": "end",
|
|
1079
|
+
"\x1BOF": "end",
|
|
1080
|
+
"\r": "enter",
|
|
1081
|
+
"\n": "enter",
|
|
1082
|
+
"\x03": "cancel",
|
|
1083
|
+
"\x1B": "cancel",
|
|
1084
|
+
"\x1B[D": "left",
|
|
1085
|
+
"\x1BOD": "left",
|
|
1086
|
+
"\x1B[C": "right",
|
|
1087
|
+
"\x1BOC": "right",
|
|
1088
|
+
"\x1B[1;5D": "wordleft",
|
|
1089
|
+
"\x1B[1;3D": "wordleft",
|
|
1090
|
+
"\x1Bb": "wordleft",
|
|
1091
|
+
"\x1B[1;5C": "wordright",
|
|
1092
|
+
"\x1B[1;3C": "wordright",
|
|
1093
|
+
"\x1Bf": "wordright",
|
|
1094
|
+
"\x01": "linestart",
|
|
1095
|
+
"\x05": "lineend",
|
|
1096
|
+
"\x7F": "erase",
|
|
1097
|
+
"\x1B[3~": "delete",
|
|
1098
|
+
"\b": "killword",
|
|
1099
|
+
"\x1B\x7F": "killword",
|
|
1100
|
+
"\x1B[3;5~": "killnext",
|
|
1101
|
+
"\x1Bd": "killnext",
|
|
1102
|
+
"\x15": "clear",
|
|
1103
|
+
"\v": "killend",
|
|
1104
|
+
"\x17": "word",
|
|
1105
|
+
"\x19": "yank",
|
|
1106
|
+
"\x1A": "suspend",
|
|
1107
|
+
"\t": "tab",
|
|
1108
|
+
"\x1F": "help",
|
|
1109
|
+
"\x1BOP": "help",
|
|
1110
|
+
"\x1B[11~": "help"
|
|
1111
|
+
};
|
|
1112
|
+
});
|
|
1113
|
+
|
|
1114
|
+
// ../kit/src/redraw.ts
|
|
1115
|
+
function overwrite(lines, columns) {
|
|
1116
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
1117
|
+
`);
|
|
1118
|
+
}
|
|
1119
|
+
function rowsTaken(lines, columns) {
|
|
1120
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
1121
|
+
}
|
|
1122
|
+
var SYNC_START = "\x1B[?2026h", SYNC_END = "\x1B[?2026l";
|
|
1123
|
+
var init_redraw = __esm(() => {
|
|
1124
|
+
init_format();
|
|
1125
|
+
});
|
|
1126
|
+
|
|
1127
|
+
// ../kit/src/prompt.ts
|
|
1128
|
+
import process21 from "process";
|
|
1129
|
+
function readKeys(input, paste = { active: false }) {
|
|
1130
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
1131
|
+
}
|
|
1132
|
+
function roomAfter(question, columns) {
|
|
1133
|
+
return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
|
|
1134
|
+
}
|
|
1135
|
+
function withCaret(colors, line, room, dim = false) {
|
|
1136
|
+
const { before, at, after } = visible(line, room);
|
|
1137
|
+
const tone = dim ? colors.dim : (text) => text;
|
|
1138
|
+
return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
|
|
1139
|
+
}
|
|
1140
|
+
function sharedStart(texts) {
|
|
1141
|
+
const [first = [], ...rest] = texts.map((text) => [...text]);
|
|
1142
|
+
let length = first.length;
|
|
1143
|
+
for (const chars of rest) {
|
|
1144
|
+
const differs = chars.findIndex((char, index) => char !== first[index]);
|
|
1145
|
+
length = Math.min(length, differs === -1 ? chars.length : differs);
|
|
1146
|
+
}
|
|
1147
|
+
return first.slice(0, length).join("");
|
|
1148
|
+
}
|
|
1149
|
+
function listed2(colors, found, columns) {
|
|
1150
|
+
const shared = sharedStart(found);
|
|
1151
|
+
const cut = Math.max(shared.lastIndexOf("/"), shared.lastIndexOf(" ")) + 1;
|
|
1152
|
+
const names = found.slice(0, MAX_LISTED).map((each) => each.slice(cut));
|
|
1153
|
+
const more = found.length > MAX_LISTED ? ` \u2026 ${found.length - MAX_LISTED} more` : "";
|
|
1154
|
+
return ` ${colors.dim(truncate(names.join(" ") + more, Math.max(columns - 3, 1)))}`;
|
|
1155
|
+
}
|
|
1156
|
+
async function input2(question, { default: fallback, mask = false, validate, history, complete, ...settings } = {}) {
|
|
1157
|
+
let line = { text: "", caret: 0 };
|
|
1158
|
+
let invalid;
|
|
1159
|
+
let completions = [];
|
|
1160
|
+
const remembered = history === undefined || mask ? undefined : history;
|
|
1161
|
+
const earlier = remembered === undefined ? [] : earlierAnswers(remembered);
|
|
1162
|
+
let recalled = -1;
|
|
1163
|
+
let draft = line;
|
|
1164
|
+
const taken = () => line.text === "" ? fallback ?? "" : line.text;
|
|
1165
|
+
const shown = () => mask ? "*".repeat([...taken()].length) : taken();
|
|
1166
|
+
const accepted = await ask(question, settings, (colors, state, { columns }) => {
|
|
1167
|
+
if (state !== "asking")
|
|
1168
|
+
return [answer(colors, question, state, shown())];
|
|
1169
|
+
const typed = line.text === "" ? { text: shown(), caret: [...shown()].length } : { text: shown(), caret: line.caret };
|
|
1170
|
+
return [`${colors.cyan("?")} ${question} ${withCaret(colors, typed, roomAfter(question, columns), line.text === "")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`], ...completions.length > 1 ? [listed2(colors, completions, columns)] : []];
|
|
1171
|
+
}, (key) => {
|
|
1172
|
+
if (key === "cancel")
|
|
1173
|
+
return "cancel";
|
|
1174
|
+
invalid = undefined;
|
|
1175
|
+
completions = [];
|
|
1176
|
+
if (line.chained === true && endsKills(key))
|
|
1177
|
+
line = { ...line, chained: false };
|
|
1178
|
+
if (key === "tab") {
|
|
1179
|
+
const chars = [...line.text];
|
|
1180
|
+
const before = chars.slice(0, line.caret).join("");
|
|
1181
|
+
const found = complete?.(before) ?? [];
|
|
1182
|
+
const filled = sharedStart(found);
|
|
1183
|
+
if ([...filled].length > [...before].length)
|
|
1184
|
+
line = { ...line, text: filled + chars.slice(line.caret).join(""), caret: [...filled].length };
|
|
1185
|
+
else
|
|
1186
|
+
completions = found;
|
|
1187
|
+
return;
|
|
1188
|
+
}
|
|
1189
|
+
if (key === "enter") {
|
|
1190
|
+
invalid = validate?.(taken());
|
|
1191
|
+
return invalid === undefined ? "enter" : undefined;
|
|
1192
|
+
}
|
|
1193
|
+
if (key === "up" || key === "down") {
|
|
1194
|
+
const to = Math.min(Math.max(recalled + (key === "up" ? 1 : -1), -1), earlier.length - 1);
|
|
1195
|
+
if (recalled === -1)
|
|
1196
|
+
draft = line;
|
|
1197
|
+
recalled = to;
|
|
1198
|
+
const shown = to === -1 ? draft : { text: earlier[to], caret: [...earlier[to]].length };
|
|
1199
|
+
line = { ...shown, killed: line.killed ?? "" };
|
|
1200
|
+
return;
|
|
1201
|
+
}
|
|
1202
|
+
const edit = { home: "linestart", end: "lineend" }[key] ?? key;
|
|
1203
|
+
if (typeof edit === "object" || isEditKey(edit))
|
|
1204
|
+
line = editLine(line, edit);
|
|
1205
|
+
return;
|
|
1206
|
+
});
|
|
1207
|
+
if (!accepted)
|
|
1208
|
+
return;
|
|
1209
|
+
if (remembered !== undefined && taken() !== "")
|
|
1210
|
+
rememberAnswer(remembered, taken());
|
|
1211
|
+
return taken();
|
|
1212
|
+
}
|
|
1213
|
+
function answer(colors, question, state, picked) {
|
|
1214
|
+
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1215
|
+
}
|
|
1216
|
+
async function ask(question, { hint, terminal = process21 }, render, press) {
|
|
1217
|
+
const { stdin, stderr } = terminal;
|
|
1218
|
+
if (!isInteractive(terminal))
|
|
1219
|
+
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
1220
|
+
const colors = paint(stderr);
|
|
1221
|
+
let current = "asking";
|
|
1222
|
+
let outcome;
|
|
1223
|
+
const columns = () => stderr.columns || 80;
|
|
1224
|
+
const draw = (state, last = false) => {
|
|
1225
|
+
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
1226
|
+
const rows = rowsTaken(frame, columns());
|
|
1227
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
1228
|
+
current = state;
|
|
1229
|
+
};
|
|
1230
|
+
const redraw = () => draw(current);
|
|
1231
|
+
const paste = { active: false };
|
|
1232
|
+
const stop = terminal.stop ?? (terminal === process21 ? stopJob : undefined);
|
|
1233
|
+
const suspend = () => {
|
|
1234
|
+
if (stop === undefined)
|
|
1235
|
+
return;
|
|
1236
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
1237
|
+
stdin.setRawMode(false);
|
|
1238
|
+
stop();
|
|
1239
|
+
stdin.setRawMode(true);
|
|
1240
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1241
|
+
};
|
|
1242
|
+
try {
|
|
1243
|
+
stderr.on?.("resize", redraw);
|
|
1244
|
+
stdin.setRawMode(true);
|
|
1245
|
+
stdin.resume();
|
|
1246
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1247
|
+
draw("asking");
|
|
1248
|
+
return await new Promise((resolve) => {
|
|
1249
|
+
function onData(data) {
|
|
1250
|
+
for (const key of readKeys(data.toString(), paste)) {
|
|
1251
|
+
if (key === "suspend") {
|
|
1252
|
+
suspend();
|
|
1253
|
+
continue;
|
|
1254
|
+
}
|
|
1255
|
+
const pressed = press(key);
|
|
1256
|
+
if (pressed !== undefined) {
|
|
1257
|
+
settle(pressed);
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
draw("asking");
|
|
1262
|
+
}
|
|
1263
|
+
function onEnd() {
|
|
1264
|
+
settle("cancel");
|
|
1265
|
+
}
|
|
1266
|
+
function settle(settled) {
|
|
1267
|
+
outcome = settled;
|
|
1268
|
+
stdin.off("data", onData);
|
|
1269
|
+
stdin.off("end", onEnd);
|
|
1270
|
+
resolve(settled === "enter");
|
|
1271
|
+
}
|
|
1272
|
+
stdin.on("data", onData);
|
|
1273
|
+
stdin.on("end", onEnd);
|
|
1274
|
+
});
|
|
1275
|
+
} finally {
|
|
1276
|
+
stderr.off?.("resize", redraw);
|
|
1277
|
+
draw(outcome ?? "cancel", true);
|
|
1278
|
+
stderr.write(`
|
|
1279
|
+
\x1B[?25h\x1B[?2004l`);
|
|
1280
|
+
stdin.setRawMode(false);
|
|
1281
|
+
stdin.pause();
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
var PROMPT_KEYS, MAX_LISTED = 12;
|
|
1285
|
+
var init_prompt = __esm(() => {
|
|
1286
|
+
init_answers();
|
|
1287
|
+
init_args();
|
|
1288
|
+
init_format();
|
|
1289
|
+
init_job();
|
|
1290
|
+
init_mode();
|
|
1291
|
+
init_line();
|
|
1292
|
+
init_state();
|
|
1293
|
+
init_redraw();
|
|
1294
|
+
init_style();
|
|
1295
|
+
PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
1296
|
+
});
|
|
1297
|
+
|
|
1298
|
+
// src/ev.ts
|
|
1299
|
+
import process23 from "process";
|
|
1300
|
+
|
|
1301
|
+
// ../kit/src/index.ts
|
|
1302
|
+
init_args();
|
|
1303
|
+
|
|
1304
|
+
// ../kit/src/argv.ts
|
|
1305
|
+
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
1306
|
+
import { resolve as resolve3 } from "path";
|
|
1307
|
+
import process11 from "process";
|
|
1308
|
+
function commandLine() {
|
|
1309
|
+
try {
|
|
1310
|
+
return readFileSync3("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
1311
|
+
} catch {
|
|
1312
|
+
return;
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
function realPath(word) {
|
|
1316
|
+
try {
|
|
1317
|
+
return realpathSync(resolve3(word));
|
|
1318
|
+
} catch {
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
function scriptArgs(argv = process11.argv.slice(2), cmdline = commandLine(), script = process11.argv[1]) {
|
|
1323
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
1324
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
1325
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
1326
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
1327
|
+
}
|
|
1328
|
+
// ../kit/src/chart.ts
|
|
1329
|
+
init_format();
|
|
1330
|
+
init_mode();
|
|
1331
|
+
init_style();
|
|
1332
|
+
init_theme();
|
|
1333
|
+
// ../kit/src/ci.ts
|
|
1334
|
+
init_args();
|
|
1335
|
+
init_format();
|
|
1336
|
+
|
|
1337
|
+
// ../kit/src/progress.ts
|
|
1338
|
+
init_format();
|
|
1339
|
+
init_style();
|
|
1340
|
+
init_theme();
|
|
1341
|
+
var ESC = String.fromCharCode(27);
|
|
1342
|
+
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
1343
|
+
var RESET_STYLE = `${ESC}[0m`;
|
|
1344
|
+
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
1345
|
+
|
|
1346
|
+
// ../kit/src/ci.ts
|
|
1347
|
+
init_style();
|
|
1348
|
+
|
|
1349
|
+
// ../kit/src/tool.ts
|
|
1350
|
+
init_format();
|
|
1351
|
+
// ../kit/src/cli.ts
|
|
1352
|
+
init_args();
|
|
1353
|
+
import { readFileSync as readFileSync4, realpathSync as realpathSync2 } from "fs";
|
|
1354
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
1355
|
+
import process15 from "process";
|
|
1356
|
+
|
|
1357
|
+
// ../kit/src/askpass.ts
|
|
1358
|
+
import process12 from "process";
|
|
1359
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1360
|
+
async function askpassClient(argv) {
|
|
1361
|
+
const socketPath = process12.env[SOCKET_VARIABLE];
|
|
1362
|
+
if (socketPath === undefined)
|
|
1363
|
+
return;
|
|
1364
|
+
const request = { prompt: argv[0] ?? "", ...process12.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
1365
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
1366
|
+
let received = "";
|
|
1367
|
+
try {
|
|
1368
|
+
await Bun.connect({
|
|
1369
|
+
unix: socketPath,
|
|
1370
|
+
socket: {
|
|
1371
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
1372
|
+
`),
|
|
1373
|
+
data: (_, chunk) => {
|
|
1374
|
+
received += chunk.toString();
|
|
1375
|
+
},
|
|
1376
|
+
close: () => resolve(received),
|
|
1377
|
+
error: () => resolve("")
|
|
1378
|
+
}
|
|
1379
|
+
});
|
|
1380
|
+
} catch {
|
|
1381
|
+
return 1;
|
|
1382
|
+
}
|
|
1383
|
+
const reply = await promise;
|
|
1384
|
+
if (reply === "")
|
|
1385
|
+
return 1;
|
|
1386
|
+
const { answer } = JSON.parse(reply);
|
|
1387
|
+
if (request.notice === true)
|
|
1388
|
+
return 0;
|
|
1389
|
+
if (answer === undefined)
|
|
1390
|
+
return 1;
|
|
1391
|
+
process12.stdout.write(`${answer}
|
|
1392
|
+
`);
|
|
1393
|
+
return 0;
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
// ../kit/src/completions.ts
|
|
1397
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
1398
|
+
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'
|
|
1399
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
1400
|
+
set -l current (commandline -ct)
|
|
1401
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
1402
|
+
if test "$line" = __files__
|
|
1403
|
+
__fish_complete_path $current
|
|
1404
|
+
else
|
|
1405
|
+
echo $line
|
|
1406
|
+
end
|
|
1407
|
+
end
|
|
1408
|
+
end`;
|
|
1409
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1410
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
1411
|
+
local -a lines
|
|
1412
|
+
COMPREPLY=()
|
|
1413
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
1414
|
+
for line in "\${lines[@]}"; do
|
|
1415
|
+
if [[ $line == __files__ ]]; then
|
|
1416
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
1417
|
+
else
|
|
1418
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
1419
|
+
fi
|
|
1420
|
+
done
|
|
1421
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
1422
|
+
}`;
|
|
1423
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1424
|
+
local line
|
|
1425
|
+
local -a described plain
|
|
1426
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
1427
|
+
if [[ $line == __files__ ]]; then
|
|
1428
|
+
_files
|
|
1429
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
1430
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
1431
|
+
else
|
|
1432
|
+
plain+=("$line")
|
|
1433
|
+
fi
|
|
1434
|
+
done
|
|
1435
|
+
(( \${#described} )) && _describe -V value described
|
|
1436
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
1437
|
+
return 0
|
|
1438
|
+
}`;
|
|
1439
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
1440
|
+
if (shell === "fish")
|
|
1441
|
+
return `${header}
|
|
1442
|
+
${FISH_FUNCTION}
|
|
1443
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
1444
|
+
`).join("")}`;
|
|
1445
|
+
if (shell === "bash")
|
|
1446
|
+
return `${header}
|
|
1447
|
+
${BASH_FUNCTION}
|
|
1448
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1449
|
+
`;
|
|
1450
|
+
return `${header}
|
|
1451
|
+
${ZSH_FUNCTION}
|
|
1452
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1453
|
+
`;
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
// ../kit/src/notify.ts
|
|
1457
|
+
init_format();
|
|
1458
|
+
init_mode();
|
|
1459
|
+
import process13 from "process";
|
|
1460
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
1461
|
+
var CANCELLED = 130;
|
|
1462
|
+
function base64(text) {
|
|
1463
|
+
return Buffer.from(text).toString("base64");
|
|
1464
|
+
}
|
|
1465
|
+
function notification(title, body, env = process13.env) {
|
|
1466
|
+
const id = `kit${process13.pid}`;
|
|
1467
|
+
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\\`];
|
|
1468
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1469
|
+
}
|
|
1470
|
+
function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
|
|
1471
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1472
|
+
return;
|
|
1473
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
// ../kit/src/cli.ts
|
|
1477
|
+
init_style();
|
|
1478
|
+
init_text2();
|
|
1479
|
+
|
|
1480
|
+
// ../kit/src/usage.ts
|
|
1481
|
+
import { appendFileSync, mkdirSync } from "fs";
|
|
1482
|
+
import { homedir as homedir3 } from "os";
|
|
1483
|
+
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
1484
|
+
import process14 from "process";
|
|
1485
|
+
|
|
1486
|
+
// ../kit/src/logs.ts
|
|
1487
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
1488
|
+
var CLI_FOLDER = "kaynooo-cli";
|
|
1489
|
+
|
|
1490
|
+
// ../kit/src/usage.ts
|
|
1491
|
+
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
1492
|
+
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
1493
|
+
var LONGEST_NAME = 40;
|
|
1494
|
+
var usageError;
|
|
1495
|
+
function noteUsageError(message) {
|
|
1496
|
+
usageError = message;
|
|
1497
|
+
}
|
|
1498
|
+
function stateHome(env = process14.env) {
|
|
1499
|
+
const dir = env.XDG_STATE_HOME;
|
|
1500
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
919
1501
|
}
|
|
920
|
-
function
|
|
1502
|
+
function usagePath(env = process14.env) {
|
|
1503
|
+
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1504
|
+
}
|
|
1505
|
+
function usageRecorded(env = process14.env) {
|
|
1506
|
+
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1507
|
+
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1508
|
+
}
|
|
1509
|
+
function flagNames(argv) {
|
|
1510
|
+
const end = argv.indexOf("--");
|
|
1511
|
+
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
1512
|
+
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
1513
|
+
}
|
|
1514
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
1515
|
+
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
1516
|
+
usageError = undefined;
|
|
1517
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
1518
|
+
}
|
|
1519
|
+
function recordUsage(entry, env = process14.env) {
|
|
921
1520
|
if (!usageRecorded(env))
|
|
922
1521
|
return;
|
|
923
1522
|
try {
|
|
@@ -1011,8 +1610,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
1011
1610
|
`);
|
|
1012
1611
|
}
|
|
1013
1612
|
function printError(prefix, message, hint, cause) {
|
|
1014
|
-
const colors = paint(
|
|
1015
|
-
const styled = takesControlCodes(
|
|
1613
|
+
const colors = paint(process15.stderr);
|
|
1614
|
+
const styled = takesControlCodes(process15.stderr);
|
|
1016
1615
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1017
1616
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1018
1617
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1055,11 +1654,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
1055
1654
|
}
|
|
1056
1655
|
}
|
|
1057
1656
|
if (name === undefined && level.path.length > 1) {
|
|
1058
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1657
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stderr));
|
|
1059
1658
|
return 2;
|
|
1060
1659
|
}
|
|
1061
1660
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1062
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1661
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stdout));
|
|
1063
1662
|
return 0;
|
|
1064
1663
|
}
|
|
1065
1664
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1205,6 +1804,9 @@ function packageVersion(entry = Bun.main) {
|
|
|
1205
1804
|
}
|
|
1206
1805
|
async function runCli(cli, argv = scriptArgs()) {
|
|
1207
1806
|
const version = cli.version ?? packageVersion();
|
|
1807
|
+
const answered = await askpassClient(argv);
|
|
1808
|
+
if (answered !== undefined)
|
|
1809
|
+
return answered;
|
|
1208
1810
|
if (argv[0] === COMPLETE)
|
|
1209
1811
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1210
1812
|
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
@@ -1215,7 +1817,7 @@ async function runCli(cli, argv = scriptArgs()) {
|
|
|
1215
1817
|
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1216
1818
|
if (cli.usage !== false) {
|
|
1217
1819
|
try {
|
|
1218
|
-
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
1820
|
+
recordUsage(usageEntry(cli.name, command, argv, code, { ms: performance.now() - started }));
|
|
1219
1821
|
} catch {}
|
|
1220
1822
|
}
|
|
1221
1823
|
return code;
|
|
@@ -1235,30 +1837,6 @@ function commandPath(scope, argv) {
|
|
|
1235
1837
|
}
|
|
1236
1838
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1237
1839
|
}
|
|
1238
|
-
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1239
|
-
if (argv[0] === COMPLETE)
|
|
1240
|
-
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1241
|
-
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1242
|
-
return printCompletionScript(name, flagValue(argv));
|
|
1243
|
-
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
1244
|
-
console.log(version ?? packageVersion());
|
|
1245
|
-
return 0;
|
|
1246
|
-
}
|
|
1247
|
-
let code;
|
|
1248
|
-
const started = performance.now();
|
|
1249
|
-
try {
|
|
1250
|
-
code = await run(argv);
|
|
1251
|
-
} catch (error) {
|
|
1252
|
-
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1253
|
-
}
|
|
1254
|
-
notifyEnd(name, code, performance.now() - started);
|
|
1255
|
-
if (usage !== false) {
|
|
1256
|
-
try {
|
|
1257
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1258
|
-
} catch {}
|
|
1259
|
-
}
|
|
1260
|
-
return code;
|
|
1261
|
-
}
|
|
1262
1840
|
// ../kit/src/compose.ts
|
|
1263
1841
|
async function captureOutput(argv, { cwd, env } = {}) {
|
|
1264
1842
|
const run = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, env: { ...process.env, ...env }, stdin: "ignore", stdout: "pipe", stderr: "pipe" });
|
|
@@ -1268,19 +1846,28 @@ async function captureOutput(argv, { cwd, env } = {}) {
|
|
|
1268
1846
|
async function compose(args, { flags = [], ...options } = {}) {
|
|
1269
1847
|
return captureOutput(["docker", "compose", ...flags, ...args], options);
|
|
1270
1848
|
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1849
|
+
|
|
1850
|
+
// ../kit/src/index.ts
|
|
1851
|
+
init_config();
|
|
1852
|
+
|
|
1853
|
+
// ../kit/src/excerpt.ts
|
|
1854
|
+
init_text2();
|
|
1855
|
+
|
|
1856
|
+
// ../kit/src/index.ts
|
|
1857
|
+
init_folders();
|
|
1858
|
+
init_format();
|
|
1859
|
+
|
|
1860
|
+
// ../kit/src/git.ts
|
|
1861
|
+
init_args();
|
|
1862
|
+
// ../kit/src/limit.ts
|
|
1863
|
+
init_args();
|
|
1864
|
+
|
|
1865
|
+
// ../kit/src/index.ts
|
|
1866
|
+
init_mode();
|
|
1867
|
+
|
|
1868
|
+
// ../kit/src/report.ts
|
|
1869
|
+
init_style();
|
|
1870
|
+
init_text2();
|
|
1284
1871
|
// ../kit/src/secrets.ts
|
|
1285
1872
|
var SECRET_PART = /token|secret|passw|credential|private|dsn|apikey|accesskey|key$/i;
|
|
1286
1873
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
@@ -1292,10 +1879,23 @@ function isSecretName(name) {
|
|
|
1292
1879
|
var {Glob } = globalThis.Bun;
|
|
1293
1880
|
var SESSION_FILES = new Glob("*.json");
|
|
1294
1881
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1882
|
+
|
|
1883
|
+
// ../kit/src/index.ts
|
|
1884
|
+
init_style();
|
|
1885
|
+
init_text2();
|
|
1886
|
+
init_theme();
|
|
1887
|
+
init_user_config();
|
|
1888
|
+
|
|
1889
|
+
// ../kit/src/watch.ts
|
|
1890
|
+
init_args();
|
|
1891
|
+
init_input();
|
|
1892
|
+
init_style();
|
|
1893
|
+
// ../kit/src/workspace-root.ts
|
|
1894
|
+
init_user_config();
|
|
1295
1895
|
// src/commands/audit.ts
|
|
1296
1896
|
import { stat as stat4 } from "fs/promises";
|
|
1297
1897
|
import { relative, resolve as resolve4 } from "path";
|
|
1298
|
-
import
|
|
1898
|
+
import process18 from "process";
|
|
1299
1899
|
|
|
1300
1900
|
// ../kit/src/shell.ts
|
|
1301
1901
|
var SEPARATORS = new Set([`
|
|
@@ -1351,7 +1951,7 @@ var {$ } = globalThis.Bun;
|
|
|
1351
1951
|
|
|
1352
1952
|
// src/files.ts
|
|
1353
1953
|
import { chmod, chown, readdir, realpath, rename, rm, stat, writeFile } from "fs/promises";
|
|
1354
|
-
import { basename, dirname as dirname4, join as join7 } from "path";
|
|
1954
|
+
import { basename, dirname as dirname4, extname, join as join7 } from "path";
|
|
1355
1955
|
|
|
1356
1956
|
// src/dotenv.ts
|
|
1357
1957
|
var ASSIGNMENT = /^\s*(?:export\s+)?([A-Z_][\w.-]*)\s*=(.*)$/i;
|
|
@@ -1697,11 +2297,30 @@ async function envFiles(folder = process.cwd()) {
|
|
|
1697
2297
|
}
|
|
1698
2298
|
return names.sort();
|
|
1699
2299
|
}
|
|
1700
|
-
|
|
2300
|
+
var OTHER_FORMATS = { ".json": "JSON", ".jsonc": "JSON", ".json5": "JSON", ".yaml": "YAML", ".yml": "YAML", ".toml": "TOML", ".ini": "INI", ".xml": "XML" };
|
|
2301
|
+
var BLANK_OR_COMMENT = /^\s*(?:#.*)?$/;
|
|
2302
|
+
function notDotenv(why, redact) {
|
|
2303
|
+
fail(`${why}, and ev reads dotenv files (KEY=value lines)`, 2, `\`${redact}\` masks the secrets of any text`);
|
|
2304
|
+
}
|
|
2305
|
+
function assertDotenvName(path, redact = `ev redact < ${path}`) {
|
|
2306
|
+
const format = OTHER_FORMATS[extname(path).toLowerCase()];
|
|
2307
|
+
if (format !== undefined)
|
|
2308
|
+
notDotenv(`${path} is ${format}`, redact);
|
|
2309
|
+
}
|
|
2310
|
+
function assertDotenvText(path, dotenv, redact = `ev redact < ${path}`) {
|
|
2311
|
+
if (dotenv.lines.every((line) => line.key === undefined) && !dotenv.lines.every((line) => BLANK_OR_COMMENT.test(line.raw)))
|
|
2312
|
+
notDotenv(`${path} holds no KEY=value line, so it is not a dotenv file`, redact);
|
|
2313
|
+
}
|
|
2314
|
+
async function readEnv(path, { scanned = false } = {}) {
|
|
1701
2315
|
const file = Bun.file(path);
|
|
2316
|
+
if (!scanned)
|
|
2317
|
+
assertDotenvName(path);
|
|
1702
2318
|
if (!await file.exists())
|
|
1703
2319
|
fail(`${path} does not exist`);
|
|
1704
|
-
|
|
2320
|
+
const dotenv = parseDotenv(await file.text());
|
|
2321
|
+
if (!scanned)
|
|
2322
|
+
assertDotenvText(path, dotenv);
|
|
2323
|
+
return dotenv;
|
|
1705
2324
|
}
|
|
1706
2325
|
async function writeAtomic(path, text) {
|
|
1707
2326
|
let target = path;
|
|
@@ -2116,11 +2735,10 @@ async function move(fix, compose, composeAfter, envBefore, envAfter) {
|
|
|
2116
2735
|
}
|
|
2117
2736
|
|
|
2118
2737
|
// src/commands/audit.ts
|
|
2119
|
-
var usage2 = `ev audit [dir...] [--fix]
|
|
2738
|
+
var usage2 = `ev audit [dir...] [--fix]: lists the .env files any account can read or git tracks and the compose files writing a secret out, never printing a value
|
|
2120
2739
|
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
With --fix, moves each secret a listed compose file writes out into the .env beside it as \${KEY}, puts it back when \`docker compose config\` resolves differently after, and shuts other accounts out of both files and of every listed .env; a key the .env already sets to another value stays put.`;
|
|
2740
|
+
It looks under each folder (the current one by default) down to 5 levels, skipping \`node_modules\`, \`vendor\` and \`.git\`, and leaves \`.example\`, \`.sample\`, \`.template\` and \`.dist\` files out.
|
|
2741
|
+
With --fix, each secret a listed compose file writes out moves into the .env beside it as \`\${KEY}\` and goes back when \`docker compose config\` resolves differently after; a key the .env already sets to another value stays put.`;
|
|
2124
2742
|
var EXITS = [[0, "it finds none (with --fix, when none is left)"], [1, "it finds one"], [2, "a usage error"]];
|
|
2125
2743
|
var options = {
|
|
2126
2744
|
json: jsonOption("the findings and the folders it could not read"),
|
|
@@ -2141,12 +2759,12 @@ async function isFolder(path) {
|
|
|
2141
2759
|
}
|
|
2142
2760
|
}
|
|
2143
2761
|
function shown2(path) {
|
|
2144
|
-
return path.startsWith(`${
|
|
2762
|
+
return path.startsWith(`${process18.cwd()}/`) ? relative(process18.cwd(), path) : path;
|
|
2145
2763
|
}
|
|
2146
2764
|
async function fixAll(exposed, json) {
|
|
2147
2765
|
const fixed = [];
|
|
2148
2766
|
let left = false;
|
|
2149
|
-
const tint = role("path",
|
|
2767
|
+
const tint = role("path", process18.stdout);
|
|
2150
2768
|
for (const { path, readable, group, tracked, secrets } of exposed) {
|
|
2151
2769
|
const fix = secrets === undefined ? undefined : await fixCompose(path, group === true);
|
|
2152
2770
|
const open = fix?.open ?? (readable && !await shutOthersOut(path, group === true) ? [path] : []);
|
|
@@ -2198,489 +2816,86 @@ async function audit2(args) {
|
|
|
2198
2816
|
console.log("no exposed .env file nor compose file writing a secret out");
|
|
2199
2817
|
return 0;
|
|
2200
2818
|
}
|
|
2201
|
-
const uid =
|
|
2202
|
-
const tint = role("path",
|
|
2819
|
+
const uid = process18.getuid?.();
|
|
2820
|
+
const tint = role("path", process18.stdout);
|
|
2203
2821
|
for (const { path, readable, group, tracked, secrets } of exposed) {
|
|
2204
2822
|
const sudo = uid !== undefined && uid !== 0 && (await stat4(path)).uid !== uid ? "sudo " : "";
|
|
2205
2823
|
const problems = [
|
|
2206
2824
|
...secrets === undefined ? [] : [`writes out ${secrets.join(", ")}: ev audit --fix moves the values into a .env beside it`],
|
|
2207
2825
|
...readable ? [group === true ? `readable by its group or an ACL: ${sudo}chmod go-rwx ${shellQuote(shown2(path))}` : `readable by any account: ${sudo}chmod o-rwx ${shellQuote(shown2(path))}`] : [],
|
|
2208
2826
|
...tracked ? [`tracked by git: git rm --cached ${shellQuote(shown2(path))}, then ignore it`] : []
|
|
2209
|
-
];
|
|
2210
|
-
console.log(`${tint(shown2(path))}
|
|
2211
|
-
${problems.join(`
|
|
2212
|
-
`)}`);
|
|
2213
|
-
}
|
|
2214
|
-
return 1;
|
|
2215
|
-
}
|
|
2216
|
-
|
|
2217
|
-
// src/commands/compare.ts
|
|
2218
|
-
import process18 from "process";
|
|
2219
|
-
var diffUsage = `ev diff <a> <b>
|
|
2220
|
-
|
|
2221
|
-
Names the keys set in one file and not the other, never their values.
|
|
2222
|
-
|
|
2223
|
-
--json prints {a, b, onlyA, onlyB}.`;
|
|
2224
|
-
var DIFF_EXITS = [[0, "both set the same keys"], [1, "they differ"], [2, "a usage error"]];
|
|
2225
|
-
var missingUsage = `ev missing [file]
|
|
2226
|
-
|
|
2227
|
-
Names the keys the reference file sets that the file (.env by default) does not.
|
|
2228
|
-
|
|
2229
|
-
--json prints {a, b, onlyA, onlyB} with the reference as a, so onlyA is what is missing.`;
|
|
2230
|
-
var MISSING_EXITS = [[0, "none is missing"], [1, "some are"], [2, "a usage error"]];
|
|
2231
|
-
var jsonFlag = { json: jsonOption() };
|
|
2232
|
-
async function keys(path) {
|
|
2233
|
-
return new Set(entries(await readEnv(path)).keys());
|
|
2234
|
-
}
|
|
2235
|
-
async function diff(args) {
|
|
2236
|
-
const parsed = parse(args, diffUsage, jsonFlag, { exits: DIFF_EXITS });
|
|
2237
|
-
const [a, b] = parsed.positionals;
|
|
2238
|
-
if (a === undefined || b === undefined)
|
|
2239
|
-
fail(`needs two files
|
|
2240
|
-
|
|
2241
|
-
${diffUsage}`);
|
|
2242
|
-
const left = await keys(a);
|
|
2243
|
-
const right = await keys(b);
|
|
2244
|
-
const onlyA = [...left].filter((key) => !right.has(key));
|
|
2245
|
-
const onlyB = [...right].filter((key) => !left.has(key));
|
|
2246
|
-
if (parsed.values.json === true) {
|
|
2247
|
-
printJson({ a, b, onlyA, onlyB });
|
|
2248
|
-
return onlyA.length + onlyB.length === 0 ? 0 : 1;
|
|
2249
|
-
}
|
|
2250
|
-
const path = role("path", process18.stdout);
|
|
2251
|
-
const value = role("value", process18.stdout);
|
|
2252
|
-
const lines = [...onlyA.map((key) => `only in ${path(a)}: ${value(key)}`), ...onlyB.map((key) => `only in ${path(b)}: ${value(key)}`)];
|
|
2253
|
-
if (lines.length === 0)
|
|
2254
|
-
return 0;
|
|
2255
|
-
console.log(lines.join(`
|
|
2256
|
-
`));
|
|
2257
|
-
return 1;
|
|
2258
|
-
}
|
|
2259
|
-
async function missing(args) {
|
|
2260
|
-
const parsed = parse(args, missingUsage, { against: { type: "string", description: "the reference file (.env.example by default)" }, ...jsonFlag }, { exits: MISSING_EXITS });
|
|
2261
|
-
const [file = ".env"] = parsed.positionals;
|
|
2262
|
-
const against = parsed.values.against ?? ".env.example";
|
|
2263
|
-
const have = await keys(file);
|
|
2264
|
-
const reference = await keys(against);
|
|
2265
|
-
const absent = [...reference].filter((key) => !have.has(key));
|
|
2266
|
-
if (parsed.values.json === true) {
|
|
2267
|
-
printJson({ a: against, b: file, onlyA: absent, onlyB: [...have].filter((key) => !reference.has(key)) });
|
|
2268
|
-
return absent.length === 0 ? 0 : 1;
|
|
2269
|
-
}
|
|
2270
|
-
if (absent.length === 0)
|
|
2271
|
-
return 0;
|
|
2272
|
-
const path = role("path", process18.stdout);
|
|
2273
|
-
const value = role("value", process18.stdout);
|
|
2274
|
-
console.log(absent.map((key) => `${value(key)} (set in ${path(against)}, not in ${path(file)})`).join(`
|
|
2275
|
-
`));
|
|
2276
|
-
return 1;
|
|
2277
|
-
}
|
|
2278
|
-
|
|
2279
|
-
// ../kit/src/prompt.ts
|
|
2280
|
-
import process20 from "process";
|
|
2281
|
-
|
|
2282
|
-
// ../kit/src/answers.ts
|
|
2283
|
-
import { mkdirSync as mkdirSync2, readFileSync as readFileSync5, writeFileSync } from "fs";
|
|
2284
|
-
import { dirname as dirname7, join as join10 } from "path";
|
|
2285
|
-
var KEPT = 50;
|
|
2286
|
-
function answersFile() {
|
|
2287
|
-
return join10(cacheFolder(), "kaynooo-cli", "answers.json");
|
|
2288
|
-
}
|
|
2289
|
-
function stored() {
|
|
2290
|
-
try {
|
|
2291
|
-
const parsed = JSON.parse(readFileSync5(answersFile(), "utf-8"));
|
|
2292
|
-
if (typeof parsed !== "object" || parsed === null)
|
|
2293
|
-
return {};
|
|
2294
|
-
return Object.fromEntries(Object.entries(parsed).filter((entry) => Array.isArray(entry[1]) && entry[1].every((answer) => typeof answer === "string")));
|
|
2295
|
-
} catch {
|
|
2296
|
-
return {};
|
|
2297
|
-
}
|
|
2298
|
-
}
|
|
2299
|
-
function earlierAnswers(key) {
|
|
2300
|
-
return stored()[key] ?? [];
|
|
2301
|
-
}
|
|
2302
|
-
function rememberAnswer(key, answer) {
|
|
2303
|
-
const all = stored();
|
|
2304
|
-
const file = answersFile();
|
|
2305
|
-
all[key] = [answer, ...(all[key] ?? []).filter((earlier) => earlier !== answer)].slice(0, KEPT);
|
|
2306
|
-
try {
|
|
2307
|
-
mkdirSync2(dirname7(file), { recursive: true });
|
|
2308
|
-
writeFileSync(file, JSON.stringify(all));
|
|
2309
|
-
} catch {}
|
|
2310
|
-
}
|
|
2311
|
-
|
|
2312
|
-
// ../kit/src/job.ts
|
|
2313
|
-
import process19 from "process";
|
|
2314
|
-
function stopJob() {
|
|
2315
|
-
process19.kill(0, "SIGTSTP");
|
|
2316
|
-
}
|
|
2317
|
-
|
|
2318
|
-
// ../kit/src/picker/line.ts
|
|
2319
|
-
var EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
2320
|
-
var BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
2321
|
-
var FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
2322
|
-
function isEditKey(key) {
|
|
2323
|
-
return EDIT_KEYS.has(key);
|
|
2324
|
-
}
|
|
2325
|
-
function endsKills(key) {
|
|
2326
|
-
return typeof key !== "object" && !isEditKey(key);
|
|
2327
|
-
}
|
|
2328
|
-
var WORD_CHARACTER = /[\p{L}\p{N}_]/u;
|
|
2329
|
-
var SPACE = /\s/;
|
|
2330
|
-
function isWord(char) {
|
|
2331
|
-
return char !== undefined && WORD_CHARACTER.test(char);
|
|
2332
|
-
}
|
|
2333
|
-
function wordStart(chars, from) {
|
|
2334
|
-
let at = from;
|
|
2335
|
-
while (at > 0 && !isWord(chars[at - 1]))
|
|
2336
|
-
at--;
|
|
2337
|
-
while (at > 0 && isWord(chars[at - 1]))
|
|
2338
|
-
at--;
|
|
2339
|
-
return at;
|
|
2340
|
-
}
|
|
2341
|
-
function wordEnd(chars, from) {
|
|
2342
|
-
let at = from;
|
|
2343
|
-
while (at < chars.length && !isWord(chars[at]))
|
|
2344
|
-
at++;
|
|
2345
|
-
while (at < chars.length && isWord(chars[at]))
|
|
2346
|
-
at++;
|
|
2347
|
-
return at;
|
|
2348
|
-
}
|
|
2349
|
-
function spacedStart(chars, from) {
|
|
2350
|
-
let at = from;
|
|
2351
|
-
while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
|
|
2352
|
-
at--;
|
|
2353
|
-
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
2354
|
-
at--;
|
|
2355
|
-
return at;
|
|
2356
|
-
}
|
|
2357
|
-
function cut(chars, from, to) {
|
|
2358
|
-
return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
|
|
2359
|
-
}
|
|
2360
|
-
function insert(chars, at, text) {
|
|
2361
|
-
const typed = [...text];
|
|
2362
|
-
return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
|
|
2363
|
-
}
|
|
2364
|
-
function editLine(line, key) {
|
|
2365
|
-
const { killed = "", chained = false } = line;
|
|
2366
|
-
const chars = [...line.text];
|
|
2367
|
-
const at = Math.min(Math.max(line.caret, 0), chars.length);
|
|
2368
|
-
const edited = edit(chars, at, key, killed);
|
|
2369
|
-
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
2370
|
-
return line.killed === undefined ? edited : { ...edited, killed };
|
|
2371
|
-
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
2372
|
-
if (taken === "")
|
|
2373
|
-
return { ...edited, killed, chained };
|
|
2374
|
-
if (!chained)
|
|
2375
|
-
return { ...edited, killed: taken, chained: true };
|
|
2376
|
-
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
2377
|
-
}
|
|
2378
|
-
function edit(chars, at, key, killed) {
|
|
2379
|
-
const text = chars.join("");
|
|
2380
|
-
if (typeof key === "object")
|
|
2381
|
-
return insert(chars, at, key.text);
|
|
2382
|
-
switch (key) {
|
|
2383
|
-
case "left":
|
|
2384
|
-
return { text, caret: Math.max(at - 1, 0) };
|
|
2385
|
-
case "right":
|
|
2386
|
-
return { text, caret: Math.min(at + 1, chars.length) };
|
|
2387
|
-
case "wordleft":
|
|
2388
|
-
return { text, caret: wordStart(chars, at) };
|
|
2389
|
-
case "wordright":
|
|
2390
|
-
return { text, caret: wordEnd(chars, at) };
|
|
2391
|
-
case "linestart":
|
|
2392
|
-
return { text, caret: 0 };
|
|
2393
|
-
case "lineend":
|
|
2394
|
-
return { text, caret: chars.length };
|
|
2395
|
-
case "erase":
|
|
2396
|
-
return cut(chars, Math.max(at - 1, 0), at);
|
|
2397
|
-
case "delete":
|
|
2398
|
-
return cut(chars, at, Math.min(at + 1, chars.length));
|
|
2399
|
-
case "word":
|
|
2400
|
-
return cut(chars, spacedStart(chars, at), at);
|
|
2401
|
-
case "killword":
|
|
2402
|
-
return cut(chars, wordStart(chars, at), at);
|
|
2403
|
-
case "killnext":
|
|
2404
|
-
return cut(chars, at, wordEnd(chars, at));
|
|
2405
|
-
case "clear":
|
|
2406
|
-
return cut(chars, 0, at);
|
|
2407
|
-
case "killend":
|
|
2408
|
-
return cut(chars, at, chars.length);
|
|
2409
|
-
case "yank":
|
|
2410
|
-
return insert(chars, at, killed);
|
|
2827
|
+
];
|
|
2828
|
+
console.log(`${tint(shown2(path))}
|
|
2829
|
+
${problems.join(`
|
|
2830
|
+
`)}`);
|
|
2411
2831
|
}
|
|
2412
|
-
|
|
2413
|
-
function visible({ text, caret }, room) {
|
|
2414
|
-
const chars = [...text];
|
|
2415
|
-
const at = Math.min(Math.max(caret, 0), chars.length);
|
|
2416
|
-
const cells = at === chars.length ? [...chars, " "] : chars;
|
|
2417
|
-
const widths = cells.map((char) => Bun.stringWidth(char));
|
|
2418
|
-
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
2419
|
-
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
2420
|
-
let start = at;
|
|
2421
|
-
let end = at + 1;
|
|
2422
|
-
while (start > 0 && fits(start - 1, end))
|
|
2423
|
-
start--;
|
|
2424
|
-
while (end < cells.length && fits(start, end + 1))
|
|
2425
|
-
end++;
|
|
2426
|
-
const left = start > 0 ? "\u2026" : "";
|
|
2427
|
-
const right = end < cells.length ? "\u2026" : "";
|
|
2428
|
-
return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
|
|
2832
|
+
return 1;
|
|
2429
2833
|
}
|
|
2430
2834
|
|
|
2431
|
-
//
|
|
2432
|
-
|
|
2433
|
-
var
|
|
2835
|
+
// src/commands/compare.ts
|
|
2836
|
+
import process19 from "process";
|
|
2837
|
+
var diffUsage = `ev diff <a> <b>
|
|
2434
2838
|
|
|
2435
|
-
|
|
2436
|
-
var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
2437
|
-
var PASTE_START = "\x1B[200~";
|
|
2438
|
-
var PASTE_END = "\x1B[201~";
|
|
2439
|
-
var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
2440
|
-
var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
2441
|
-
var WHEEL_LINES = 3;
|
|
2442
|
-
var KEYS = {
|
|
2443
|
-
"\x1B[A": "up",
|
|
2444
|
-
"\x1BOA": "up",
|
|
2445
|
-
"\x10": "up",
|
|
2446
|
-
"\x1B[B": "down",
|
|
2447
|
-
"\x1BOB": "down",
|
|
2448
|
-
"\x0E": "down",
|
|
2449
|
-
"\x1B[5~": "pageup",
|
|
2450
|
-
"\x1B[6~": "pagedown",
|
|
2451
|
-
"\x1B[H": "home",
|
|
2452
|
-
"\x1B[1~": "home",
|
|
2453
|
-
"\x1BOH": "home",
|
|
2454
|
-
"\x1B[F": "end",
|
|
2455
|
-
"\x1B[4~": "end",
|
|
2456
|
-
"\x1BOF": "end",
|
|
2457
|
-
"\r": "enter",
|
|
2458
|
-
"\n": "enter",
|
|
2459
|
-
"\x03": "cancel",
|
|
2460
|
-
"\x1B": "cancel",
|
|
2461
|
-
"\x1B[D": "left",
|
|
2462
|
-
"\x1BOD": "left",
|
|
2463
|
-
"\x1B[C": "right",
|
|
2464
|
-
"\x1BOC": "right",
|
|
2465
|
-
"\x1B[1;5D": "wordleft",
|
|
2466
|
-
"\x1B[1;3D": "wordleft",
|
|
2467
|
-
"\x1Bb": "wordleft",
|
|
2468
|
-
"\x1B[1;5C": "wordright",
|
|
2469
|
-
"\x1B[1;3C": "wordright",
|
|
2470
|
-
"\x1Bf": "wordright",
|
|
2471
|
-
"\x01": "linestart",
|
|
2472
|
-
"\x05": "lineend",
|
|
2473
|
-
"\x7F": "erase",
|
|
2474
|
-
"\x1B[3~": "delete",
|
|
2475
|
-
"\b": "killword",
|
|
2476
|
-
"\x1B\x7F": "killword",
|
|
2477
|
-
"\x1B[3;5~": "killnext",
|
|
2478
|
-
"\x1Bd": "killnext",
|
|
2479
|
-
"\x15": "clear",
|
|
2480
|
-
"\v": "killend",
|
|
2481
|
-
"\x17": "word",
|
|
2482
|
-
"\x19": "yank",
|
|
2483
|
-
"\x1A": "suspend",
|
|
2484
|
-
"\t": "tab",
|
|
2485
|
-
"\x1F": "help",
|
|
2486
|
-
"\x1BOP": "help",
|
|
2487
|
-
"\x1B[11~": "help"
|
|
2488
|
-
};
|
|
2489
|
-
function repeat(value, count) {
|
|
2490
|
-
return Array.from({ length: count }).fill(value);
|
|
2491
|
-
}
|
|
2492
|
-
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
2493
|
-
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
2494
|
-
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
2495
|
-
const wheel = MOUSE.exec(sequence)?.[1];
|
|
2496
|
-
if (wheel !== undefined)
|
|
2497
|
-
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
2498
|
-
const named = codes.get(sequence);
|
|
2499
|
-
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
2500
|
-
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
2501
|
-
paste.active = sequence === PASTE_START;
|
|
2502
|
-
return [];
|
|
2503
|
-
}
|
|
2504
|
-
if (paste.active && (sequence === "\r" || sequence === `
|
|
2505
|
-
`))
|
|
2506
|
-
return [];
|
|
2507
|
-
if (key !== undefined)
|
|
2508
|
-
return [key];
|
|
2509
|
-
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
2510
|
-
});
|
|
2511
|
-
}
|
|
2839
|
+
Names the keys set in one file and not the other, never their values.
|
|
2512
2840
|
|
|
2513
|
-
|
|
2514
|
-
var
|
|
2515
|
-
var
|
|
2516
|
-
function overwrite(lines, columns) {
|
|
2517
|
-
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
2518
|
-
`);
|
|
2519
|
-
}
|
|
2520
|
-
function rowsTaken(lines, columns) {
|
|
2521
|
-
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
2522
|
-
}
|
|
2841
|
+
--json prints {a, b, onlyA, onlyB}.`;
|
|
2842
|
+
var DIFF_EXITS = [[0, "both set the same keys"], [1, "they differ"], [2, "a usage error"]];
|
|
2843
|
+
var missingUsage = `ev missing [file]
|
|
2523
2844
|
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
|
|
2532
|
-
}
|
|
2533
|
-
function withCaret(colors, line, room, dim = false) {
|
|
2534
|
-
const { before, at, after } = visible(line, room);
|
|
2535
|
-
const tone = dim ? colors.dim : (text) => text;
|
|
2536
|
-
return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
|
|
2845
|
+
Names the keys the reference file sets that the file (.env by default) does not.
|
|
2846
|
+
|
|
2847
|
+
--json prints {a, b, onlyA, onlyB} with the reference as a, so onlyA is what is missing.`;
|
|
2848
|
+
var MISSING_EXITS = [[0, "none is missing"], [1, "some are"], [2, "a usage error"]];
|
|
2849
|
+
var jsonFlag = { json: jsonOption() };
|
|
2850
|
+
async function keys(path) {
|
|
2851
|
+
return new Set(entries(await readEnv(path)).keys());
|
|
2537
2852
|
}
|
|
2538
|
-
function
|
|
2539
|
-
const
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2853
|
+
async function diff(args) {
|
|
2854
|
+
const parsed = parse(args, diffUsage, jsonFlag, { exits: DIFF_EXITS });
|
|
2855
|
+
const [a, b] = parsed.positionals;
|
|
2856
|
+
if (a === undefined || b === undefined)
|
|
2857
|
+
fail(`needs two files
|
|
2858
|
+
|
|
2859
|
+
${diffUsage}`);
|
|
2860
|
+
const left = await keys(a);
|
|
2861
|
+
const right = await keys(b);
|
|
2862
|
+
const onlyA = [...left].filter((key) => !right.has(key));
|
|
2863
|
+
const onlyB = [...right].filter((key) => !left.has(key));
|
|
2864
|
+
if (parsed.values.json === true) {
|
|
2865
|
+
printJson({ a, b, onlyA, onlyB });
|
|
2866
|
+
return onlyA.length + onlyB.length === 0 ? 0 : 1;
|
|
2544
2867
|
}
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
return
|
|
2553
|
-
}
|
|
2554
|
-
async function input2(question, { default: fallback, mask = false, validate, history, complete, ...settings } = {}) {
|
|
2555
|
-
let line = { text: "", caret: 0 };
|
|
2556
|
-
let invalid;
|
|
2557
|
-
let completions = [];
|
|
2558
|
-
const remembered = history === undefined || mask ? undefined : history;
|
|
2559
|
-
const earlier = remembered === undefined ? [] : earlierAnswers(remembered);
|
|
2560
|
-
let recalled = -1;
|
|
2561
|
-
let draft = line;
|
|
2562
|
-
const taken = () => line.text === "" ? fallback ?? "" : line.text;
|
|
2563
|
-
const shown = () => mask ? "*".repeat([...taken()].length) : taken();
|
|
2564
|
-
const accepted = await ask(question, settings, (colors, state, { columns }) => {
|
|
2565
|
-
if (state !== "asking")
|
|
2566
|
-
return [answer(colors, question, state, shown())];
|
|
2567
|
-
const typed = line.text === "" ? { text: shown(), caret: [...shown()].length } : { text: shown(), caret: line.caret };
|
|
2568
|
-
return [`${colors.cyan("?")} ${question} ${withCaret(colors, typed, roomAfter(question, columns), line.text === "")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`], ...completions.length > 1 ? [listed2(colors, completions, columns)] : []];
|
|
2569
|
-
}, (key) => {
|
|
2570
|
-
if (key === "cancel")
|
|
2571
|
-
return "cancel";
|
|
2572
|
-
invalid = undefined;
|
|
2573
|
-
completions = [];
|
|
2574
|
-
if (line.chained === true && endsKills(key))
|
|
2575
|
-
line = { ...line, chained: false };
|
|
2576
|
-
if (key === "tab") {
|
|
2577
|
-
const chars = [...line.text];
|
|
2578
|
-
const before = chars.slice(0, line.caret).join("");
|
|
2579
|
-
const found = complete?.(before) ?? [];
|
|
2580
|
-
const filled = sharedStart(found);
|
|
2581
|
-
if ([...filled].length > [...before].length)
|
|
2582
|
-
line = { ...line, text: filled + chars.slice(line.caret).join(""), caret: [...filled].length };
|
|
2583
|
-
else
|
|
2584
|
-
completions = found;
|
|
2585
|
-
return;
|
|
2586
|
-
}
|
|
2587
|
-
if (key === "enter") {
|
|
2588
|
-
invalid = validate?.(taken());
|
|
2589
|
-
return invalid === undefined ? "enter" : undefined;
|
|
2590
|
-
}
|
|
2591
|
-
if (key === "up" || key === "down") {
|
|
2592
|
-
const to = Math.min(Math.max(recalled + (key === "up" ? 1 : -1), -1), earlier.length - 1);
|
|
2593
|
-
if (recalled === -1)
|
|
2594
|
-
draft = line;
|
|
2595
|
-
recalled = to;
|
|
2596
|
-
const shown = to === -1 ? draft : { text: earlier[to], caret: [...earlier[to]].length };
|
|
2597
|
-
line = { ...shown, killed: line.killed ?? "" };
|
|
2598
|
-
return;
|
|
2599
|
-
}
|
|
2600
|
-
const edit = { home: "linestart", end: "lineend" }[key] ?? key;
|
|
2601
|
-
if (typeof edit === "object" || isEditKey(edit))
|
|
2602
|
-
line = editLine(line, edit);
|
|
2603
|
-
return;
|
|
2604
|
-
});
|
|
2605
|
-
if (!accepted)
|
|
2606
|
-
return;
|
|
2607
|
-
if (remembered !== undefined && taken() !== "")
|
|
2608
|
-
rememberAnswer(remembered, taken());
|
|
2609
|
-
return taken();
|
|
2610
|
-
}
|
|
2611
|
-
function answer(colors, question, state, picked) {
|
|
2612
|
-
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
2868
|
+
const path = role("path", process19.stdout);
|
|
2869
|
+
const value = role("value", process19.stdout);
|
|
2870
|
+
const lines = [...onlyA.map((key) => `only in ${path(a)}: ${value(key)}`), ...onlyB.map((key) => `only in ${path(b)}: ${value(key)}`)];
|
|
2871
|
+
if (lines.length === 0)
|
|
2872
|
+
return 0;
|
|
2873
|
+
console.log(lines.join(`
|
|
2874
|
+
`));
|
|
2875
|
+
return 1;
|
|
2613
2876
|
}
|
|
2614
|
-
async function
|
|
2615
|
-
const {
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
const
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
const rows = rowsTaken(frame, columns());
|
|
2625
|
-
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
2626
|
-
current = state;
|
|
2627
|
-
};
|
|
2628
|
-
const redraw = () => draw(current);
|
|
2629
|
-
const paste = { active: false };
|
|
2630
|
-
const stop = terminal.stop ?? (terminal === process20 ? stopJob : undefined);
|
|
2631
|
-
const suspend = () => {
|
|
2632
|
-
if (stop === undefined)
|
|
2633
|
-
return;
|
|
2634
|
-
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
2635
|
-
stdin.setRawMode(false);
|
|
2636
|
-
stop();
|
|
2637
|
-
stdin.setRawMode(true);
|
|
2638
|
-
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
2639
|
-
};
|
|
2640
|
-
try {
|
|
2641
|
-
stderr.on?.("resize", redraw);
|
|
2642
|
-
stdin.setRawMode(true);
|
|
2643
|
-
stdin.resume();
|
|
2644
|
-
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
2645
|
-
draw("asking");
|
|
2646
|
-
return await new Promise((resolve) => {
|
|
2647
|
-
function onData(data) {
|
|
2648
|
-
for (const key of readKeys(data.toString(), paste)) {
|
|
2649
|
-
if (key === "suspend") {
|
|
2650
|
-
suspend();
|
|
2651
|
-
continue;
|
|
2652
|
-
}
|
|
2653
|
-
const pressed = press(key);
|
|
2654
|
-
if (pressed !== undefined) {
|
|
2655
|
-
settle(pressed);
|
|
2656
|
-
return;
|
|
2657
|
-
}
|
|
2658
|
-
}
|
|
2659
|
-
draw("asking");
|
|
2660
|
-
}
|
|
2661
|
-
function onEnd() {
|
|
2662
|
-
settle("cancel");
|
|
2663
|
-
}
|
|
2664
|
-
function settle(settled) {
|
|
2665
|
-
outcome = settled;
|
|
2666
|
-
stdin.off("data", onData);
|
|
2667
|
-
stdin.off("end", onEnd);
|
|
2668
|
-
resolve(settled === "enter");
|
|
2669
|
-
}
|
|
2670
|
-
stdin.on("data", onData);
|
|
2671
|
-
stdin.on("end", onEnd);
|
|
2672
|
-
});
|
|
2673
|
-
} finally {
|
|
2674
|
-
stderr.off?.("resize", redraw);
|
|
2675
|
-
draw(outcome ?? "cancel", true);
|
|
2676
|
-
stderr.write(`
|
|
2677
|
-
\x1B[?25h\x1B[?2004l`);
|
|
2678
|
-
stdin.setRawMode(false);
|
|
2679
|
-
stdin.pause();
|
|
2877
|
+
async function missing(args) {
|
|
2878
|
+
const parsed = parse(args, missingUsage, { against: { type: "string", description: "the reference file (.env.example by default)" }, ...jsonFlag }, { exits: MISSING_EXITS });
|
|
2879
|
+
const [file = ".env"] = parsed.positionals;
|
|
2880
|
+
const against = parsed.values.against ?? ".env.example";
|
|
2881
|
+
const have = await keys(file);
|
|
2882
|
+
const reference = await keys(against);
|
|
2883
|
+
const absent = [...reference].filter((key) => !have.has(key));
|
|
2884
|
+
if (parsed.values.json === true) {
|
|
2885
|
+
printJson({ a: against, b: file, onlyA: absent, onlyB: [...have].filter((key) => !reference.has(key)) });
|
|
2886
|
+
return absent.length === 0 ? 0 : 1;
|
|
2680
2887
|
}
|
|
2888
|
+
if (absent.length === 0)
|
|
2889
|
+
return 0;
|
|
2890
|
+
const path = role("path", process19.stdout);
|
|
2891
|
+
const value = role("value", process19.stdout);
|
|
2892
|
+
console.log(absent.map((key) => `${value(key)} (set in ${path(against)}, not in ${path(file)})`).join(`
|
|
2893
|
+
`));
|
|
2894
|
+
return 1;
|
|
2681
2895
|
}
|
|
2682
2896
|
|
|
2683
2897
|
// src/commands/edit.ts
|
|
2898
|
+
init_prompt();
|
|
2684
2899
|
var DEFAULT_FILE = ".env";
|
|
2685
2900
|
var TRAILING_NEWLINE = /\r?\n$/;
|
|
2686
2901
|
var KEY_NAME = /^[A-Z_][\w.-]*$/i;
|
|
@@ -2712,6 +2927,7 @@ function checkKey(key) {
|
|
|
2712
2927
|
badUsage(`${JSON.stringify(key)} is not a valid key: letters, digits, _, . and - only, not starting with a digit`);
|
|
2713
2928
|
}
|
|
2714
2929
|
async function readOrEmpty(path) {
|
|
2930
|
+
assertDotenvName(path);
|
|
2715
2931
|
return await Bun.file(path).exists() ? readEnv(path) : { lines: [] };
|
|
2716
2932
|
}
|
|
2717
2933
|
async function set(args) {
|
|
@@ -3000,10 +3216,8 @@ async function checkApp(folder, except = new Set) {
|
|
|
3000
3216
|
var usage3 = `ev pins [dir] [--except NAME,...]
|
|
3001
3217
|
|
|
3002
3218
|
Checks that an app's tests pin the env that reaches outside.
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
The dir is an app, or a monorepo holding apps one level down (the current folder by default).
|
|
3006
|
-
Reads variable names only, never a value.`;
|
|
3219
|
+
Lists the optional URL, key, token, secret, password and host variables of the app's \`defineEnv\` schema that no \`.env.test\` entry, \`overrideEnv\` or bunfig preload pins, and each test file calling \`testSite\` or \`proxyKeyTests\` without pinning them all; a file reaching none says so with a \`// ev pins: none reached, <why>\` comment.
|
|
3220
|
+
The dir is an app, or a monorepo holding apps one level down (the current folder by default). It reads variable names only, never a value.`;
|
|
3007
3221
|
var EXITS2 = [[0, "everything is pinned"], [1, "something is not"], [2, "a usage error"]];
|
|
3008
3222
|
var options2 = {
|
|
3009
3223
|
json: jsonOption("each app with its reaching, unpinned variables and flagged test files"),
|
|
@@ -3069,7 +3283,7 @@ async function pins(args) {
|
|
|
3069
3283
|
var {$: $2 } = globalThis.Bun;
|
|
3070
3284
|
var listUsage = `ev list [file]
|
|
3071
3285
|
|
|
3072
|
-
Prints every key of the folder's .env* files, or of one file, with secret values masked
|
|
3286
|
+
Prints every key of the folder's .env* files, or of one file, with secret values masked to a few leading characters and the length.
|
|
3073
3287
|
|
|
3074
3288
|
--json prints [{file, key, value, secret}], value masked and secret true when a value was.`;
|
|
3075
3289
|
var LIST_EXITS = [[0, "it printed them"], [1, "there is no .env* file"], [2, "a usage error"]];
|
|
@@ -3104,10 +3318,10 @@ function printRows(rows, json, plain) {
|
|
|
3104
3318
|
else
|
|
3105
3319
|
plain();
|
|
3106
3320
|
}
|
|
3107
|
-
async function readAll(names) {
|
|
3321
|
+
async function readAll(names, scanned) {
|
|
3108
3322
|
const files = [];
|
|
3109
3323
|
for (const name of names)
|
|
3110
|
-
files.push([name, await readEnv(name)]);
|
|
3324
|
+
files.push([name, await readEnv(name, { scanned })]);
|
|
3111
3325
|
return { files, known: await loadKnown(process.cwd(), files.map(([, file]) => file)) };
|
|
3112
3326
|
}
|
|
3113
3327
|
async function list(args) {
|
|
@@ -3117,7 +3331,7 @@ async function list(args) {
|
|
|
3117
3331
|
if (names.length === 0)
|
|
3118
3332
|
fail("no .env* file in this folder", 1);
|
|
3119
3333
|
const rows = [];
|
|
3120
|
-
const { files, known } = await readAll(names);
|
|
3334
|
+
const { files, known } = await readAll(names, file === undefined);
|
|
3121
3335
|
for (const [name, file] of files) {
|
|
3122
3336
|
for (const [key, value] of entries(file))
|
|
3123
3337
|
rows.push(row(name, key, value, known));
|
|
@@ -3137,7 +3351,7 @@ async function get(args) {
|
|
|
3137
3351
|
${getUsage}`);
|
|
3138
3352
|
const names = file === undefined ? await envFiles() : [file];
|
|
3139
3353
|
const rows = [];
|
|
3140
|
-
const { files, known } = await readAll(names);
|
|
3354
|
+
const { files, known } = await readAll(names, file === undefined);
|
|
3141
3355
|
for (const [name, file] of files) {
|
|
3142
3356
|
const value = entries(file).get(key);
|
|
3143
3357
|
if (value !== undefined)
|
|
@@ -3176,7 +3390,7 @@ ${grepUsage}`);
|
|
|
3176
3390
|
}
|
|
3177
3391
|
const names = given.length === 0 ? await envFiles() : given;
|
|
3178
3392
|
const rows = [];
|
|
3179
|
-
const { files, known } = await readAll(names);
|
|
3393
|
+
const { files, known } = await readAll(names, given.length === 0);
|
|
3180
3394
|
for (const [name, file] of files) {
|
|
3181
3395
|
for (const [key, value] of entries(file)) {
|
|
3182
3396
|
if (pattern.test(key))
|
|
@@ -3198,10 +3412,13 @@ async function show(args) {
|
|
|
3198
3412
|
${showUsage}`);
|
|
3199
3413
|
if (revision.startsWith("-"))
|
|
3200
3414
|
fail(`${revision} is not a revision: it reads as a git option`);
|
|
3415
|
+
const redact = `git show ${revision}:${path} | ev redact`;
|
|
3416
|
+
assertDotenvName(path, redact);
|
|
3201
3417
|
const shown = await $2`git show --end-of-options ${`${revision}:${path}`}`.quiet().nothrow();
|
|
3202
3418
|
if (shown.exitCode !== 0)
|
|
3203
3419
|
fail(`git show ${revision}:${path} failed: ${shown.stderr.toString().trim()}`, 1);
|
|
3204
3420
|
const file = parseDotenv(shown.stdout.toString());
|
|
3421
|
+
assertDotenvText(target ?? "", file, redact);
|
|
3205
3422
|
const known = await loadKnown(process.cwd(), [file]);
|
|
3206
3423
|
const rows = [...entries(file)].map(([key, value]) => row(target ?? "", key, value, known));
|
|
3207
3424
|
printRows(rows, parsed.values.json === true, () => {
|
|
@@ -3212,7 +3429,7 @@ ${showUsage}`);
|
|
|
3212
3429
|
}
|
|
3213
3430
|
|
|
3214
3431
|
// src/commands/redact.ts
|
|
3215
|
-
import
|
|
3432
|
+
import process22 from "process";
|
|
3216
3433
|
|
|
3217
3434
|
// src/redactor.ts
|
|
3218
3435
|
var DIFF_START = /^(?:diff --git |@@ )/;
|
|
@@ -3330,17 +3547,17 @@ function check(text, known) {
|
|
|
3330
3547
|
}
|
|
3331
3548
|
|
|
3332
3549
|
// src/commands/redact.ts
|
|
3333
|
-
var usage4 = `redact [--check]
|
|
3550
|
+
var usage4 = `ev redact [--check]
|
|
3334
3551
|
|
|
3335
|
-
Copies stdin to stdout line by line with secrets masked: known token formats
|
|
3336
|
-
--check prints nothing of the input and lists the file and line of each secret found, exiting 1 when there is any: \`git diff --cached | redact --check\`.`;
|
|
3552
|
+
Copies stdin to stdout line by line with secrets masked: known token formats, private key blocks, the password and tokens of any URL and the values of secret-looking keys in this folder's .env* files.
|
|
3553
|
+
--check prints nothing of the input and lists the file and line of each secret found, exiting 1 when there is any: \`git diff --cached | ev redact --check\`.`;
|
|
3337
3554
|
var EXITS3 = [[0, "it copied the input or found no secret"], [1, "--check finds one"], [2, "a usage error"]];
|
|
3338
3555
|
var options3 = {
|
|
3339
3556
|
check: { type: "boolean", description: "list where secrets are instead of masking them, exit 1 when found" },
|
|
3340
3557
|
"no-env": { type: "boolean", description: "do not search for the values of the .env* files" }
|
|
3341
3558
|
};
|
|
3342
3559
|
async function redact(args) {
|
|
3343
|
-
const parsed = parse(args, usage4, options3, { exits: EXITS3, replaces: "printing a command's secrets into a log or a transcript", examples: [["docker compose config | redact", "the resolved compose file, secrets masked"], ["git diff --cached | redact --check", "refuse a commit carrying a secret"]] });
|
|
3560
|
+
const parsed = parse(args, usage4, options3, { exits: EXITS3, replaces: "printing a command's secrets into a log or a transcript", examples: [["docker compose config | ev redact", "the resolved compose file, secrets masked"], ["git diff --cached | ev redact --check", "refuse a commit carrying a secret"]] });
|
|
3344
3561
|
const known = parsed.values["no-env"] === true ? undefined : await loadKnown();
|
|
3345
3562
|
if (parsed.values.check === true) {
|
|
3346
3563
|
const findings = check(await readInput("-"), known);
|
|
@@ -3351,13 +3568,13 @@ async function redact(args) {
|
|
|
3351
3568
|
const redactor = new Redactor(known);
|
|
3352
3569
|
const decoder = new TextDecoder;
|
|
3353
3570
|
for await (const chunk of Bun.stdin.stream())
|
|
3354
|
-
|
|
3355
|
-
|
|
3571
|
+
process22.stdout.write(redactor.push(decoder.decode(chunk, { stream: true })));
|
|
3572
|
+
process22.stdout.write(redactor.push(decoder.decode()) + redactor.end());
|
|
3356
3573
|
return 0;
|
|
3357
3574
|
}
|
|
3358
3575
|
|
|
3359
3576
|
// src/ev.ts
|
|
3360
|
-
|
|
3577
|
+
process23.exitCode = await runCli({
|
|
3361
3578
|
name: "ev",
|
|
3362
3579
|
about: ".env files listed and edited with secrets masked",
|
|
3363
3580
|
replaces: "cat .env, grep on env files and editing them by hand",
|