@kaynooo/cli-git 0.5.1 → 0.6.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 +10 -1
- package/dist/gb.js +1234 -0
- package/dist/gc.js +135 -75
- package/dist/gst.js +134 -74
- package/package.json +8 -6
package/dist/gc.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/gc.ts
|
|
5
|
-
import
|
|
5
|
+
import process8 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/args.ts
|
|
8
|
-
import
|
|
8
|
+
import process3 from "process";
|
|
9
9
|
import { parseArgs } from "util";
|
|
10
10
|
|
|
11
11
|
// ../kit/src/style.ts
|
|
@@ -298,6 +298,55 @@ function printJson(value) {
|
|
|
298
298
|
console.log(JSON.stringify(value, undefined, 2));
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
+
// ../kit/src/help.ts
|
|
302
|
+
import process2 from "process";
|
|
303
|
+
var OPTIONAL = /\[[^\]]+\]/g;
|
|
304
|
+
var USAGE_PREFIX = /^usage:\s*/i;
|
|
305
|
+
var FULL_STOP = /\.$/;
|
|
306
|
+
function usageLine(usage, colors = paint(process2.stdout)) {
|
|
307
|
+
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
308
|
+
}
|
|
309
|
+
function helpText(usage, options, colors = paint(process2.stdout), { examples = [], replaces } = {}) {
|
|
310
|
+
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
311
|
+
`);
|
|
312
|
+
}
|
|
313
|
+
function replacesRows(replaces, colors = paint(process2.stdout)) {
|
|
314
|
+
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
315
|
+
}
|
|
316
|
+
function wantsHelpJson(env = process2.env) {
|
|
317
|
+
return env.KIT_HELP === "json";
|
|
318
|
+
}
|
|
319
|
+
function description(usage, { examples = [], replaces } = {}) {
|
|
320
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
321
|
+
`);
|
|
322
|
+
const first = lines[0];
|
|
323
|
+
const colon = first.indexOf(": ");
|
|
324
|
+
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
325
|
+
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
326
|
+
return {
|
|
327
|
+
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
328
|
+
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
329
|
+
...replaces === undefined ? {} : { replaces },
|
|
330
|
+
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function exampleRows(examples, colors = paint(process2.stdout)) {
|
|
334
|
+
if (examples.length === 0)
|
|
335
|
+
return [];
|
|
336
|
+
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
337
|
+
}
|
|
338
|
+
function optionRows(options, colors = paint(process2.stdout)) {
|
|
339
|
+
const rows = Object.entries(options).map(([name, option]) => {
|
|
340
|
+
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
341
|
+
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
342
|
+
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
343
|
+
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
344
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
|
|
345
|
+
});
|
|
346
|
+
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
347
|
+
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
348
|
+
}
|
|
349
|
+
|
|
301
350
|
// ../kit/src/text.ts
|
|
302
351
|
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
303
352
|
function distance(a, b) {
|
|
@@ -317,8 +366,19 @@ function closest(name, names) {
|
|
|
317
366
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
318
367
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
319
368
|
}
|
|
369
|
+
// ../kit/src/input.ts
|
|
370
|
+
var WHOLE = /^\d+$/;
|
|
371
|
+
function wholeNumber(value, name, fallback, min = 1) {
|
|
372
|
+
if (value === undefined)
|
|
373
|
+
return fallback;
|
|
374
|
+
const number = Number(value);
|
|
375
|
+
if (!WHOLE.test(value) || !Number.isSafeInteger(number) || number < min)
|
|
376
|
+
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
377
|
+
return number;
|
|
378
|
+
}
|
|
320
379
|
|
|
321
380
|
// ../kit/src/args.ts
|
|
381
|
+
var DASHES = /^-+/;
|
|
322
382
|
function jsonOption(holds) {
|
|
323
383
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
324
384
|
}
|
|
@@ -362,58 +422,11 @@ class Completing {
|
|
|
362
422
|
}
|
|
363
423
|
}
|
|
364
424
|
var completion = { active: false };
|
|
365
|
-
var OPTIONAL = /\[[^\]]+\]/g;
|
|
366
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
367
|
-
var FULL_STOP = /\.$/;
|
|
368
|
-
var DASHES = /^-+/;
|
|
369
|
-
function usageLine(usage, colors = paint(process2.stdout)) {
|
|
370
|
-
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
371
|
-
}
|
|
372
|
-
function helpText(usage, options, colors = paint(process2.stdout), { examples = [], replaces } = {}) {
|
|
373
|
-
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
374
|
-
`);
|
|
375
|
-
}
|
|
376
|
-
function replacesRows(replaces, colors = paint(process2.stdout)) {
|
|
377
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
378
|
-
}
|
|
379
|
-
function wantsHelpJson(env = process2.env) {
|
|
380
|
-
return env.KIT_HELP === "json";
|
|
381
|
-
}
|
|
382
|
-
function description(usage, { examples = [], replaces } = {}) {
|
|
383
|
-
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
384
|
-
`);
|
|
385
|
-
const first = lines[0];
|
|
386
|
-
const colon = first.indexOf(": ");
|
|
387
|
-
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
388
|
-
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
389
|
-
return {
|
|
390
|
-
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
391
|
-
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
392
|
-
...replaces === undefined ? {} : { replaces },
|
|
393
|
-
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
function exampleRows(examples, colors = paint(process2.stdout)) {
|
|
397
|
-
if (examples.length === 0)
|
|
398
|
-
return [];
|
|
399
|
-
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
400
|
-
}
|
|
401
|
-
function optionRows(options, colors = paint(process2.stdout)) {
|
|
402
|
-
const rows = Object.entries(options).map(([name, option]) => {
|
|
403
|
-
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
404
|
-
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
405
|
-
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
406
|
-
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
407
|
-
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
|
|
408
|
-
});
|
|
409
|
-
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
410
|
-
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
411
|
-
}
|
|
412
425
|
var OUTPUT_OPTIONS = {
|
|
413
426
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
414
427
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
415
428
|
};
|
|
416
|
-
function applyOutput(color, plain, env =
|
|
429
|
+
function applyOutput(color, plain, env = process3.env) {
|
|
417
430
|
const when = plain === true ? "never" : color ?? "auto";
|
|
418
431
|
if (when === "auto")
|
|
419
432
|
return;
|
|
@@ -570,18 +583,9 @@ function nearestOption(message, options, allowNegative) {
|
|
|
570
583
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
571
584
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
572
585
|
}
|
|
573
|
-
var WHOLE = /^\d+$/;
|
|
574
|
-
function wholeNumber(value, name, fallback, min = 1) {
|
|
575
|
-
if (value === undefined)
|
|
576
|
-
return fallback;
|
|
577
|
-
const number = Number(value);
|
|
578
|
-
if (!WHOLE.test(value) || !Number.isSafeInteger(number) || number < min)
|
|
579
|
-
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
580
|
-
return number;
|
|
581
|
-
}
|
|
582
586
|
// ../kit/src/process.ts
|
|
583
587
|
import { constants } from "os";
|
|
584
|
-
import
|
|
588
|
+
import process4 from "process";
|
|
585
589
|
var KILL_GRACE_MS = 2000;
|
|
586
590
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
587
591
|
function exitCodeOf(code, signal) {
|
|
@@ -603,7 +607,7 @@ function holdSignals(cleanup) {
|
|
|
603
607
|
},
|
|
604
608
|
release: () => {
|
|
605
609
|
for (const signal of SIGNALS)
|
|
606
|
-
|
|
610
|
+
process4.off(signal, onSignal);
|
|
607
611
|
}
|
|
608
612
|
};
|
|
609
613
|
function onSignal(signal) {
|
|
@@ -616,10 +620,10 @@ function holdSignals(cleanup) {
|
|
|
616
620
|
return;
|
|
617
621
|
held.release();
|
|
618
622
|
cleanup(signal);
|
|
619
|
-
|
|
623
|
+
process4.kill(process4.pid, signal);
|
|
620
624
|
}
|
|
621
625
|
for (const signal of SIGNALS)
|
|
622
|
-
|
|
626
|
+
process4.on(signal, onSignal);
|
|
623
627
|
return held;
|
|
624
628
|
}
|
|
625
629
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -633,7 +637,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
633
637
|
return;
|
|
634
638
|
try {
|
|
635
639
|
if (grouped)
|
|
636
|
-
|
|
640
|
+
process4.kill(-proc.pid, killing);
|
|
637
641
|
else
|
|
638
642
|
proc.kill(killing);
|
|
639
643
|
} catch {}
|
|
@@ -707,15 +711,67 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
707
711
|
var RESET_STYLE = `${ESC}[0m`;
|
|
708
712
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
709
713
|
// ../kit/src/cli.ts
|
|
710
|
-
import
|
|
714
|
+
import process6 from "process";
|
|
715
|
+
|
|
716
|
+
// ../kit/src/usage.ts
|
|
717
|
+
import { appendFileSync, mkdirSync } from "fs";
|
|
718
|
+
import { homedir } from "os";
|
|
719
|
+
import { dirname, isAbsolute, join } from "path";
|
|
720
|
+
import process5 from "process";
|
|
721
|
+
|
|
722
|
+
// ../kit/src/logs.ts
|
|
723
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
724
|
+
var CLI_FOLDER = "kaynooo-cli";
|
|
725
|
+
|
|
726
|
+
// ../kit/src/usage.ts
|
|
727
|
+
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
728
|
+
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
729
|
+
var LONGEST_NAME = 40;
|
|
730
|
+
var usageError;
|
|
731
|
+
function noteUsageError(message) {
|
|
732
|
+
usageError = message;
|
|
733
|
+
}
|
|
734
|
+
function stateHome(env = process5.env) {
|
|
735
|
+
const dir = env.XDG_STATE_HOME;
|
|
736
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
|
|
737
|
+
}
|
|
738
|
+
function usagePath(env = process5.env) {
|
|
739
|
+
return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
740
|
+
}
|
|
741
|
+
function usageRecorded(env = process5.env) {
|
|
742
|
+
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
743
|
+
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
744
|
+
}
|
|
745
|
+
function flagNames(argv) {
|
|
746
|
+
const end = argv.indexOf("--");
|
|
747
|
+
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
748
|
+
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
749
|
+
}
|
|
750
|
+
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
751
|
+
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
752
|
+
usageError = undefined;
|
|
753
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
754
|
+
}
|
|
755
|
+
function recordUsage(entry, env = process5.env) {
|
|
756
|
+
if (!usageRecorded(env))
|
|
757
|
+
return;
|
|
758
|
+
try {
|
|
759
|
+
const path = usagePath(env);
|
|
760
|
+
mkdirSync(dirname(path), { recursive: true, mode: 448 });
|
|
761
|
+
appendFileSync(path, `${JSON.stringify(entry)}
|
|
762
|
+
`, { mode: 384 });
|
|
763
|
+
} catch {}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// ../kit/src/cli.ts
|
|
711
767
|
var LEVEL_OPTIONS = {
|
|
712
768
|
...OUTPUT_OPTIONS,
|
|
713
769
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
714
770
|
};
|
|
715
771
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
716
772
|
function printError(prefix, message, hint, cause) {
|
|
717
|
-
const colors = paint(
|
|
718
|
-
const styled = takesControlCodes(
|
|
773
|
+
const colors = paint(process6.stderr);
|
|
774
|
+
const styled = takesControlCodes(process6.stderr);
|
|
719
775
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
720
776
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
721
777
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -737,6 +793,8 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
|
737
793
|
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
738
794
|
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
739
795
|
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
796
|
+
if (error instanceof UsageError)
|
|
797
|
+
noteUsageError(error.message);
|
|
740
798
|
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
741
799
|
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
742
800
|
return error instanceof Exit ? error.code : 1;
|
|
@@ -798,21 +856,23 @@ async function printCandidates(found) {
|
|
|
798
856
|
console.log(line);
|
|
799
857
|
return 0;
|
|
800
858
|
}
|
|
801
|
-
async function runMain({ name, version, run, redact }, argv =
|
|
859
|
+
async function runMain({ name, version, run, redact, usage }, argv = process6.argv.slice(2)) {
|
|
802
860
|
if (argv[0] === COMPLETE)
|
|
803
861
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
804
862
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
805
863
|
console.log(version);
|
|
806
864
|
return 0;
|
|
807
865
|
}
|
|
866
|
+
let code;
|
|
808
867
|
try {
|
|
809
|
-
|
|
868
|
+
code = await run(argv);
|
|
810
869
|
} catch (error) {
|
|
811
|
-
|
|
870
|
+
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
812
871
|
}
|
|
872
|
+
if (usage !== false)
|
|
873
|
+
recordUsage(usageEntry(name, undefined, argv, code));
|
|
874
|
+
return code;
|
|
813
875
|
}
|
|
814
|
-
// ../kit/src/logs.ts
|
|
815
|
-
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
816
876
|
// ../kit/src/secrets.ts
|
|
817
877
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
818
878
|
// ../kit/src/sessions.ts
|
|
@@ -820,7 +880,7 @@ var {Glob } = globalThis.Bun;
|
|
|
820
880
|
var SESSION_FILES = new Glob("*.json");
|
|
821
881
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
822
882
|
// package.json
|
|
823
|
-
var version = "0.
|
|
883
|
+
var version = "0.6.0";
|
|
824
884
|
|
|
825
885
|
// src/git.ts
|
|
826
886
|
async function git2(args, env) {
|
|
@@ -892,7 +952,7 @@ var OPTIONS = {
|
|
|
892
952
|
};
|
|
893
953
|
var RENAME = /^[RC]\d*$/;
|
|
894
954
|
var NOT_A_REPOSITORY = /not a git repository/i;
|
|
895
|
-
var LITERAL = { ...
|
|
955
|
+
var LITERAL = { ...process8.env, GIT_LITERAL_PATHSPECS: "1" };
|
|
896
956
|
function messageOf(title, lines, tickets) {
|
|
897
957
|
return [title, lines.join(`
|
|
898
958
|
`), tickets.join(`
|
|
@@ -979,4 +1039,4 @@ ${(commit.stderr + commit.stdout).trim()}`);
|
|
|
979
1039
|
signals.release();
|
|
980
1040
|
}
|
|
981
1041
|
}
|
|
982
|
-
|
|
1042
|
+
process8.exitCode = await runMain({ name: "gc", version, run: main });
|
package/dist/gst.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/gst.ts
|
|
5
|
-
import
|
|
5
|
+
import process8 from "process";
|
|
6
6
|
|
|
7
7
|
// ../kit/src/args.ts
|
|
8
|
-
import
|
|
8
|
+
import process3 from "process";
|
|
9
9
|
import { parseArgs } from "util";
|
|
10
10
|
|
|
11
11
|
// ../kit/src/style.ts
|
|
@@ -298,6 +298,55 @@ function printJson(value) {
|
|
|
298
298
|
console.log(JSON.stringify(value, undefined, 2));
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
+
// ../kit/src/help.ts
|
|
302
|
+
import process2 from "process";
|
|
303
|
+
var OPTIONAL = /\[[^\]]+\]/g;
|
|
304
|
+
var USAGE_PREFIX = /^usage:\s*/i;
|
|
305
|
+
var FULL_STOP = /\.$/;
|
|
306
|
+
function usageLine(usage, colors = paint(process2.stdout)) {
|
|
307
|
+
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
308
|
+
}
|
|
309
|
+
function helpText(usage, options, colors = paint(process2.stdout), { examples = [], replaces } = {}) {
|
|
310
|
+
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
311
|
+
`);
|
|
312
|
+
}
|
|
313
|
+
function replacesRows(replaces, colors = paint(process2.stdout)) {
|
|
314
|
+
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
315
|
+
}
|
|
316
|
+
function wantsHelpJson(env = process2.env) {
|
|
317
|
+
return env.KIT_HELP === "json";
|
|
318
|
+
}
|
|
319
|
+
function description(usage, { examples = [], replaces } = {}) {
|
|
320
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
321
|
+
`);
|
|
322
|
+
const first = lines[0];
|
|
323
|
+
const colon = first.indexOf(": ");
|
|
324
|
+
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
325
|
+
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
326
|
+
return {
|
|
327
|
+
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
328
|
+
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
329
|
+
...replaces === undefined ? {} : { replaces },
|
|
330
|
+
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function exampleRows(examples, colors = paint(process2.stdout)) {
|
|
334
|
+
if (examples.length === 0)
|
|
335
|
+
return [];
|
|
336
|
+
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
337
|
+
}
|
|
338
|
+
function optionRows(options, colors = paint(process2.stdout)) {
|
|
339
|
+
const rows = Object.entries(options).map(([name, option]) => {
|
|
340
|
+
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
341
|
+
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
342
|
+
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
343
|
+
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
344
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
|
|
345
|
+
});
|
|
346
|
+
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
347
|
+
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
348
|
+
}
|
|
349
|
+
|
|
301
350
|
// ../kit/src/text.ts
|
|
302
351
|
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
303
352
|
function distance(a, b) {
|
|
@@ -317,8 +366,19 @@ function closest(name, names) {
|
|
|
317
366
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
318
367
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
319
368
|
}
|
|
369
|
+
// ../kit/src/input.ts
|
|
370
|
+
var WHOLE = /^\d+$/;
|
|
371
|
+
function wholeNumber(value, name, fallback, min = 1) {
|
|
372
|
+
if (value === undefined)
|
|
373
|
+
return fallback;
|
|
374
|
+
const number = Number(value);
|
|
375
|
+
if (!WHOLE.test(value) || !Number.isSafeInteger(number) || number < min)
|
|
376
|
+
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
377
|
+
return number;
|
|
378
|
+
}
|
|
320
379
|
|
|
321
380
|
// ../kit/src/args.ts
|
|
381
|
+
var DASHES = /^-+/;
|
|
322
382
|
function jsonOption(holds) {
|
|
323
383
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
324
384
|
}
|
|
@@ -362,58 +422,11 @@ class Completing {
|
|
|
362
422
|
}
|
|
363
423
|
}
|
|
364
424
|
var completion = { active: false };
|
|
365
|
-
var OPTIONAL = /\[[^\]]+\]/g;
|
|
366
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
367
|
-
var FULL_STOP = /\.$/;
|
|
368
|
-
var DASHES = /^-+/;
|
|
369
|
-
function usageLine(usage, colors = paint(process2.stdout)) {
|
|
370
|
-
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
371
|
-
}
|
|
372
|
-
function helpText(usage, options, colors = paint(process2.stdout), { examples = [], replaces } = {}) {
|
|
373
|
-
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
374
|
-
`);
|
|
375
|
-
}
|
|
376
|
-
function replacesRows(replaces, colors = paint(process2.stdout)) {
|
|
377
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
378
|
-
}
|
|
379
|
-
function wantsHelpJson(env = process2.env) {
|
|
380
|
-
return env.KIT_HELP === "json";
|
|
381
|
-
}
|
|
382
|
-
function description(usage, { examples = [], replaces } = {}) {
|
|
383
|
-
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
384
|
-
`);
|
|
385
|
-
const first = lines[0];
|
|
386
|
-
const colon = first.indexOf(": ");
|
|
387
|
-
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
388
|
-
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
389
|
-
return {
|
|
390
|
-
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
391
|
-
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
392
|
-
...replaces === undefined ? {} : { replaces },
|
|
393
|
-
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
function exampleRows(examples, colors = paint(process2.stdout)) {
|
|
397
|
-
if (examples.length === 0)
|
|
398
|
-
return [];
|
|
399
|
-
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
400
|
-
}
|
|
401
|
-
function optionRows(options, colors = paint(process2.stdout)) {
|
|
402
|
-
const rows = Object.entries(options).map(([name, option]) => {
|
|
403
|
-
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
404
|
-
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
405
|
-
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
406
|
-
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
407
|
-
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
|
|
408
|
-
});
|
|
409
|
-
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
410
|
-
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
411
|
-
}
|
|
412
425
|
var OUTPUT_OPTIONS = {
|
|
413
426
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
414
427
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
415
428
|
};
|
|
416
|
-
function applyOutput(color, plain, env =
|
|
429
|
+
function applyOutput(color, plain, env = process3.env) {
|
|
417
430
|
const when = plain === true ? "never" : color ?? "auto";
|
|
418
431
|
if (when === "auto")
|
|
419
432
|
return;
|
|
@@ -570,18 +583,9 @@ function nearestOption(message, options, allowNegative) {
|
|
|
570
583
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
571
584
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
572
585
|
}
|
|
573
|
-
var WHOLE = /^\d+$/;
|
|
574
|
-
function wholeNumber(value, name, fallback, min = 1) {
|
|
575
|
-
if (value === undefined)
|
|
576
|
-
return fallback;
|
|
577
|
-
const number = Number(value);
|
|
578
|
-
if (!WHOLE.test(value) || !Number.isSafeInteger(number) || number < min)
|
|
579
|
-
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
580
|
-
return number;
|
|
581
|
-
}
|
|
582
586
|
// ../kit/src/process.ts
|
|
583
587
|
import { constants } from "os";
|
|
584
|
-
import
|
|
588
|
+
import process4 from "process";
|
|
585
589
|
var KILL_GRACE_MS = 2000;
|
|
586
590
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
587
591
|
function exitCodeOf(code, signal) {
|
|
@@ -603,7 +607,7 @@ function holdSignals(cleanup) {
|
|
|
603
607
|
},
|
|
604
608
|
release: () => {
|
|
605
609
|
for (const signal of SIGNALS)
|
|
606
|
-
|
|
610
|
+
process4.off(signal, onSignal);
|
|
607
611
|
}
|
|
608
612
|
};
|
|
609
613
|
function onSignal(signal) {
|
|
@@ -616,10 +620,10 @@ function holdSignals(cleanup) {
|
|
|
616
620
|
return;
|
|
617
621
|
held.release();
|
|
618
622
|
cleanup(signal);
|
|
619
|
-
|
|
623
|
+
process4.kill(process4.pid, signal);
|
|
620
624
|
}
|
|
621
625
|
for (const signal of SIGNALS)
|
|
622
|
-
|
|
626
|
+
process4.on(signal, onSignal);
|
|
623
627
|
return held;
|
|
624
628
|
}
|
|
625
629
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -633,7 +637,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
633
637
|
return;
|
|
634
638
|
try {
|
|
635
639
|
if (grouped)
|
|
636
|
-
|
|
640
|
+
process4.kill(-proc.pid, killing);
|
|
637
641
|
else
|
|
638
642
|
proc.kill(killing);
|
|
639
643
|
} catch {}
|
|
@@ -707,15 +711,67 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
707
711
|
var RESET_STYLE = `${ESC}[0m`;
|
|
708
712
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
709
713
|
// ../kit/src/cli.ts
|
|
710
|
-
import
|
|
714
|
+
import process6 from "process";
|
|
715
|
+
|
|
716
|
+
// ../kit/src/usage.ts
|
|
717
|
+
import { appendFileSync, mkdirSync } from "fs";
|
|
718
|
+
import { homedir } from "os";
|
|
719
|
+
import { dirname, isAbsolute, join } from "path";
|
|
720
|
+
import process5 from "process";
|
|
721
|
+
|
|
722
|
+
// ../kit/src/logs.ts
|
|
723
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
724
|
+
var CLI_FOLDER = "kaynooo-cli";
|
|
725
|
+
|
|
726
|
+
// ../kit/src/usage.ts
|
|
727
|
+
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
728
|
+
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
729
|
+
var LONGEST_NAME = 40;
|
|
730
|
+
var usageError;
|
|
731
|
+
function noteUsageError(message) {
|
|
732
|
+
usageError = message;
|
|
733
|
+
}
|
|
734
|
+
function stateHome(env = process5.env) {
|
|
735
|
+
const dir = env.XDG_STATE_HOME;
|
|
736
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
|
|
737
|
+
}
|
|
738
|
+
function usagePath(env = process5.env) {
|
|
739
|
+
return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
740
|
+
}
|
|
741
|
+
function usageRecorded(env = process5.env) {
|
|
742
|
+
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
743
|
+
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
744
|
+
}
|
|
745
|
+
function flagNames(argv) {
|
|
746
|
+
const end = argv.indexOf("--");
|
|
747
|
+
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
748
|
+
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
749
|
+
}
|
|
750
|
+
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
751
|
+
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
752
|
+
usageError = undefined;
|
|
753
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
754
|
+
}
|
|
755
|
+
function recordUsage(entry, env = process5.env) {
|
|
756
|
+
if (!usageRecorded(env))
|
|
757
|
+
return;
|
|
758
|
+
try {
|
|
759
|
+
const path = usagePath(env);
|
|
760
|
+
mkdirSync(dirname(path), { recursive: true, mode: 448 });
|
|
761
|
+
appendFileSync(path, `${JSON.stringify(entry)}
|
|
762
|
+
`, { mode: 384 });
|
|
763
|
+
} catch {}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// ../kit/src/cli.ts
|
|
711
767
|
var LEVEL_OPTIONS = {
|
|
712
768
|
...OUTPUT_OPTIONS,
|
|
713
769
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
714
770
|
};
|
|
715
771
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
716
772
|
function printError(prefix, message, hint, cause) {
|
|
717
|
-
const colors = paint(
|
|
718
|
-
const styled = takesControlCodes(
|
|
773
|
+
const colors = paint(process6.stderr);
|
|
774
|
+
const styled = takesControlCodes(process6.stderr);
|
|
719
775
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
720
776
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
721
777
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -737,6 +793,8 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
|
737
793
|
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
738
794
|
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
739
795
|
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
796
|
+
if (error instanceof UsageError)
|
|
797
|
+
noteUsageError(error.message);
|
|
740
798
|
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
741
799
|
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
742
800
|
return error instanceof Exit ? error.code : 1;
|
|
@@ -798,21 +856,23 @@ async function printCandidates(found) {
|
|
|
798
856
|
console.log(line);
|
|
799
857
|
return 0;
|
|
800
858
|
}
|
|
801
|
-
async function runMain({ name, version, run, redact }, argv =
|
|
859
|
+
async function runMain({ name, version, run, redact, usage }, argv = process6.argv.slice(2)) {
|
|
802
860
|
if (argv[0] === COMPLETE)
|
|
803
861
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
804
862
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
805
863
|
console.log(version);
|
|
806
864
|
return 0;
|
|
807
865
|
}
|
|
866
|
+
let code;
|
|
808
867
|
try {
|
|
809
|
-
|
|
868
|
+
code = await run(argv);
|
|
810
869
|
} catch (error) {
|
|
811
|
-
|
|
870
|
+
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
812
871
|
}
|
|
872
|
+
if (usage !== false)
|
|
873
|
+
recordUsage(usageEntry(name, undefined, argv, code));
|
|
874
|
+
return code;
|
|
813
875
|
}
|
|
814
|
-
// ../kit/src/logs.ts
|
|
815
|
-
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
816
876
|
// ../kit/src/secrets.ts
|
|
817
877
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
818
878
|
// ../kit/src/sessions.ts
|
|
@@ -820,7 +880,7 @@ var {Glob } = globalThis.Bun;
|
|
|
820
880
|
var SESSION_FILES = new Glob("*.json");
|
|
821
881
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
822
882
|
// package.json
|
|
823
|
-
var version = "0.
|
|
883
|
+
var version = "0.6.0";
|
|
824
884
|
|
|
825
885
|
// src/git.ts
|
|
826
886
|
async function git2(args, env) {
|
|
@@ -961,4 +1021,4 @@ ${USAGE}`);
|
|
|
961
1021
|
`));
|
|
962
1022
|
return 0;
|
|
963
1023
|
}
|
|
964
|
-
|
|
1024
|
+
process8.exitCode = await runMain({ name: "gst", version, run: main });
|