@kaynooo/cli-env 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ev.js +291 -95
- package/dist/redact.js +256 -69
- package/package.json +1 -1
- package/src/commands/read.ts +18 -4
package/dist/ev.js
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/ev.ts
|
|
5
|
-
import
|
|
5
|
+
import process15 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
|
-
import
|
|
7
|
+
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
9
9
|
|
|
10
10
|
// ../kit/src/format.ts
|
|
11
|
-
import
|
|
11
|
+
import process6 from "process";
|
|
12
12
|
|
|
13
13
|
// ../kit/src/style.ts
|
|
14
|
-
import
|
|
14
|
+
import process5 from "process";
|
|
15
15
|
|
|
16
16
|
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
17
17
|
function x(s) {
|
|
@@ -274,36 +274,222 @@ function le(i = {}) {
|
|
|
274
274
|
}
|
|
275
275
|
var t = le();
|
|
276
276
|
|
|
277
|
-
// ../kit/src/
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
277
|
+
// ../kit/src/theme.ts
|
|
278
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
279
|
+
import { homedir as homedir2 } from "os";
|
|
280
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
281
|
+
import process4 from "process";
|
|
282
|
+
|
|
283
|
+
// ../kit/src/config.ts
|
|
284
|
+
import { existsSync } from "fs";
|
|
285
|
+
import { dirname, join, resolve } from "path";
|
|
286
|
+
import process2 from "process";
|
|
287
|
+
function findUp(names, from = process2.cwd(), stop = () => false) {
|
|
288
|
+
const wanted = typeof names === "string" ? [names] : names;
|
|
289
|
+
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
290
|
+
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
291
|
+
if (found !== undefined)
|
|
292
|
+
return found;
|
|
293
|
+
if (stop(dir) || dirname(dir) === dir)
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// ../kit/src/user-config.ts
|
|
299
|
+
import { homedir } from "os";
|
|
300
|
+
import { join as join2 } from "path";
|
|
301
|
+
import process3 from "process";
|
|
302
|
+
function configBase(where = {}) {
|
|
303
|
+
const xdg = where.xdg ?? (where.home === undefined ? process3.env.XDG_CONFIG_HOME : undefined);
|
|
304
|
+
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
305
|
+
}
|
|
306
|
+
function userConfigPath(bin, where = {}) {
|
|
307
|
+
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// ../kit/src/theme.ts
|
|
311
|
+
var DEFAULT = {
|
|
312
|
+
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
313
|
+
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501" },
|
|
314
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
315
|
+
bins: {}
|
|
283
316
|
};
|
|
284
|
-
|
|
317
|
+
var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
318
|
+
var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
319
|
+
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#" };
|
|
320
|
+
var PRESETS = {
|
|
321
|
+
default: {},
|
|
322
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"] },
|
|
323
|
+
mono: { colors: MONO, accents: ["bold"] },
|
|
324
|
+
ascii: { glyphs: ASCII }
|
|
325
|
+
};
|
|
326
|
+
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"]);
|
|
327
|
+
var HEX = /^#[0-9a-f]{6}$/i;
|
|
328
|
+
var CONTROL = /\p{Cc}/u;
|
|
329
|
+
var MAX_FILE_BYTES = 64 * 1024;
|
|
330
|
+
var SPACES = /\s+/;
|
|
331
|
+
function isColorSpec(spec) {
|
|
332
|
+
if (typeof spec === "number")
|
|
333
|
+
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
334
|
+
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
335
|
+
}
|
|
336
|
+
function tinted(colors, spec) {
|
|
337
|
+
if (typeof spec === "number")
|
|
338
|
+
return colors.ansi256(spec);
|
|
339
|
+
return spec.trim().split(SPACES).reduce((chain, token) => HEX.test(token) ? chain.hex(token) : chain[token] ?? chain, colors);
|
|
340
|
+
}
|
|
341
|
+
function isRecord(value) {
|
|
342
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
343
|
+
}
|
|
344
|
+
function readThemeFile(path, warn) {
|
|
345
|
+
try {
|
|
346
|
+
const stat = statSync(path, { throwIfNoEntry: false });
|
|
347
|
+
if (stat === undefined)
|
|
348
|
+
return;
|
|
349
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
350
|
+
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
354
|
+
if (isRecord(parsed))
|
|
355
|
+
return parsed;
|
|
356
|
+
warn(`${path} is not a JSON object, theme ignored`);
|
|
357
|
+
} catch (error) {
|
|
358
|
+
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
359
|
+
}
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
function applyPreset(theme, name, warn, where) {
|
|
363
|
+
if (name === undefined)
|
|
364
|
+
return;
|
|
365
|
+
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
366
|
+
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const preset = PRESETS[name];
|
|
370
|
+
Object.assign(theme.colors, preset.colors);
|
|
371
|
+
Object.assign(theme.glyphs, preset.glyphs);
|
|
372
|
+
if (preset.accents !== undefined)
|
|
373
|
+
theme.accents = [...preset.accents];
|
|
374
|
+
return name;
|
|
375
|
+
}
|
|
376
|
+
function applyFile(theme, file, where, warn) {
|
|
377
|
+
if (isRecord(file.colors)) {
|
|
378
|
+
for (const [key, value] of Object.entries(file.colors)) {
|
|
379
|
+
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
380
|
+
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
381
|
+
else if (!isColorSpec(value))
|
|
382
|
+
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
383
|
+
else
|
|
384
|
+
theme.colors[key] = value;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
if (isRecord(file.glyphs)) {
|
|
388
|
+
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
389
|
+
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
390
|
+
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
391
|
+
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
392
|
+
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
393
|
+
else
|
|
394
|
+
theme.glyphs[key] = value;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
398
|
+
theme.accents = [...file.accents];
|
|
399
|
+
else if (file.accents !== undefined)
|
|
400
|
+
warn(`${where}: accents must be a non-empty list of colours`);
|
|
401
|
+
if (isRecord(file.bins)) {
|
|
402
|
+
for (const [bin, value] of Object.entries(file.bins)) {
|
|
403
|
+
if (isColorSpec(value))
|
|
404
|
+
theme.bins[bin] = value;
|
|
405
|
+
else
|
|
406
|
+
warn(`${where}: bin ${bin} has no valid colour`);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
function endsWalk(home) {
|
|
411
|
+
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
412
|
+
}
|
|
413
|
+
var warned = new Set;
|
|
414
|
+
function warnOnce(message) {
|
|
415
|
+
if (warned.has(message))
|
|
416
|
+
return;
|
|
417
|
+
warned.add(message);
|
|
418
|
+
console.error(`warning: theme ${message}`);
|
|
419
|
+
}
|
|
420
|
+
function isPath(chosen) {
|
|
421
|
+
return chosen.includes("/") || chosen.endsWith(".json");
|
|
422
|
+
}
|
|
423
|
+
function loadTheme({ env = process4.env, from = process4.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
424
|
+
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null) };
|
|
425
|
+
const sources = [];
|
|
426
|
+
const chosen = env.KIT_THEME ?? "";
|
|
427
|
+
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
428
|
+
if (isPath(chosen))
|
|
429
|
+
wanted.push(resolve2(from, chosen));
|
|
430
|
+
const files = [];
|
|
431
|
+
for (const path of wanted) {
|
|
432
|
+
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
433
|
+
if (path !== undefined && file !== undefined)
|
|
434
|
+
files.push({ path, file });
|
|
435
|
+
}
|
|
436
|
+
let preset = "default";
|
|
437
|
+
if (chosen !== "" && !isPath(chosen)) {
|
|
438
|
+
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
439
|
+
} else {
|
|
440
|
+
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
441
|
+
if (named !== undefined)
|
|
442
|
+
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
443
|
+
}
|
|
444
|
+
for (const { path, file } of files) {
|
|
445
|
+
applyFile(theme, file, path, warn);
|
|
446
|
+
sources.push(path);
|
|
447
|
+
}
|
|
448
|
+
return { theme, sources, preset };
|
|
449
|
+
}
|
|
450
|
+
var current;
|
|
451
|
+
var currentKey = "";
|
|
452
|
+
function activeTheme() {
|
|
453
|
+
const key = `${process4.cwd()}\x00${process4.env.KIT_THEME ?? ""}\x00${process4.env.XDG_CONFIG_HOME ?? ""}`;
|
|
454
|
+
if (current === undefined || key !== currentKey) {
|
|
455
|
+
current = loadTheme();
|
|
456
|
+
currentKey = key;
|
|
457
|
+
}
|
|
458
|
+
return current;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// ../kit/src/style.ts
|
|
462
|
+
var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:" };
|
|
463
|
+
function takesControlCodes(stream, env = process5.env) {
|
|
285
464
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
286
465
|
}
|
|
287
|
-
function paint(stream, env =
|
|
466
|
+
function paint(stream, env = process5.env) {
|
|
288
467
|
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
289
468
|
}
|
|
290
|
-
function marked(mark, text, stream, detail, env =
|
|
469
|
+
function marked(mark, text, stream, detail, env = process5.env) {
|
|
291
470
|
const colors = paint(stream, env);
|
|
292
|
-
|
|
293
|
-
|
|
471
|
+
let head = MARK_WORDS[mark];
|
|
472
|
+
if (takesControlCodes(stream, env)) {
|
|
473
|
+
const { theme } = activeTheme();
|
|
474
|
+
head = tinted(colors.bold, theme.colors[mark])(theme.glyphs[mark]);
|
|
475
|
+
}
|
|
294
476
|
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
295
477
|
}
|
|
296
478
|
function ok(text, detail) {
|
|
297
|
-
console.log(marked("ok", text,
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
479
|
+
console.log(marked("ok", text, process5.stdout, detail));
|
|
480
|
+
}
|
|
481
|
+
function role(name, stream, env = process5.env) {
|
|
482
|
+
const colors = paint(stream, env);
|
|
483
|
+
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name]) : colors;
|
|
484
|
+
}
|
|
485
|
+
var STATUS_WORDS = {
|
|
486
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
487
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
488
|
+
running: ["running", "in_progress", "started"],
|
|
489
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
490
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
305
491
|
};
|
|
306
|
-
var STATUS_OF = new Map(Object.entries(
|
|
492
|
+
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
307
493
|
|
|
308
494
|
// ../kit/src/format.ts
|
|
309
495
|
function upTo(text, separator) {
|
|
@@ -318,7 +504,7 @@ var ESCAPE = String.fromCharCode(27);
|
|
|
318
504
|
function textWidth(text) {
|
|
319
505
|
return Bun.stringWidth(text);
|
|
320
506
|
}
|
|
321
|
-
function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
507
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process6.stdout } = {}) {
|
|
322
508
|
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
323
509
|
const widths = [];
|
|
324
510
|
for (const row of cells) {
|
|
@@ -326,7 +512,7 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
|
326
512
|
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
327
513
|
}
|
|
328
514
|
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
329
|
-
const colors = paint(
|
|
515
|
+
const colors = paint(stream);
|
|
330
516
|
const lines = shown.map((row) => row.map((cell, index) => {
|
|
331
517
|
const width = widths[index] ?? 0;
|
|
332
518
|
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
@@ -334,7 +520,8 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
|
334
520
|
return `${gap}${cell}`;
|
|
335
521
|
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
336
522
|
}).join(" ").trimEnd());
|
|
337
|
-
|
|
523
|
+
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
524
|
+
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
338
525
|
`);
|
|
339
526
|
}
|
|
340
527
|
function narrow(rows, widths, limit) {
|
|
@@ -358,27 +545,27 @@ function printJson(value) {
|
|
|
358
545
|
}
|
|
359
546
|
|
|
360
547
|
// ../kit/src/help.ts
|
|
361
|
-
import
|
|
548
|
+
import process7 from "process";
|
|
362
549
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
363
550
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
364
551
|
var FULL_STOP = /\.$/;
|
|
365
|
-
function usageLine(usage, colors = paint(
|
|
552
|
+
function usageLine(usage, colors = paint(process7.stdout)) {
|
|
366
553
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
367
554
|
}
|
|
368
|
-
function helpText(usage, options, colors = paint(
|
|
555
|
+
function helpText(usage, options, colors = paint(process7.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
369
556
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
370
557
|
`);
|
|
371
558
|
}
|
|
372
|
-
function exitRows(exits, colors = paint(
|
|
559
|
+
function exitRows(exits, colors = paint(process7.stdout)) {
|
|
373
560
|
if (exits.length === 0)
|
|
374
561
|
return [];
|
|
375
562
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
376
563
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
377
564
|
}
|
|
378
|
-
function replacesRows(replaces, colors = paint(
|
|
565
|
+
function replacesRows(replaces, colors = paint(process7.stdout)) {
|
|
379
566
|
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
380
567
|
}
|
|
381
|
-
function wantsHelpJson(env =
|
|
568
|
+
function wantsHelpJson(env = process7.env) {
|
|
382
569
|
return env.KIT_HELP === "json";
|
|
383
570
|
}
|
|
384
571
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -397,12 +584,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
397
584
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
398
585
|
};
|
|
399
586
|
}
|
|
400
|
-
function exampleRows(examples, colors = paint(
|
|
587
|
+
function exampleRows(examples, colors = paint(process7.stdout)) {
|
|
401
588
|
if (examples.length === 0)
|
|
402
589
|
return [];
|
|
403
590
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
404
591
|
}
|
|
405
|
-
function optionRows(options, colors = paint(
|
|
592
|
+
function optionRows(options, colors = paint(process7.stdout)) {
|
|
406
593
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
407
594
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
408
595
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -434,10 +621,10 @@ function closest(name, names) {
|
|
|
434
621
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
435
622
|
}
|
|
436
623
|
// ../kit/src/input.ts
|
|
437
|
-
import
|
|
624
|
+
import process8 from "process";
|
|
438
625
|
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
439
626
|
if (path === "-") {
|
|
440
|
-
if (
|
|
627
|
+
if (process8.stdin.isTTY)
|
|
441
628
|
fail(noStdin);
|
|
442
629
|
return Bun.stdin.text();
|
|
443
630
|
}
|
|
@@ -496,7 +683,7 @@ var OUTPUT_OPTIONS = {
|
|
|
496
683
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
497
684
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
498
685
|
};
|
|
499
|
-
function applyOutput(color, plain, env =
|
|
686
|
+
function applyOutput(color, plain, env = process9.env) {
|
|
500
687
|
const when = plain === true ? "never" : color ?? "auto";
|
|
501
688
|
if (when === "auto")
|
|
502
689
|
return;
|
|
@@ -671,15 +858,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
671
858
|
var RESET_STYLE = `${ESC}[0m`;
|
|
672
859
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
673
860
|
// ../kit/src/cli.ts
|
|
674
|
-
import { readFileSync, realpathSync } from "fs";
|
|
675
|
-
import { dirname as
|
|
676
|
-
import
|
|
861
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
862
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
863
|
+
import process11 from "process";
|
|
677
864
|
|
|
678
865
|
// ../kit/src/usage.ts
|
|
679
866
|
import { appendFileSync, mkdirSync } from "fs";
|
|
680
|
-
import { homedir } from "os";
|
|
681
|
-
import { dirname, isAbsolute, join } from "path";
|
|
682
|
-
import
|
|
867
|
+
import { homedir as homedir3 } from "os";
|
|
868
|
+
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
869
|
+
import process10 from "process";
|
|
683
870
|
|
|
684
871
|
// ../kit/src/logs.ts
|
|
685
872
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -693,14 +880,14 @@ var usageError;
|
|
|
693
880
|
function noteUsageError(message) {
|
|
694
881
|
usageError = message;
|
|
695
882
|
}
|
|
696
|
-
function stateHome(env =
|
|
883
|
+
function stateHome(env = process10.env) {
|
|
697
884
|
const dir = env.XDG_STATE_HOME;
|
|
698
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
885
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
699
886
|
}
|
|
700
|
-
function usagePath(env =
|
|
701
|
-
return
|
|
887
|
+
function usagePath(env = process10.env) {
|
|
888
|
+
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
702
889
|
}
|
|
703
|
-
function usageRecorded(env =
|
|
890
|
+
function usageRecorded(env = process10.env) {
|
|
704
891
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
705
892
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
706
893
|
}
|
|
@@ -714,12 +901,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
714
901
|
usageError = undefined;
|
|
715
902
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
716
903
|
}
|
|
717
|
-
function recordUsage(entry, env =
|
|
904
|
+
function recordUsage(entry, env = process10.env) {
|
|
718
905
|
if (!usageRecorded(env))
|
|
719
906
|
return;
|
|
720
907
|
try {
|
|
721
908
|
const path = usagePath(env);
|
|
722
|
-
mkdirSync(
|
|
909
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
723
910
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
724
911
|
`, { mode: 384 });
|
|
725
912
|
} catch {}
|
|
@@ -805,8 +992,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
805
992
|
`);
|
|
806
993
|
}
|
|
807
994
|
function printError(prefix, message, hint, cause) {
|
|
808
|
-
const colors = paint(
|
|
809
|
-
const styled = takesControlCodes(
|
|
995
|
+
const colors = paint(process11.stderr);
|
|
996
|
+
const styled = takesControlCodes(process11.stderr);
|
|
810
997
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
811
998
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
812
999
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -849,11 +1036,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
849
1036
|
}
|
|
850
1037
|
}
|
|
851
1038
|
if (name === undefined && level.path.length > 1) {
|
|
852
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1039
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process11.stderr));
|
|
853
1040
|
return 2;
|
|
854
1041
|
}
|
|
855
1042
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
856
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1043
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process11.stdout));
|
|
857
1044
|
return 0;
|
|
858
1045
|
}
|
|
859
1046
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -970,17 +1157,17 @@ async function printCandidates(found) {
|
|
|
970
1157
|
return 0;
|
|
971
1158
|
}
|
|
972
1159
|
function packageVersion(entry = Bun.main) {
|
|
973
|
-
for (let dir =
|
|
1160
|
+
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
974
1161
|
try {
|
|
975
|
-
const { version } = JSON.parse(
|
|
1162
|
+
const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
|
|
976
1163
|
if (typeof version === "string")
|
|
977
1164
|
return version;
|
|
978
1165
|
} catch {}
|
|
979
|
-
if (
|
|
1166
|
+
if (dirname3(dir) === dir)
|
|
980
1167
|
return "0.0.0";
|
|
981
1168
|
}
|
|
982
1169
|
}
|
|
983
|
-
async function runCli(cli, argv =
|
|
1170
|
+
async function runCli(cli, argv = process11.argv.slice(2)) {
|
|
984
1171
|
const version = cli.version ?? packageVersion();
|
|
985
1172
|
if (argv[0] === COMPLETE)
|
|
986
1173
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1007,7 +1194,7 @@ function commandPath(scope, argv) {
|
|
|
1007
1194
|
}
|
|
1008
1195
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1009
1196
|
}
|
|
1010
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1197
|
+
async function runMain({ name, version, run, redact, usage }, argv = process11.argv.slice(2)) {
|
|
1011
1198
|
if (argv[0] === COMPLETE)
|
|
1012
1199
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1013
1200
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -1049,8 +1236,8 @@ var SESSION_FILES = new Glob("*.json");
|
|
|
1049
1236
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1050
1237
|
// src/commands/audit.ts
|
|
1051
1238
|
import { stat as stat4 } from "fs/promises";
|
|
1052
|
-
import { relative, resolve } from "path";
|
|
1053
|
-
import
|
|
1239
|
+
import { relative, resolve as resolve3 } from "path";
|
|
1240
|
+
import process13 from "process";
|
|
1054
1241
|
|
|
1055
1242
|
// ../kit/src/shell.ts
|
|
1056
1243
|
var SEPARATORS = new Set([`
|
|
@@ -1101,12 +1288,12 @@ function shellQuote(word) {
|
|
|
1101
1288
|
|
|
1102
1289
|
// src/audit.ts
|
|
1103
1290
|
import { readdir as readdir2, stat as stat2 } from "fs/promises";
|
|
1104
|
-
import { dirname as
|
|
1291
|
+
import { dirname as dirname5, join as join7 } from "path";
|
|
1105
1292
|
var {$ } = globalThis.Bun;
|
|
1106
1293
|
|
|
1107
1294
|
// src/files.ts
|
|
1108
1295
|
import { chmod, chown, readdir, realpath, rename, rm, stat, writeFile } from "fs/promises";
|
|
1109
|
-
import { basename, dirname as
|
|
1296
|
+
import { basename, dirname as dirname4, join as join6 } from "path";
|
|
1110
1297
|
|
|
1111
1298
|
// src/dotenv.ts
|
|
1112
1299
|
var ASSIGNMENT = /^\s*(?:export\s+)?([A-Z_][\w.-]*)\s*=(.*)$/i;
|
|
@@ -1418,7 +1605,7 @@ async function envFiles(folder = process.cwd()) {
|
|
|
1418
1605
|
const found = await readdir(folder, { withFileTypes: true });
|
|
1419
1606
|
const names = [];
|
|
1420
1607
|
for (const entry of found) {
|
|
1421
|
-
if (ENV_FILE.test(entry.name) && await isFileEntry(entry,
|
|
1608
|
+
if (ENV_FILE.test(entry.name) && await isFileEntry(entry, join6(folder, entry.name)))
|
|
1422
1609
|
names.push(entry.name);
|
|
1423
1610
|
}
|
|
1424
1611
|
return names.sort();
|
|
@@ -1442,7 +1629,7 @@ async function writeAtomic(path, text) {
|
|
|
1442
1629
|
if (error.code !== "ENOENT")
|
|
1443
1630
|
throw error;
|
|
1444
1631
|
}
|
|
1445
|
-
const temp =
|
|
1632
|
+
const temp = join6(dirname4(target), `.${basename(target)}.${process.pid}.${crypto.randomUUID()}.tmp`);
|
|
1446
1633
|
try {
|
|
1447
1634
|
await writeFile(temp, text, { mode: 384, flag: "wx" });
|
|
1448
1635
|
if (owner !== undefined)
|
|
@@ -1498,7 +1685,7 @@ async function acquire(path) {
|
|
|
1498
1685
|
try {
|
|
1499
1686
|
real = await realpath(path);
|
|
1500
1687
|
} catch {}
|
|
1501
|
-
const lock =
|
|
1688
|
+
const lock = join6(dirname4(real), `.${basename(real)}.lock`);
|
|
1502
1689
|
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
1503
1690
|
while (true) {
|
|
1504
1691
|
try {
|
|
@@ -1533,7 +1720,7 @@ async function envFilesBelow(folder, depth = 0) {
|
|
|
1533
1720
|
return found;
|
|
1534
1721
|
}
|
|
1535
1722
|
for (const entry of children) {
|
|
1536
|
-
const path =
|
|
1723
|
+
const path = join6(folder, entry.name);
|
|
1537
1724
|
if (entry.isDirectory() && depth < KNOWN_DEPTH && !SKIPPED.has(entry.name))
|
|
1538
1725
|
found.push(...await envFilesBelow(path, depth + 1));
|
|
1539
1726
|
else if (ENV_FILE.test(entry.name) && await isFileEntry(entry, path))
|
|
@@ -1575,7 +1762,7 @@ function inlineSecrets(compose) {
|
|
|
1575
1762
|
async function openToOthers(path) {
|
|
1576
1763
|
if (((await stat2(path)).mode & 4) === 0)
|
|
1577
1764
|
return false;
|
|
1578
|
-
for (let dir =
|
|
1765
|
+
for (let dir = dirname5(path);dir !== "/"; dir = dirname5(dir)) {
|
|
1579
1766
|
if (((await stat2(dir)).mode & 1) === 0)
|
|
1580
1767
|
return false;
|
|
1581
1768
|
}
|
|
@@ -1596,7 +1783,7 @@ async function sharedWith(path) {
|
|
|
1596
1783
|
const shared = groupReads(info.mode, info.gid, primaryGroup(info.uid));
|
|
1597
1784
|
if (!shared && (Bun.which("getfacl") === null || !await hasAclReader(path)))
|
|
1598
1785
|
return false;
|
|
1599
|
-
for (let dir =
|
|
1786
|
+
for (let dir = dirname5(path);dir !== "/"; dir = dirname5(dir)) {
|
|
1600
1787
|
if (((await stat2(dir)).mode & 9) === 0)
|
|
1601
1788
|
return false;
|
|
1602
1789
|
}
|
|
@@ -1608,7 +1795,7 @@ async function hasAclReader(path) {
|
|
|
1608
1795
|
`).some((line) => ACL_READER.test(line));
|
|
1609
1796
|
}
|
|
1610
1797
|
async function tracked(path) {
|
|
1611
|
-
const run = await $`git ls-files --error-unmatch -- ${path}`.cwd(
|
|
1798
|
+
const run = await $`git ls-files --error-unmatch -- ${path}`.cwd(dirname5(path)).quiet().nothrow();
|
|
1612
1799
|
const error = run.stderr.toString();
|
|
1613
1800
|
if (run.exitCode === 0)
|
|
1614
1801
|
return true;
|
|
@@ -1625,7 +1812,7 @@ async function* candidates2(root, unread, depth = 0) {
|
|
|
1625
1812
|
return;
|
|
1626
1813
|
}
|
|
1627
1814
|
for (const entry of found) {
|
|
1628
|
-
const path =
|
|
1815
|
+
const path = join7(root, entry.name);
|
|
1629
1816
|
if (entry.isDirectory() && depth < MAX_DEPTH && !SKIPPED2.has(entry.name))
|
|
1630
1817
|
yield* candidates2(path, unread, depth + 1);
|
|
1631
1818
|
else if (!TEMPLATE.test(entry.name) && (ENV_FILE.test(entry.name) || COMPOSE_FILE.test(entry.name)) && await isFileEntry(entry, path))
|
|
@@ -1657,7 +1844,7 @@ async function audit(roots) {
|
|
|
1657
1844
|
|
|
1658
1845
|
// src/fix.ts
|
|
1659
1846
|
import { chmod as chmod2, chown as chown2, lstat, rm as rm2, stat as stat3 } from "fs/promises";
|
|
1660
|
-
import { dirname as
|
|
1847
|
+
import { dirname as dirname6, join as join8 } from "path";
|
|
1661
1848
|
var MAP_ENTRY = /^(\s*)(["']?)([A-Z0-9_]+)\2(\s*:)(.*)$/;
|
|
1662
1849
|
var LIST_ENTRY = /^(\s*-[ \t]*)(["']?)([A-Z0-9_]+)=(.*)$/;
|
|
1663
1850
|
var TRAILING = /^\s*(?:#.*)?$/;
|
|
@@ -1731,7 +1918,7 @@ async function isLink(path) {
|
|
|
1731
1918
|
}
|
|
1732
1919
|
}
|
|
1733
1920
|
async function resolved(path) {
|
|
1734
|
-
const { code, stdout } = await compose(["config", "--format", "json"], { flags: ["-f", path], cwd:
|
|
1921
|
+
const { code, stdout } = await compose(["config", "--format", "json"], { flags: ["-f", path], cwd: dirname6(path) });
|
|
1735
1922
|
return code === 0 ? stdout : undefined;
|
|
1736
1923
|
}
|
|
1737
1924
|
function gainedBy(before, after, key) {
|
|
@@ -1750,7 +1937,7 @@ async function shutOthersOut(path, group = false) {
|
|
|
1750
1937
|
}
|
|
1751
1938
|
}
|
|
1752
1939
|
async function fixCompose(path, group = false) {
|
|
1753
|
-
const env =
|
|
1940
|
+
const env = join8(dirname6(path), ".env");
|
|
1754
1941
|
const compose = await Bun.file(path).text();
|
|
1755
1942
|
const envBefore = await Bun.file(env).exists() ? await Bun.file(env).text() : undefined;
|
|
1756
1943
|
const dotenv = parseDotenv(envBefore ?? "");
|
|
@@ -1868,7 +2055,7 @@ async function isFolder(path) {
|
|
|
1868
2055
|
}
|
|
1869
2056
|
}
|
|
1870
2057
|
function shown2(path) {
|
|
1871
|
-
return path.startsWith(`${
|
|
2058
|
+
return path.startsWith(`${process13.cwd()}/`) ? relative(process13.cwd(), path) : path;
|
|
1872
2059
|
}
|
|
1873
2060
|
async function fixAll(exposed, json) {
|
|
1874
2061
|
const fixed = [];
|
|
@@ -1897,7 +2084,7 @@ async function fixAll(exposed, json) {
|
|
|
1897
2084
|
}
|
|
1898
2085
|
async function audit2(args) {
|
|
1899
2086
|
const parsed = parse(args, usage2, options);
|
|
1900
|
-
const roots = (parsed.positionals.length > 0 ? parsed.positionals : ["."]).map((dir) =>
|
|
2087
|
+
const roots = (parsed.positionals.length > 0 ? parsed.positionals : ["."]).map((dir) => resolve3(dir));
|
|
1901
2088
|
for (const dir of roots) {
|
|
1902
2089
|
if (!await isFolder(dir))
|
|
1903
2090
|
fail(`${dir} is not a folder`);
|
|
@@ -1924,7 +2111,7 @@ async function audit2(args) {
|
|
|
1924
2111
|
console.log("no exposed .env file nor compose file writing a secret out");
|
|
1925
2112
|
return 0;
|
|
1926
2113
|
}
|
|
1927
|
-
const uid =
|
|
2114
|
+
const uid = process13.getuid?.();
|
|
1928
2115
|
for (const { path, readable, group, tracked, secrets } of exposed) {
|
|
1929
2116
|
const sudo = uid !== undefined && uid !== 0 && (await stat4(path)).uid !== uid ? "sudo " : "";
|
|
1930
2117
|
const problems = [
|
|
@@ -2135,11 +2322,11 @@ ${cpUsage}`);
|
|
|
2135
2322
|
|
|
2136
2323
|
// src/commands/pins.ts
|
|
2137
2324
|
import { readdir as readdir4, stat as stat5 } from "fs/promises";
|
|
2138
|
-
import { join as
|
|
2325
|
+
import { join as join10, resolve as resolve4 } from "path";
|
|
2139
2326
|
|
|
2140
2327
|
// src/pins.ts
|
|
2141
2328
|
import { readdir as readdir3, readFile } from "fs/promises";
|
|
2142
|
-
import { join as
|
|
2329
|
+
import { join as join9, relative as relative2 } from "path";
|
|
2143
2330
|
var OPTIONAL2 = /^\s*([A-Z][A-Z0-9_]*)\s*:\s*s\.Optional\(/gm;
|
|
2144
2331
|
var REACHING = /(?:URL|URI|TOKEN|KEY|SECRET|PASSWORD|DSN|_HOST)(?:_FILE)?$/;
|
|
2145
2332
|
var SELF = /(?:^|_)(?:PUBLIC|SITE|BASE|APP)_URL$/;
|
|
@@ -2169,7 +2356,7 @@ async function walk(folder, keep) {
|
|
|
2169
2356
|
for (const entry of entries) {
|
|
2170
2357
|
if (SKIPPED3.has(entry.name))
|
|
2171
2358
|
continue;
|
|
2172
|
-
const path =
|
|
2359
|
+
const path = join9(folder, entry.name);
|
|
2173
2360
|
if (entry.isDirectory())
|
|
2174
2361
|
found.push(...await walk(path, keep));
|
|
2175
2362
|
else if (entry.isFile() && keep(entry.name))
|
|
@@ -2180,7 +2367,7 @@ async function walk(folder, keep) {
|
|
|
2180
2367
|
async function testFiles(folder) {
|
|
2181
2368
|
const found = [];
|
|
2182
2369
|
for (const root of TEST_ROOTS) {
|
|
2183
|
-
found.push(...await walk(
|
|
2370
|
+
found.push(...await walk(join9(folder, root), (name) => TEST_FILE.test(name)));
|
|
2184
2371
|
}
|
|
2185
2372
|
return found;
|
|
2186
2373
|
}
|
|
@@ -2248,7 +2435,7 @@ function reachesOutside(name) {
|
|
|
2248
2435
|
}
|
|
2249
2436
|
async function schemaFile(folder) {
|
|
2250
2437
|
for (const candidate of SCHEMA_CANDIDATES) {
|
|
2251
|
-
const path =
|
|
2438
|
+
const path = join9(folder, candidate);
|
|
2252
2439
|
if (await exists(path) && (await readFile(path, "utf8")).includes("defineEnv("))
|
|
2253
2440
|
return path;
|
|
2254
2441
|
}
|
|
@@ -2259,7 +2446,7 @@ async function testEnvKeys(folder) {
|
|
|
2259
2446
|
for (const entry of await readdir3(folder, { withFileTypes: true })) {
|
|
2260
2447
|
if (!entry.isFile() || !ENV_TEST.test(entry.name))
|
|
2261
2448
|
continue;
|
|
2262
|
-
for (const line of parseDotenv(await readFile(
|
|
2449
|
+
for (const line of parseDotenv(await readFile(join9(folder, entry.name), "utf8")).lines) {
|
|
2263
2450
|
if (line.key !== undefined)
|
|
2264
2451
|
keys.add(line.key);
|
|
2265
2452
|
}
|
|
@@ -2267,7 +2454,7 @@ async function testEnvKeys(folder) {
|
|
|
2267
2454
|
return keys;
|
|
2268
2455
|
}
|
|
2269
2456
|
async function pinningPreload(folder) {
|
|
2270
|
-
const path =
|
|
2457
|
+
const path = join9(folder, "bunfig.toml");
|
|
2271
2458
|
if (!await exists(path))
|
|
2272
2459
|
return;
|
|
2273
2460
|
let config;
|
|
@@ -2278,7 +2465,7 @@ async function pinningPreload(folder) {
|
|
|
2278
2465
|
}
|
|
2279
2466
|
const preloads = [config.test?.preload, config.preload].flat().filter((entry) => typeof entry === "string" && entry.startsWith("."));
|
|
2280
2467
|
for (const preload of preloads) {
|
|
2281
|
-
const file =
|
|
2468
|
+
const file = join9(folder, preload);
|
|
2282
2469
|
if (!await exists(file))
|
|
2283
2470
|
continue;
|
|
2284
2471
|
const source = await readFile(file, "utf8");
|
|
@@ -2340,7 +2527,7 @@ async function apps(dir, except) {
|
|
|
2340
2527
|
for (const entry of (await readdir4(dir, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2341
2528
|
if (!entry.isDirectory() || entry.name.startsWith(".") || entry.name === "node_modules")
|
|
2342
2529
|
continue;
|
|
2343
|
-
const app = await checkApp(
|
|
2530
|
+
const app = await checkApp(join10(dir, entry.name), except);
|
|
2344
2531
|
if (app !== undefined)
|
|
2345
2532
|
found.push(app);
|
|
2346
2533
|
}
|
|
@@ -2355,7 +2542,7 @@ function name(app, root) {
|
|
|
2355
2542
|
async function pins(args) {
|
|
2356
2543
|
const parsed = parse(args, usage3, options2, { positionals: ["[dir]"] });
|
|
2357
2544
|
const json = parsed.values.json === true;
|
|
2358
|
-
const root =
|
|
2545
|
+
const root = resolve4(parsed.positionals[0] ?? ".");
|
|
2359
2546
|
const except = new Set((parsed.values.except ?? "").split(",").map((entry) => entry.trim()).filter((entry) => entry !== ""));
|
|
2360
2547
|
if (!await isFolder2(root))
|
|
2361
2548
|
fail(`${root} is not a folder`);
|
|
@@ -2402,6 +2589,15 @@ function display(key, value, known) {
|
|
|
2402
2589
|
`, "\\n").replaceAll("\r", "\\r");
|
|
2403
2590
|
}
|
|
2404
2591
|
var jsonFlag2 = { json: jsonOption() };
|
|
2592
|
+
function keyTable(rows) {
|
|
2593
|
+
const path = role("path", process.stdout);
|
|
2594
|
+
const key = role("value", process.stdout);
|
|
2595
|
+
return table(rows.map((each) => [path(each.file), key(each.key), each.value]));
|
|
2596
|
+
}
|
|
2597
|
+
function fileTable(rows) {
|
|
2598
|
+
const path = role("path", process.stdout);
|
|
2599
|
+
return table(rows.map((each) => [path(each.file), each.value]));
|
|
2600
|
+
}
|
|
2405
2601
|
function row(file, key, value, known) {
|
|
2406
2602
|
const shown = display(key, value, known);
|
|
2407
2603
|
return { file, key, value: shown, secret: shown !== value.replaceAll(`
|
|
@@ -2433,7 +2629,7 @@ async function list(args) {
|
|
|
2433
2629
|
}
|
|
2434
2630
|
printRows(rows, parsed.values.json === true, () => {
|
|
2435
2631
|
if (rows.length > 0)
|
|
2436
|
-
console.log(
|
|
2632
|
+
console.log(keyTable(rows));
|
|
2437
2633
|
});
|
|
2438
2634
|
return 0;
|
|
2439
2635
|
}
|
|
@@ -2454,7 +2650,7 @@ ${getUsage}`);
|
|
|
2454
2650
|
}
|
|
2455
2651
|
if (rows.length === 0)
|
|
2456
2652
|
fail(`${key} is not set in ${file ?? "any .env* file"}`, 1);
|
|
2457
|
-
printRows(rows, parsed.values.json === true, () => console.log(file === undefined ?
|
|
2653
|
+
printRows(rows, parsed.values.json === true, () => console.log(file === undefined ? fileTable(rows) : rows[0]?.value));
|
|
2458
2654
|
return 0;
|
|
2459
2655
|
}
|
|
2460
2656
|
var grepUsage = `ev grep [-i] <regex> [file...]
|
|
@@ -2496,7 +2692,7 @@ ${grepUsage}`);
|
|
|
2496
2692
|
}
|
|
2497
2693
|
if (rows.length === 0)
|
|
2498
2694
|
fail(`no key matches ${source} in ${names.join(", ") || "any .env* file"}`, 1);
|
|
2499
|
-
printRows(rows, parsed.values.json === true, () => console.log(
|
|
2695
|
+
printRows(rows, parsed.values.json === true, () => console.log(keyTable(rows)));
|
|
2500
2696
|
return 0;
|
|
2501
2697
|
}
|
|
2502
2698
|
async function show(args) {
|
|
@@ -2523,7 +2719,7 @@ ${showUsage}`);
|
|
|
2523
2719
|
}
|
|
2524
2720
|
|
|
2525
2721
|
// src/commands/redact.ts
|
|
2526
|
-
import
|
|
2722
|
+
import process14 from "process";
|
|
2527
2723
|
|
|
2528
2724
|
// src/redactor.ts
|
|
2529
2725
|
var DIFF_START = /^(?:diff --git |@@ )/;
|
|
@@ -2663,13 +2859,13 @@ async function redact(args) {
|
|
|
2663
2859
|
const redactor = new Redactor(known);
|
|
2664
2860
|
const decoder = new TextDecoder;
|
|
2665
2861
|
for await (const chunk of Bun.stdin.stream())
|
|
2666
|
-
|
|
2667
|
-
|
|
2862
|
+
process14.stdout.write(redactor.push(decoder.decode(chunk, { stream: true })));
|
|
2863
|
+
process14.stdout.write(redactor.push(decoder.decode()) + redactor.end());
|
|
2668
2864
|
return 0;
|
|
2669
2865
|
}
|
|
2670
2866
|
|
|
2671
2867
|
// src/ev.ts
|
|
2672
|
-
|
|
2868
|
+
process15.exitCode = await runCli({
|
|
2673
2869
|
name: "ev",
|
|
2674
2870
|
about: ".env files listed and edited with secrets masked",
|
|
2675
2871
|
replaces: "cat .env, grep on env files and editing them by hand",
|