@kaynooo/cli-check 0.9.1 → 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/README.md +20 -0
- package/dist/cli.js +440 -286
- package/dist/errs-cli.js +217 -157
- package/dist/fix-cli.js +454 -300
- package/dist/j-cli.js +1779 -0
- package/package.json +5 -4
package/dist/errs-cli.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/errs-cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process14 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/args.ts
|
|
8
|
-
import
|
|
8
|
+
import process5 from "process";
|
|
9
9
|
import { parseArgs } from "util";
|
|
10
10
|
|
|
11
11
|
// ../kit/src/format.ts
|
|
@@ -375,6 +375,55 @@ function printJson(value) {
|
|
|
375
375
|
console.log(JSON.stringify(value, undefined, 2));
|
|
376
376
|
}
|
|
377
377
|
|
|
378
|
+
// ../kit/src/help.ts
|
|
379
|
+
import process3 from "process";
|
|
380
|
+
var OPTIONAL = /\[[^\]]+\]/g;
|
|
381
|
+
var USAGE_PREFIX = /^usage:\s*/i;
|
|
382
|
+
var FULL_STOP = /\.$/;
|
|
383
|
+
function usageLine(usage, colors = paint(process3.stdout)) {
|
|
384
|
+
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
385
|
+
}
|
|
386
|
+
function helpText(usage, options, colors = paint(process3.stdout), { examples = [], replaces } = {}) {
|
|
387
|
+
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
388
|
+
`);
|
|
389
|
+
}
|
|
390
|
+
function replacesRows(replaces, colors = paint(process3.stdout)) {
|
|
391
|
+
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
392
|
+
}
|
|
393
|
+
function wantsHelpJson(env = process3.env) {
|
|
394
|
+
return env.KIT_HELP === "json";
|
|
395
|
+
}
|
|
396
|
+
function description(usage, { examples = [], replaces } = {}) {
|
|
397
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
398
|
+
`);
|
|
399
|
+
const first = lines[0];
|
|
400
|
+
const colon = first.indexOf(": ");
|
|
401
|
+
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
402
|
+
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
403
|
+
return {
|
|
404
|
+
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
405
|
+
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
406
|
+
...replaces === undefined ? {} : { replaces },
|
|
407
|
+
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
function exampleRows(examples, colors = paint(process3.stdout)) {
|
|
411
|
+
if (examples.length === 0)
|
|
412
|
+
return [];
|
|
413
|
+
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
414
|
+
}
|
|
415
|
+
function optionRows(options, colors = paint(process3.stdout)) {
|
|
416
|
+
const rows = Object.entries(options).map(([name, option]) => {
|
|
417
|
+
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
418
|
+
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
419
|
+
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
420
|
+
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
421
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
|
|
422
|
+
});
|
|
423
|
+
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
424
|
+
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
425
|
+
}
|
|
426
|
+
|
|
378
427
|
// ../kit/src/text.ts
|
|
379
428
|
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
380
429
|
function stripAnsi(text) {
|
|
@@ -397,8 +446,33 @@ function closest(name, names) {
|
|
|
397
446
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
398
447
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
399
448
|
}
|
|
449
|
+
// ../kit/src/input.ts
|
|
450
|
+
import process4 from "process";
|
|
451
|
+
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
452
|
+
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
453
|
+
function duration(value, name, fallback, unit = "s") {
|
|
454
|
+
if (value === undefined)
|
|
455
|
+
return fallback;
|
|
456
|
+
const match = DURATION.exec(value.trim());
|
|
457
|
+
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
458
|
+
if (ms < 1)
|
|
459
|
+
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
460
|
+
return ms;
|
|
461
|
+
}
|
|
462
|
+
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
463
|
+
if (path === "-") {
|
|
464
|
+
if (process4.stdin.isTTY)
|
|
465
|
+
fail(noStdin);
|
|
466
|
+
return Bun.stdin.text();
|
|
467
|
+
}
|
|
468
|
+
const file = Bun.file(path);
|
|
469
|
+
if (!await file.exists())
|
|
470
|
+
fail(`no file ${path}`);
|
|
471
|
+
return file.text();
|
|
472
|
+
}
|
|
400
473
|
|
|
401
474
|
// ../kit/src/args.ts
|
|
475
|
+
var DASHES = /^-+/;
|
|
402
476
|
function jsonOption(holds) {
|
|
403
477
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
404
478
|
}
|
|
@@ -442,58 +516,11 @@ class Completing {
|
|
|
442
516
|
}
|
|
443
517
|
}
|
|
444
518
|
var completion = { active: false };
|
|
445
|
-
var OPTIONAL = /\[[^\]]+\]/g;
|
|
446
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
447
|
-
var FULL_STOP = /\.$/;
|
|
448
|
-
var DASHES = /^-+/;
|
|
449
|
-
function usageLine(usage, colors = paint(process3.stdout)) {
|
|
450
|
-
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
451
|
-
}
|
|
452
|
-
function helpText(usage, options, colors = paint(process3.stdout), { examples = [], replaces } = {}) {
|
|
453
|
-
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
454
|
-
`);
|
|
455
|
-
}
|
|
456
|
-
function replacesRows(replaces, colors = paint(process3.stdout)) {
|
|
457
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
458
|
-
}
|
|
459
|
-
function wantsHelpJson(env = process3.env) {
|
|
460
|
-
return env.KIT_HELP === "json";
|
|
461
|
-
}
|
|
462
|
-
function description(usage, { examples = [], replaces } = {}) {
|
|
463
|
-
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
464
|
-
`);
|
|
465
|
-
const first = lines[0];
|
|
466
|
-
const colon = first.indexOf(": ");
|
|
467
|
-
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
468
|
-
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
469
|
-
return {
|
|
470
|
-
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
471
|
-
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
472
|
-
...replaces === undefined ? {} : { replaces },
|
|
473
|
-
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
474
|
-
};
|
|
475
|
-
}
|
|
476
|
-
function exampleRows(examples, colors = paint(process3.stdout)) {
|
|
477
|
-
if (examples.length === 0)
|
|
478
|
-
return [];
|
|
479
|
-
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
480
|
-
}
|
|
481
|
-
function optionRows(options, colors = paint(process3.stdout)) {
|
|
482
|
-
const rows = Object.entries(options).map(([name, option]) => {
|
|
483
|
-
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
484
|
-
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
485
|
-
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
486
|
-
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
487
|
-
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
|
|
488
|
-
});
|
|
489
|
-
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
490
|
-
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
491
|
-
}
|
|
492
519
|
var OUTPUT_OPTIONS = {
|
|
493
520
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
494
521
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
495
522
|
};
|
|
496
|
-
function applyOutput(color, plain, env =
|
|
523
|
+
function applyOutput(color, plain, env = process5.env) {
|
|
497
524
|
const when = plain === true ? "never" : color ?? "auto";
|
|
498
525
|
if (when === "auto")
|
|
499
526
|
return;
|
|
@@ -650,31 +677,9 @@ function nearestOption(message, options, allowNegative) {
|
|
|
650
677
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
651
678
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
652
679
|
}
|
|
653
|
-
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
654
|
-
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
655
|
-
function duration(value, name, fallback, unit = "s") {
|
|
656
|
-
if (value === undefined)
|
|
657
|
-
return fallback;
|
|
658
|
-
const match = DURATION.exec(value.trim());
|
|
659
|
-
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
660
|
-
if (ms < 1)
|
|
661
|
-
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
662
|
-
return ms;
|
|
663
|
-
}
|
|
664
|
-
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
665
|
-
if (path === "-") {
|
|
666
|
-
if (process3.stdin.isTTY)
|
|
667
|
-
fail(noStdin);
|
|
668
|
-
return Bun.stdin.text();
|
|
669
|
-
}
|
|
670
|
-
const file = Bun.file(path);
|
|
671
|
-
if (!await file.exists())
|
|
672
|
-
fail(`no file ${path}`);
|
|
673
|
-
return file.text();
|
|
674
|
-
}
|
|
675
680
|
// ../kit/src/process.ts
|
|
676
681
|
import { constants } from "os";
|
|
677
|
-
import
|
|
682
|
+
import process6 from "process";
|
|
678
683
|
var KILL_GRACE_MS = 2000;
|
|
679
684
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
680
685
|
function exitCodeOf(code, signal) {
|
|
@@ -696,7 +701,7 @@ function holdSignals(cleanup) {
|
|
|
696
701
|
},
|
|
697
702
|
release: () => {
|
|
698
703
|
for (const signal of SIGNALS)
|
|
699
|
-
|
|
704
|
+
process6.off(signal, onSignal);
|
|
700
705
|
}
|
|
701
706
|
};
|
|
702
707
|
function onSignal(signal) {
|
|
@@ -709,10 +714,10 @@ function holdSignals(cleanup) {
|
|
|
709
714
|
return;
|
|
710
715
|
held.release();
|
|
711
716
|
cleanup(signal);
|
|
712
|
-
|
|
717
|
+
process6.kill(process6.pid, signal);
|
|
713
718
|
}
|
|
714
719
|
for (const signal of SIGNALS)
|
|
715
|
-
|
|
720
|
+
process6.on(signal, onSignal);
|
|
716
721
|
return held;
|
|
717
722
|
}
|
|
718
723
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -726,7 +731,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
726
731
|
return;
|
|
727
732
|
try {
|
|
728
733
|
if (grouped)
|
|
729
|
-
|
|
734
|
+
process6.kill(-proc.pid, killing);
|
|
730
735
|
else
|
|
731
736
|
proc.kill(killing);
|
|
732
737
|
} catch {}
|
|
@@ -800,15 +805,111 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
800
805
|
var RESET_STYLE = `${ESC}[0m`;
|
|
801
806
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
802
807
|
// ../kit/src/cli.ts
|
|
803
|
-
import
|
|
808
|
+
import process9 from "process";
|
|
809
|
+
|
|
810
|
+
// ../kit/src/usage.ts
|
|
811
|
+
import { appendFileSync, mkdirSync } from "fs";
|
|
812
|
+
import { homedir as homedir2 } from "os";
|
|
813
|
+
import { dirname, isAbsolute, join as join2 } from "path";
|
|
814
|
+
import process8 from "process";
|
|
815
|
+
|
|
816
|
+
// ../kit/src/logs.ts
|
|
817
|
+
import { lstatSync, openSync } from "fs";
|
|
818
|
+
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
819
|
+
import { homedir, tmpdir } from "os";
|
|
820
|
+
import { join } from "path";
|
|
821
|
+
import process7 from "process";
|
|
822
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
823
|
+
var CLI_FOLDER = "kaynooo-cli";
|
|
824
|
+
function isPrivateDirectory(path) {
|
|
825
|
+
try {
|
|
826
|
+
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
827
|
+
return info !== undefined && info.isDirectory() && info.uid === (process7.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
828
|
+
} catch {
|
|
829
|
+
return false;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
async function privateLogDirectory(name, env = process7.env) {
|
|
833
|
+
const runtime = env.XDG_RUNTIME_DIR;
|
|
834
|
+
const base = runtime === undefined || runtime === "" ? join(homedir(), ".cache", CLI_FOLDER) : join(runtime, CLI_FOLDER);
|
|
835
|
+
const path = join(base, name);
|
|
836
|
+
try {
|
|
837
|
+
await mkdir(path, { recursive: true, mode: 448 });
|
|
838
|
+
if (isPrivateDirectory(path))
|
|
839
|
+
return path;
|
|
840
|
+
} catch {}
|
|
841
|
+
return mkdtemp(join(tmpdir(), `${name.replaceAll("/", "-")}-`));
|
|
842
|
+
}
|
|
843
|
+
async function sweepLogs(dir, maxAgeMs = DAY_MS, now = Date.now()) {
|
|
844
|
+
let names;
|
|
845
|
+
try {
|
|
846
|
+
names = await readdir(dir);
|
|
847
|
+
} catch {
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
for (const name of names) {
|
|
851
|
+
const path = join(dir, name);
|
|
852
|
+
try {
|
|
853
|
+
const info = await stat(path);
|
|
854
|
+
if (info.isDirectory())
|
|
855
|
+
await sweepLogs(path, maxAgeMs, now);
|
|
856
|
+
if (now - info.mtimeMs > maxAgeMs)
|
|
857
|
+
await rm(path, { force: true, recursive: info.isDirectory() });
|
|
858
|
+
} catch {
|
|
859
|
+
continue;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
// ../kit/src/usage.ts
|
|
865
|
+
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
866
|
+
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
867
|
+
var LONGEST_NAME = 40;
|
|
868
|
+
var usageError;
|
|
869
|
+
function noteUsageError(message) {
|
|
870
|
+
usageError = message;
|
|
871
|
+
}
|
|
872
|
+
function stateHome(env = process8.env) {
|
|
873
|
+
const dir = env.XDG_STATE_HOME;
|
|
874
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join2(homedir2(), ".local", "state");
|
|
875
|
+
}
|
|
876
|
+
function usagePath(env = process8.env) {
|
|
877
|
+
return join2(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
878
|
+
}
|
|
879
|
+
function usageRecorded(env = process8.env) {
|
|
880
|
+
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
881
|
+
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
882
|
+
}
|
|
883
|
+
function flagNames(argv) {
|
|
884
|
+
const end = argv.indexOf("--");
|
|
885
|
+
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
886
|
+
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
887
|
+
}
|
|
888
|
+
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
889
|
+
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
890
|
+
usageError = undefined;
|
|
891
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
892
|
+
}
|
|
893
|
+
function recordUsage(entry, env = process8.env) {
|
|
894
|
+
if (!usageRecorded(env))
|
|
895
|
+
return;
|
|
896
|
+
try {
|
|
897
|
+
const path = usagePath(env);
|
|
898
|
+
mkdirSync(dirname(path), { recursive: true, mode: 448 });
|
|
899
|
+
appendFileSync(path, `${JSON.stringify(entry)}
|
|
900
|
+
`, { mode: 384 });
|
|
901
|
+
} catch {}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
// ../kit/src/cli.ts
|
|
804
905
|
var LEVEL_OPTIONS = {
|
|
805
906
|
...OUTPUT_OPTIONS,
|
|
806
907
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
807
908
|
};
|
|
808
909
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
809
910
|
function printError(prefix, message, hint, cause) {
|
|
810
|
-
const colors = paint(
|
|
811
|
-
const styled = takesControlCodes(
|
|
911
|
+
const colors = paint(process9.stderr);
|
|
912
|
+
const styled = takesControlCodes(process9.stderr);
|
|
812
913
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
813
914
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
814
915
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -827,6 +928,8 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
|
827
928
|
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
828
929
|
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
829
930
|
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
931
|
+
if (error instanceof UsageError)
|
|
932
|
+
noteUsageError(error.message);
|
|
830
933
|
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
831
934
|
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
832
935
|
return error instanceof Exit ? error.code : 1;
|
|
@@ -888,65 +991,22 @@ async function printCandidates(found) {
|
|
|
888
991
|
console.log(line);
|
|
889
992
|
return 0;
|
|
890
993
|
}
|
|
891
|
-
async function runMain({ name, version, run, redact }, argv =
|
|
994
|
+
async function runMain({ name, version, run, redact, usage }, argv = process9.argv.slice(2)) {
|
|
892
995
|
if (argv[0] === COMPLETE)
|
|
893
996
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
894
997
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
895
998
|
console.log(version);
|
|
896
999
|
return 0;
|
|
897
1000
|
}
|
|
1001
|
+
let code;
|
|
898
1002
|
try {
|
|
899
|
-
|
|
1003
|
+
code = await run(argv);
|
|
900
1004
|
} catch (error) {
|
|
901
|
-
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
|
-
// ../kit/src/logs.ts
|
|
905
|
-
import { lstatSync, openSync } from "fs";
|
|
906
|
-
import { mkdir, mkdtemp, readdir, rm, stat } from "fs/promises";
|
|
907
|
-
import { homedir, tmpdir } from "os";
|
|
908
|
-
import { join } from "path";
|
|
909
|
-
import process6 from "process";
|
|
910
|
-
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
911
|
-
var CLI_FOLDER = "kaynooo-cli";
|
|
912
|
-
function isPrivateDirectory(path) {
|
|
913
|
-
try {
|
|
914
|
-
const info = lstatSync(path, { throwIfNoEntry: false });
|
|
915
|
-
return info !== undefined && info.isDirectory() && info.uid === (process6.getuid?.() ?? info.uid) && (info.mode & 63) === 0;
|
|
916
|
-
} catch {
|
|
917
|
-
return false;
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
async function privateLogDirectory(name, env = process6.env) {
|
|
921
|
-
const runtime = env.XDG_RUNTIME_DIR;
|
|
922
|
-
const base = runtime === undefined || runtime === "" ? join(homedir(), ".cache", CLI_FOLDER) : join(runtime, CLI_FOLDER);
|
|
923
|
-
const path = join(base, name);
|
|
924
|
-
try {
|
|
925
|
-
await mkdir(path, { recursive: true, mode: 448 });
|
|
926
|
-
if (isPrivateDirectory(path))
|
|
927
|
-
return path;
|
|
928
|
-
} catch {}
|
|
929
|
-
return mkdtemp(join(tmpdir(), `${name.replaceAll("/", "-")}-`));
|
|
930
|
-
}
|
|
931
|
-
async function sweepLogs(dir, maxAgeMs = DAY_MS, now = Date.now()) {
|
|
932
|
-
let names;
|
|
933
|
-
try {
|
|
934
|
-
names = await readdir(dir);
|
|
935
|
-
} catch {
|
|
936
|
-
return;
|
|
937
|
-
}
|
|
938
|
-
for (const name of names) {
|
|
939
|
-
const path = join(dir, name);
|
|
940
|
-
try {
|
|
941
|
-
const info = await stat(path);
|
|
942
|
-
if (info.isDirectory())
|
|
943
|
-
await sweepLogs(path, maxAgeMs, now);
|
|
944
|
-
if (now - info.mtimeMs > maxAgeMs)
|
|
945
|
-
await rm(path, { force: true, recursive: info.isDirectory() });
|
|
946
|
-
} catch {
|
|
947
|
-
continue;
|
|
948
|
-
}
|
|
1005
|
+
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
949
1006
|
}
|
|
1007
|
+
if (usage !== false)
|
|
1008
|
+
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1009
|
+
return code;
|
|
950
1010
|
}
|
|
951
1011
|
// ../kit/src/secrets.ts
|
|
952
1012
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
@@ -955,17 +1015,17 @@ var {Glob } = globalThis.Bun;
|
|
|
955
1015
|
var SESSION_FILES = new Glob("*.json");
|
|
956
1016
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
957
1017
|
// package.json
|
|
958
|
-
var version = "0.
|
|
1018
|
+
var version = "0.11.0";
|
|
959
1019
|
|
|
960
1020
|
// src/errs.ts
|
|
961
1021
|
import { relative as relative2 } from "path";
|
|
962
|
-
import
|
|
1022
|
+
import process13 from "process";
|
|
963
1023
|
|
|
964
1024
|
// src/compose.ts
|
|
965
1025
|
import { existsSync } from "fs";
|
|
966
|
-
import { homedir as
|
|
967
|
-
import { basename, dirname, join as
|
|
968
|
-
import
|
|
1026
|
+
import { homedir as homedir3 } from "os";
|
|
1027
|
+
import { basename, dirname as dirname2, join as join3, relative, resolve } from "path";
|
|
1028
|
+
import process11 from "process";
|
|
969
1029
|
|
|
970
1030
|
// ../kit/src/shell.ts
|
|
971
1031
|
var SEPARATORS = new Set([`
|
|
@@ -1035,7 +1095,7 @@ function toolWords(program) {
|
|
|
1035
1095
|
}
|
|
1036
1096
|
async function readFiles(dir, names) {
|
|
1037
1097
|
for (const name of names) {
|
|
1038
|
-
const handle = Bun.file(
|
|
1098
|
+
const handle = Bun.file(join3(dir, name));
|
|
1039
1099
|
if (await handle.exists())
|
|
1040
1100
|
return { name, text: await handle.text() };
|
|
1041
1101
|
}
|
|
@@ -1050,7 +1110,7 @@ async function variables(composeDir) {
|
|
|
1050
1110
|
if (match !== null && !line.trimStart().startsWith("#"))
|
|
1051
1111
|
env[match[1] ?? ""] = (match[2] ?? "").trim().replace(QUOTED, "$2");
|
|
1052
1112
|
}
|
|
1053
|
-
for (const [key, value] of Object.entries(
|
|
1113
|
+
for (const [key, value] of Object.entries(process11.env)) {
|
|
1054
1114
|
if (value !== undefined)
|
|
1055
1115
|
env[key] = value;
|
|
1056
1116
|
}
|
|
@@ -1070,7 +1130,7 @@ function interpolate(text, env) {
|
|
|
1070
1130
|
function bindSource(source, composeDir, env) {
|
|
1071
1131
|
const path = interpolate(source, env);
|
|
1072
1132
|
if (path.startsWith("~"))
|
|
1073
|
-
return
|
|
1133
|
+
return join3(homedir3(), path.slice(1));
|
|
1074
1134
|
if (path.startsWith("/"))
|
|
1075
1135
|
return resolve(path);
|
|
1076
1136
|
return path.startsWith(".") ? resolve(composeDir, path) : undefined;
|
|
@@ -1117,7 +1177,7 @@ async function composeFiles(composeDir, env) {
|
|
|
1117
1177
|
for (const name of listed.split(separator === undefined || separator === "" ? ":" : separator).filter((entry) => entry !== "")) {
|
|
1118
1178
|
const file = Bun.file(resolve(composeDir, name));
|
|
1119
1179
|
if (!await file.exists())
|
|
1120
|
-
fail(`COMPOSE_FILE names ${
|
|
1180
|
+
fail(`COMPOSE_FILE names ${join3(composeDir, name)}, which does not exist`, 1, "fix COMPOSE_FILE, or run on the host with --host");
|
|
1121
1181
|
files.push({ name, text: await file.text() });
|
|
1122
1182
|
}
|
|
1123
1183
|
return files;
|
|
@@ -1139,7 +1199,7 @@ async function readServices(composeDir) {
|
|
|
1139
1199
|
try {
|
|
1140
1200
|
parsed = parseServices(file.text, composeDir, env);
|
|
1141
1201
|
} catch (error) {
|
|
1142
|
-
fail(`cannot read ${
|
|
1202
|
+
fail(`cannot read ${join3(composeDir, file.name)}: ${error instanceof Error ? error.message : String(error)}`, 1, "fix the file, or run on the host with --host");
|
|
1143
1203
|
}
|
|
1144
1204
|
for (const [name, extra] of parsed) {
|
|
1145
1205
|
const known = services.get(name);
|
|
@@ -1151,11 +1211,11 @@ async function readServices(composeDir) {
|
|
|
1151
1211
|
function climb(dir) {
|
|
1152
1212
|
const folders = [dir];
|
|
1153
1213
|
let current = dir;
|
|
1154
|
-
while (!existsSync(
|
|
1155
|
-
current =
|
|
1214
|
+
while (!existsSync(join3(current, ".git")) && dirname2(current) !== current) {
|
|
1215
|
+
current = dirname2(current);
|
|
1156
1216
|
folders.push(current);
|
|
1157
1217
|
}
|
|
1158
|
-
return existsSync(
|
|
1218
|
+
return existsSync(join3(current, ".git")) ? folders : [dir];
|
|
1159
1219
|
}
|
|
1160
1220
|
function containerPath(service, dir) {
|
|
1161
1221
|
const holding = service.mounts.filter((mount) => {
|
|
@@ -1166,7 +1226,7 @@ function containerPath(service, dir) {
|
|
|
1166
1226
|
if (deepest === undefined)
|
|
1167
1227
|
return;
|
|
1168
1228
|
const inside = relative(deepest.source, dir);
|
|
1169
|
-
return inside === "" ? deepest.target :
|
|
1229
|
+
return inside === "" ? deepest.target : join3(deepest.target, inside);
|
|
1170
1230
|
}
|
|
1171
1231
|
var noticed = new Set;
|
|
1172
1232
|
async function place(dir, program, { service, host } = {}) {
|
|
@@ -1186,7 +1246,7 @@ async function place(dir, program, { service, host } = {}) {
|
|
|
1186
1246
|
fail(`--in ${service}: no compose project mounts ${dir}`);
|
|
1187
1247
|
return;
|
|
1188
1248
|
}
|
|
1189
|
-
if (Bun.which("docker", { PATH:
|
|
1249
|
+
if (Bun.which("docker", { PATH: process11.env.PATH ?? "" }) === null) {
|
|
1190
1250
|
if (service !== undefined)
|
|
1191
1251
|
fail(`--in ${service}: docker not found`);
|
|
1192
1252
|
if (!noticed.has(found.composeDir)) {
|
|
@@ -1238,7 +1298,7 @@ class Stack {
|
|
|
1238
1298
|
}
|
|
1239
1299
|
static async running(composeDir) {
|
|
1240
1300
|
try {
|
|
1241
|
-
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env:
|
|
1301
|
+
const ran = await runCommand(["docker", "compose", "ps", "--services", "--status", "running"], { cwd: composeDir, env: process11.env, timeoutMs: PS_TIMEOUT_MS });
|
|
1242
1302
|
if (ran.code !== 0)
|
|
1243
1303
|
return `docker compose ps failed in ${composeDir}: ${ran.text.trim().split(`
|
|
1244
1304
|
`).at(-1) ?? `exit ${ran.code}`}`;
|
|
@@ -1896,20 +1956,20 @@ function parseErrors(output) {
|
|
|
1896
1956
|
|
|
1897
1957
|
// src/run.ts
|
|
1898
1958
|
import { mkdir as mkdir2, writeFile } from "fs/promises";
|
|
1899
|
-
import { basename as basename2, join as
|
|
1900
|
-
import
|
|
1959
|
+
import { basename as basename2, join as join4 } from "path";
|
|
1960
|
+
import process12 from "process";
|
|
1901
1961
|
var LOG_MAX_AGE_MS = 3 * 24 * 60 * 60 * 1000;
|
|
1902
1962
|
async function logDirectory(cwd) {
|
|
1903
1963
|
const root = await privateLogDirectory("check");
|
|
1904
1964
|
await sweepLogs(root, LOG_MAX_AGE_MS);
|
|
1905
|
-
const path =
|
|
1965
|
+
const path = join4(root, `${basename2(cwd)}-${Bun.hash(cwd).toString(36)}-${Date.now().toString(36)}-${process12.pid}`);
|
|
1906
1966
|
await mkdir2(path, { mode: 448 });
|
|
1907
1967
|
return path;
|
|
1908
1968
|
}
|
|
1909
1969
|
async function saveLog(output) {
|
|
1910
1970
|
const root = await privateLogDirectory("errs");
|
|
1911
1971
|
await sweepLogs(root);
|
|
1912
|
-
const path =
|
|
1972
|
+
const path = join4(root, `${new Date().toISOString().replaceAll(/[:.]/g, "-")}-${process12.pid}-${crypto.randomUUID().slice(0, 8)}.log`);
|
|
1913
1973
|
await writeFile(path, output, { mode: 384, flag: "wx" });
|
|
1914
1974
|
return path;
|
|
1915
1975
|
}
|
|
@@ -1917,7 +1977,7 @@ async function runStep(command, cwd, logFile, { env = {}, timeoutMs, held } = {}
|
|
|
1917
1977
|
const started = Date.now();
|
|
1918
1978
|
const { code, text, timedOut } = await runCommand(["sh", "-c", `${command} 2>&1`], {
|
|
1919
1979
|
cwd,
|
|
1920
|
-
env: { ...
|
|
1980
|
+
env: { ...process12.env, NO_COLOR: "1", FORCE_COLOR: "0", ...env },
|
|
1921
1981
|
...timeoutMs === undefined ? {} : { timeoutMs },
|
|
1922
1982
|
...held === undefined ? {} : { onStart: (child) => held.forward(child) }
|
|
1923
1983
|
});
|
|
@@ -1947,7 +2007,7 @@ function printOutcome(name, width, command, logFile, outcome) {
|
|
|
1947
2007
|
}
|
|
1948
2008
|
|
|
1949
2009
|
// src/errs.ts
|
|
1950
|
-
var
|
|
2010
|
+
var usage2 = `errs [options] [log]
|
|
1951
2011
|
errs [options] -- <command> [args...]
|
|
1952
2012
|
errs --in <service> | --host -- <command> [args...]
|
|
1953
2013
|
|
|
@@ -1988,7 +2048,7 @@ async function readInput2(command, run, settings, cwd) {
|
|
|
1988
2048
|
const held = holdSignals();
|
|
1989
2049
|
let ran;
|
|
1990
2050
|
try {
|
|
1991
|
-
ran = await runCommand(placement === undefined ? command : argvIn(placement, command), { ...placement === undefined ? {} : { cwd: placement.composeDir }, env: { ...
|
|
2051
|
+
ran = await runCommand(placement === undefined ? command : argvIn(placement, command), { ...placement === undefined ? {} : { cwd: placement.composeDir }, env: { ...process13.env, NO_COLOR: "1", FORCE_COLOR: "0" }, onStart: (child) => held.forward(child) });
|
|
1992
2052
|
} catch (error) {
|
|
1993
2053
|
fail(`cannot run ${command[0]}: ${error instanceof Error ? error.message : String(error)}`);
|
|
1994
2054
|
} finally {
|
|
@@ -1996,14 +2056,14 @@ async function readInput2(command, run, settings, cwd) {
|
|
|
1996
2056
|
}
|
|
1997
2057
|
return { text: stripAnsi(ran.text), log: await saveLog(ran.output), code: ran.code };
|
|
1998
2058
|
}
|
|
1999
|
-
async function errs(args, cwd =
|
|
2059
|
+
async function errs(args, cwd = process13.cwd()) {
|
|
2000
2060
|
const first = args[0];
|
|
2001
2061
|
const bare = first !== undefined && !first.startsWith("-") && !await Bun.file(first).exists();
|
|
2002
|
-
const parsed = parse(bare ? [] : args,
|
|
2062
|
+
const parsed = parse(bare ? [] : args, usage2, options, { rest: true, replaces: "reading raw tsc, eslint, phpunit, phpstan or playwright logs, or grepping a test summary out of them", examples: [["errs -- bun run check", "the type errors of a run"], ["bun test 2>&1 | errs", "the failed tests from stdin"], ["errs -- vendor/bin/phpunit", "each failed PHP test with its file and line"]] });
|
|
2003
2063
|
if (parsed.positionals.length > 1)
|
|
2004
2064
|
fail(`give one log, or a command after --
|
|
2005
2065
|
|
|
2006
|
-
${
|
|
2066
|
+
${usage2}`);
|
|
2007
2067
|
const input = await readInput2(bare ? args : parsed.rest ?? parsed.positionals, bare || parsed.rest !== undefined, placeSettings(parsed.values), cwd);
|
|
2008
2068
|
const { errors, unrecognised } = parseErrors(input.text);
|
|
2009
2069
|
if (parsed.values.json === true) {
|
|
@@ -2020,4 +2080,4 @@ ${usage}`);
|
|
|
2020
2080
|
}
|
|
2021
2081
|
|
|
2022
2082
|
// src/errs-cli.ts
|
|
2023
|
-
|
|
2083
|
+
process14.exitCode = await runMain({ name: "errs", version, run: async (args) => errs(args) });
|