@kaynooo/cli-git 0.5.0 → 0.5.2
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/gc.js +260 -90
- package/dist/gst.js +258 -88
- package/package.json +2 -2
package/dist/gc.js
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
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
|
|
12
12
|
import process from "process";
|
|
13
13
|
|
|
14
|
-
// ../../node_modules/.bun/@kaynooo+utils@2.31.
|
|
14
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
15
15
|
function x(s) {
|
|
16
16
|
let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
|
|
17
17
|
if (!/^[a-f0-9]+$/.test(r))
|
|
@@ -231,7 +231,7 @@ class e {
|
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
// ../../node_modules/.bun/@kaynooo+utils@2.31.
|
|
234
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
|
|
235
235
|
var r = 39;
|
|
236
236
|
var o = 49;
|
|
237
237
|
var f2 = "\x1B[";
|
|
@@ -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
|
}
|
|
@@ -353,61 +413,20 @@ class HelpShown extends Exit {
|
|
|
353
413
|
|
|
354
414
|
class Completing {
|
|
355
415
|
options;
|
|
356
|
-
|
|
416
|
+
positionals;
|
|
417
|
+
candidates;
|
|
418
|
+
constructor(options, positionals = [], candidates = {}) {
|
|
357
419
|
this.options = options;
|
|
420
|
+
this.positionals = positionals;
|
|
421
|
+
this.candidates = candidates;
|
|
358
422
|
}
|
|
359
423
|
}
|
|
360
424
|
var completion = { active: false };
|
|
361
|
-
var OPTIONAL = /\[[^\]]+\]/g;
|
|
362
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
363
|
-
var FULL_STOP = /\.$/;
|
|
364
|
-
var DASHES = /^-+/;
|
|
365
|
-
function usageLine(usage, colors = paint(process2.stdout)) {
|
|
366
|
-
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
367
|
-
}
|
|
368
|
-
function helpText(usage, options, colors = paint(process2.stdout), { examples = [], replaces } = {}) {
|
|
369
|
-
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
370
|
-
`);
|
|
371
|
-
}
|
|
372
|
-
function replacesRows(replaces, colors = paint(process2.stdout)) {
|
|
373
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
374
|
-
}
|
|
375
|
-
function wantsHelpJson(env = process2.env) {
|
|
376
|
-
return env.KIT_HELP === "json";
|
|
377
|
-
}
|
|
378
|
-
function description(usage, { examples = [], replaces } = {}) {
|
|
379
|
-
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
380
|
-
`);
|
|
381
|
-
const first = lines[0];
|
|
382
|
-
const colon = first.indexOf(": ");
|
|
383
|
-
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
384
|
-
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
385
|
-
return {
|
|
386
|
-
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
387
|
-
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
388
|
-
...replaces === undefined ? {} : { replaces },
|
|
389
|
-
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
function exampleRows(examples, colors = paint(process2.stdout)) {
|
|
393
|
-
if (examples.length === 0)
|
|
394
|
-
return [];
|
|
395
|
-
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
396
|
-
}
|
|
397
|
-
function optionRows(options, colors = paint(process2.stdout)) {
|
|
398
|
-
const rows = Object.entries(options).map(([name, option]) => {
|
|
399
|
-
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
400
|
-
const value = option.type === "string" ? ` ${colors.dim("<value>")}` : "";
|
|
401
|
-
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? " <value>".length : 0), description: option.description ?? "" };
|
|
402
|
-
});
|
|
403
|
-
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
404
|
-
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
405
|
-
}
|
|
406
425
|
var OUTPUT_OPTIONS = {
|
|
407
426
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
408
427
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
409
428
|
};
|
|
410
|
-
function applyOutput(color, plain, env =
|
|
429
|
+
function applyOutput(color, plain, env = process3.env) {
|
|
411
430
|
const when = plain === true ? "never" : color ?? "auto";
|
|
412
431
|
if (when === "auto")
|
|
413
432
|
return;
|
|
@@ -424,14 +443,13 @@ function applyOutput(color, plain, env = process2.env) {
|
|
|
424
443
|
function parse(args, usage, options, settings = {}) {
|
|
425
444
|
const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
|
|
426
445
|
const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
|
|
446
|
+
const listing = listed(all, settings.allowNegative === true);
|
|
427
447
|
if (completion.active)
|
|
428
|
-
throw new Completing(
|
|
429
|
-
const
|
|
430
|
-
const own = separator === -1 ? args : args.slice(0, separator);
|
|
431
|
-
const rest = separator === -1 ? undefined : args.slice(separator + 1);
|
|
448
|
+
throw new Completing(listing, settings.positionals, settings.candidates);
|
|
449
|
+
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
432
450
|
let parsed;
|
|
433
451
|
try {
|
|
434
|
-
parsed = parseArgs({ args: joinDashValues(own, all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
452
|
+
parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
435
453
|
} catch (error) {
|
|
436
454
|
const message = parseError(error);
|
|
437
455
|
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
@@ -439,12 +457,84 @@ function parse(args, usage, options, settings = {}) {
|
|
|
439
457
|
const values = parsed.values;
|
|
440
458
|
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
441
459
|
if (values.help === true) {
|
|
442
|
-
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage,
|
|
460
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
|
|
443
461
|
throw new HelpShown;
|
|
444
462
|
}
|
|
463
|
+
checkChoices(parsed.values, all);
|
|
464
|
+
checkConflicts(parsed.values, all);
|
|
445
465
|
if (settings.positionals !== undefined)
|
|
446
466
|
checkPositionals(parsed.positionals, settings.positionals);
|
|
447
|
-
return { ...parsed, positionals: parsed.positionals, rest };
|
|
467
|
+
return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
|
|
468
|
+
}
|
|
469
|
+
function splitRest(args, passes) {
|
|
470
|
+
const separator = passes ? args.indexOf("--") : -1;
|
|
471
|
+
return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
|
|
472
|
+
}
|
|
473
|
+
function splitTrailing(args, options, count) {
|
|
474
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
475
|
+
let seen = 0;
|
|
476
|
+
if (count === 0)
|
|
477
|
+
return { own: args, rest: undefined };
|
|
478
|
+
for (let at = 0;at < args.length; at++) {
|
|
479
|
+
const word = args[at];
|
|
480
|
+
if (word === "--")
|
|
481
|
+
break;
|
|
482
|
+
if (word.startsWith("-")) {
|
|
483
|
+
if (takesValue(word))
|
|
484
|
+
at++;
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
seen++;
|
|
488
|
+
if (seen === count)
|
|
489
|
+
return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
|
|
490
|
+
}
|
|
491
|
+
return { own: args, rest: undefined };
|
|
492
|
+
}
|
|
493
|
+
function listed(options, allowNegative) {
|
|
494
|
+
if (!allowNegative)
|
|
495
|
+
return options;
|
|
496
|
+
return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
|
|
497
|
+
if (option.type !== "boolean" || option.negative === undefined)
|
|
498
|
+
return [[name, option]];
|
|
499
|
+
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
500
|
+
}));
|
|
501
|
+
}
|
|
502
|
+
function withBare(args, options) {
|
|
503
|
+
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
504
|
+
if (bare.size === 0)
|
|
505
|
+
return args;
|
|
506
|
+
const separator = args.indexOf("--");
|
|
507
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
508
|
+
return [...own.flatMap((arg, index) => {
|
|
509
|
+
const optional = bare.get(arg);
|
|
510
|
+
const next = own[index + 1];
|
|
511
|
+
const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
|
|
512
|
+
return optional === undefined || value ? [arg] : [arg, optional.bare];
|
|
513
|
+
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
514
|
+
}
|
|
515
|
+
function checkConflicts(values, options) {
|
|
516
|
+
const given = (name) => values[name] !== undefined && values[name] !== false;
|
|
517
|
+
for (const [name, { conflicts = [] }] of Object.entries(options)) {
|
|
518
|
+
const other = given(name) ? conflicts.find(given) : undefined;
|
|
519
|
+
if (other !== undefined)
|
|
520
|
+
badUsage(`--${name} cannot be used with --${other}`);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
function checkChoices(values, options) {
|
|
524
|
+
for (const [name, option] of Object.entries(options)) {
|
|
525
|
+
if (option.choices === undefined)
|
|
526
|
+
continue;
|
|
527
|
+
const given = values[name];
|
|
528
|
+
for (const value of Array.isArray(given) ? given : [given]) {
|
|
529
|
+
if (typeof value === "string")
|
|
530
|
+
oneOf(value, name, option.choices);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
function oneOf(value, name, choices) {
|
|
535
|
+
if (!choices.includes(value))
|
|
536
|
+
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
|
|
537
|
+
return value;
|
|
448
538
|
}
|
|
449
539
|
function checkPositionals(given, names) {
|
|
450
540
|
const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
|
|
@@ -493,18 +583,9 @@ function nearestOption(message, options, allowNegative) {
|
|
|
493
583
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
494
584
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
495
585
|
}
|
|
496
|
-
var WHOLE = /^\d+$/;
|
|
497
|
-
function wholeNumber(value, name, fallback, min = 1) {
|
|
498
|
-
if (value === undefined)
|
|
499
|
-
return fallback;
|
|
500
|
-
const number = Number(value);
|
|
501
|
-
if (!WHOLE.test(value) || !Number.isSafeInteger(number) || number < min)
|
|
502
|
-
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
503
|
-
return number;
|
|
504
|
-
}
|
|
505
586
|
// ../kit/src/process.ts
|
|
506
587
|
import { constants } from "os";
|
|
507
|
-
import
|
|
588
|
+
import process4 from "process";
|
|
508
589
|
var KILL_GRACE_MS = 2000;
|
|
509
590
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
510
591
|
function exitCodeOf(code, signal) {
|
|
@@ -526,7 +607,7 @@ function holdSignals(cleanup) {
|
|
|
526
607
|
},
|
|
527
608
|
release: () => {
|
|
528
609
|
for (const signal of SIGNALS)
|
|
529
|
-
|
|
610
|
+
process4.off(signal, onSignal);
|
|
530
611
|
}
|
|
531
612
|
};
|
|
532
613
|
function onSignal(signal) {
|
|
@@ -539,10 +620,10 @@ function holdSignals(cleanup) {
|
|
|
539
620
|
return;
|
|
540
621
|
held.release();
|
|
541
622
|
cleanup(signal);
|
|
542
|
-
|
|
623
|
+
process4.kill(process4.pid, signal);
|
|
543
624
|
}
|
|
544
625
|
for (const signal of SIGNALS)
|
|
545
|
-
|
|
626
|
+
process4.on(signal, onSignal);
|
|
546
627
|
return held;
|
|
547
628
|
}
|
|
548
629
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -556,7 +637,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
556
637
|
return;
|
|
557
638
|
try {
|
|
558
639
|
if (grouped)
|
|
559
|
-
|
|
640
|
+
process4.kill(-proc.pid, killing);
|
|
560
641
|
else
|
|
561
642
|
proc.kill(killing);
|
|
562
643
|
} catch {}
|
|
@@ -630,15 +711,67 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
630
711
|
var RESET_STYLE = `${ESC}[0m`;
|
|
631
712
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
632
713
|
// ../kit/src/cli.ts
|
|
633
|
-
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
|
|
634
767
|
var LEVEL_OPTIONS = {
|
|
635
768
|
...OUTPUT_OPTIONS,
|
|
636
769
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
637
770
|
};
|
|
638
771
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
639
772
|
function printError(prefix, message, hint, cause) {
|
|
640
|
-
const colors = paint(
|
|
641
|
-
const styled = takesControlCodes(
|
|
773
|
+
const colors = paint(process6.stderr);
|
|
774
|
+
const styled = takesControlCodes(process6.stderr);
|
|
642
775
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
643
776
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
644
777
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -660,49 +793,86 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
|
660
793
|
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
661
794
|
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
662
795
|
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
796
|
+
if (error instanceof UsageError)
|
|
797
|
+
noteUsageError(error.message);
|
|
663
798
|
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
664
799
|
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
665
800
|
return error instanceof Exit ? error.code : 1;
|
|
666
801
|
}
|
|
667
802
|
var COMPLETE = "__complete";
|
|
668
803
|
var FILES = "__files__";
|
|
669
|
-
async function
|
|
804
|
+
async function completingOf(run) {
|
|
670
805
|
completion.active = true;
|
|
671
806
|
try {
|
|
672
807
|
await run([]);
|
|
673
808
|
} catch (error) {
|
|
674
809
|
if (error instanceof Completing)
|
|
675
|
-
return error
|
|
810
|
+
return error;
|
|
676
811
|
} finally {
|
|
677
812
|
completion.active = false;
|
|
678
813
|
}
|
|
679
|
-
return {};
|
|
814
|
+
return new Completing({});
|
|
815
|
+
}
|
|
816
|
+
function candidateLine(candidate) {
|
|
817
|
+
return typeof candidate === "string" ? candidate : candidate.join("\t");
|
|
818
|
+
}
|
|
819
|
+
function positionalBeingTyped(before, { options, positionals }) {
|
|
820
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
821
|
+
let index = 0;
|
|
822
|
+
let at = 0;
|
|
823
|
+
while (at < before.length) {
|
|
824
|
+
const word = before[at];
|
|
825
|
+
if (word === "--") {
|
|
826
|
+
index += before.length - at - 1;
|
|
827
|
+
break;
|
|
828
|
+
}
|
|
829
|
+
if (!word.startsWith("-"))
|
|
830
|
+
index++;
|
|
831
|
+
else if (takesValue(word))
|
|
832
|
+
at++;
|
|
833
|
+
at++;
|
|
834
|
+
}
|
|
835
|
+
const last = positionals.at(-1);
|
|
836
|
+
if (index < positionals.length)
|
|
837
|
+
return positionals[index];
|
|
838
|
+
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
680
839
|
}
|
|
681
840
|
async function leafCandidates(run, words) {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
841
|
+
const completing = await completingOf(run);
|
|
842
|
+
if ((words.at(-1) ?? "").startsWith("-"))
|
|
843
|
+
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
844
|
+
const flag = words.at(-2);
|
|
845
|
+
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
846
|
+
if (option?.type === "string") {
|
|
847
|
+
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
848
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
849
|
+
}
|
|
850
|
+
const name = positionalBeingTyped(words.slice(0, -1), completing);
|
|
851
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
852
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
685
853
|
}
|
|
686
854
|
async function printCandidates(found) {
|
|
687
855
|
for (const line of await found)
|
|
688
856
|
console.log(line);
|
|
689
857
|
return 0;
|
|
690
858
|
}
|
|
691
|
-
async function runMain({ name, version, run, redact }, argv =
|
|
859
|
+
async function runMain({ name, version, run, redact, usage }, argv = process6.argv.slice(2)) {
|
|
692
860
|
if (argv[0] === COMPLETE)
|
|
693
861
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
694
862
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
695
863
|
console.log(version);
|
|
696
864
|
return 0;
|
|
697
865
|
}
|
|
866
|
+
let code;
|
|
698
867
|
try {
|
|
699
|
-
|
|
868
|
+
code = await run(argv);
|
|
700
869
|
} catch (error) {
|
|
701
|
-
|
|
870
|
+
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
702
871
|
}
|
|
872
|
+
if (usage !== false)
|
|
873
|
+
recordUsage(usageEntry(name, undefined, argv, code));
|
|
874
|
+
return code;
|
|
703
875
|
}
|
|
704
|
-
// ../kit/src/logs.ts
|
|
705
|
-
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
706
876
|
// ../kit/src/secrets.ts
|
|
707
877
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
708
878
|
// ../kit/src/sessions.ts
|
|
@@ -710,7 +880,7 @@ var {Glob } = globalThis.Bun;
|
|
|
710
880
|
var SESSION_FILES = new Glob("*.json");
|
|
711
881
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
712
882
|
// package.json
|
|
713
|
-
var version = "0.5.
|
|
883
|
+
var version = "0.5.2";
|
|
714
884
|
|
|
715
885
|
// src/git.ts
|
|
716
886
|
async function git2(args, env) {
|
|
@@ -782,7 +952,7 @@ var OPTIONS = {
|
|
|
782
952
|
};
|
|
783
953
|
var RENAME = /^[RC]\d*$/;
|
|
784
954
|
var NOT_A_REPOSITORY = /not a git repository/i;
|
|
785
|
-
var LITERAL = { ...
|
|
955
|
+
var LITERAL = { ...process8.env, GIT_LITERAL_PATHSPECS: "1" };
|
|
786
956
|
function messageOf(title, lines, tickets) {
|
|
787
957
|
return [title, lines.join(`
|
|
788
958
|
`), tickets.join(`
|
|
@@ -852,7 +1022,7 @@ ${USAGE}`);
|
|
|
852
1022
|
await unstage(paths);
|
|
853
1023
|
return exitCodeOf(null, signals.signal);
|
|
854
1024
|
}
|
|
855
|
-
const commit = await git2(["commit", "--only", "--cleanup=whitespace", "-m", message, "--", ...paths
|
|
1025
|
+
const commit = await git2(["commit", "--only", "--cleanup=whitespace", "-m", message, "--", ...paths.map((path) => `:(literal)${path}`)]);
|
|
856
1026
|
if (commit.code !== 0) {
|
|
857
1027
|
await unstage(paths);
|
|
858
1028
|
console.error(`gc: git commit failed, the paths were unstaged:
|
|
@@ -869,4 +1039,4 @@ ${(commit.stderr + commit.stdout).trim()}`);
|
|
|
869
1039
|
signals.release();
|
|
870
1040
|
}
|
|
871
1041
|
}
|
|
872
|
-
|
|
1042
|
+
process8.exitCode = await runMain({ name: "gc", version, run: main });
|
package/dist/gst.js
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
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
|
|
12
12
|
import process from "process";
|
|
13
13
|
|
|
14
|
-
// ../../node_modules/.bun/@kaynooo+utils@2.31.
|
|
14
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
15
15
|
function x(s) {
|
|
16
16
|
let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
|
|
17
17
|
if (!/^[a-f0-9]+$/.test(r))
|
|
@@ -231,7 +231,7 @@ class e {
|
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
// ../../node_modules/.bun/@kaynooo+utils@2.31.
|
|
234
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
|
|
235
235
|
var r = 39;
|
|
236
236
|
var o = 49;
|
|
237
237
|
var f2 = "\x1B[";
|
|
@@ -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
|
}
|
|
@@ -353,61 +413,20 @@ class HelpShown extends Exit {
|
|
|
353
413
|
|
|
354
414
|
class Completing {
|
|
355
415
|
options;
|
|
356
|
-
|
|
416
|
+
positionals;
|
|
417
|
+
candidates;
|
|
418
|
+
constructor(options, positionals = [], candidates = {}) {
|
|
357
419
|
this.options = options;
|
|
420
|
+
this.positionals = positionals;
|
|
421
|
+
this.candidates = candidates;
|
|
358
422
|
}
|
|
359
423
|
}
|
|
360
424
|
var completion = { active: false };
|
|
361
|
-
var OPTIONAL = /\[[^\]]+\]/g;
|
|
362
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
363
|
-
var FULL_STOP = /\.$/;
|
|
364
|
-
var DASHES = /^-+/;
|
|
365
|
-
function usageLine(usage, colors = paint(process2.stdout)) {
|
|
366
|
-
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
367
|
-
}
|
|
368
|
-
function helpText(usage, options, colors = paint(process2.stdout), { examples = [], replaces } = {}) {
|
|
369
|
-
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
370
|
-
`);
|
|
371
|
-
}
|
|
372
|
-
function replacesRows(replaces, colors = paint(process2.stdout)) {
|
|
373
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
374
|
-
}
|
|
375
|
-
function wantsHelpJson(env = process2.env) {
|
|
376
|
-
return env.KIT_HELP === "json";
|
|
377
|
-
}
|
|
378
|
-
function description(usage, { examples = [], replaces } = {}) {
|
|
379
|
-
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
380
|
-
`);
|
|
381
|
-
const first = lines[0];
|
|
382
|
-
const colon = first.indexOf(": ");
|
|
383
|
-
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
384
|
-
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
385
|
-
return {
|
|
386
|
-
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
387
|
-
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
388
|
-
...replaces === undefined ? {} : { replaces },
|
|
389
|
-
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
function exampleRows(examples, colors = paint(process2.stdout)) {
|
|
393
|
-
if (examples.length === 0)
|
|
394
|
-
return [];
|
|
395
|
-
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
396
|
-
}
|
|
397
|
-
function optionRows(options, colors = paint(process2.stdout)) {
|
|
398
|
-
const rows = Object.entries(options).map(([name, option]) => {
|
|
399
|
-
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
400
|
-
const value = option.type === "string" ? ` ${colors.dim("<value>")}` : "";
|
|
401
|
-
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? " <value>".length : 0), description: option.description ?? "" };
|
|
402
|
-
});
|
|
403
|
-
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
404
|
-
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
405
|
-
}
|
|
406
425
|
var OUTPUT_OPTIONS = {
|
|
407
426
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
408
427
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
409
428
|
};
|
|
410
|
-
function applyOutput(color, plain, env =
|
|
429
|
+
function applyOutput(color, plain, env = process3.env) {
|
|
411
430
|
const when = plain === true ? "never" : color ?? "auto";
|
|
412
431
|
if (when === "auto")
|
|
413
432
|
return;
|
|
@@ -424,14 +443,13 @@ function applyOutput(color, plain, env = process2.env) {
|
|
|
424
443
|
function parse(args, usage, options, settings = {}) {
|
|
425
444
|
const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
|
|
426
445
|
const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
|
|
446
|
+
const listing = listed(all, settings.allowNegative === true);
|
|
427
447
|
if (completion.active)
|
|
428
|
-
throw new Completing(
|
|
429
|
-
const
|
|
430
|
-
const own = separator === -1 ? args : args.slice(0, separator);
|
|
431
|
-
const rest = separator === -1 ? undefined : args.slice(separator + 1);
|
|
448
|
+
throw new Completing(listing, settings.positionals, settings.candidates);
|
|
449
|
+
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
432
450
|
let parsed;
|
|
433
451
|
try {
|
|
434
|
-
parsed = parseArgs({ args: joinDashValues(own, all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
452
|
+
parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
435
453
|
} catch (error) {
|
|
436
454
|
const message = parseError(error);
|
|
437
455
|
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
@@ -439,12 +457,84 @@ function parse(args, usage, options, settings = {}) {
|
|
|
439
457
|
const values = parsed.values;
|
|
440
458
|
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
441
459
|
if (values.help === true) {
|
|
442
|
-
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage,
|
|
460
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
|
|
443
461
|
throw new HelpShown;
|
|
444
462
|
}
|
|
463
|
+
checkChoices(parsed.values, all);
|
|
464
|
+
checkConflicts(parsed.values, all);
|
|
445
465
|
if (settings.positionals !== undefined)
|
|
446
466
|
checkPositionals(parsed.positionals, settings.positionals);
|
|
447
|
-
return { ...parsed, positionals: parsed.positionals, rest };
|
|
467
|
+
return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
|
|
468
|
+
}
|
|
469
|
+
function splitRest(args, passes) {
|
|
470
|
+
const separator = passes ? args.indexOf("--") : -1;
|
|
471
|
+
return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
|
|
472
|
+
}
|
|
473
|
+
function splitTrailing(args, options, count) {
|
|
474
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
475
|
+
let seen = 0;
|
|
476
|
+
if (count === 0)
|
|
477
|
+
return { own: args, rest: undefined };
|
|
478
|
+
for (let at = 0;at < args.length; at++) {
|
|
479
|
+
const word = args[at];
|
|
480
|
+
if (word === "--")
|
|
481
|
+
break;
|
|
482
|
+
if (word.startsWith("-")) {
|
|
483
|
+
if (takesValue(word))
|
|
484
|
+
at++;
|
|
485
|
+
continue;
|
|
486
|
+
}
|
|
487
|
+
seen++;
|
|
488
|
+
if (seen === count)
|
|
489
|
+
return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
|
|
490
|
+
}
|
|
491
|
+
return { own: args, rest: undefined };
|
|
492
|
+
}
|
|
493
|
+
function listed(options, allowNegative) {
|
|
494
|
+
if (!allowNegative)
|
|
495
|
+
return options;
|
|
496
|
+
return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
|
|
497
|
+
if (option.type !== "boolean" || option.negative === undefined)
|
|
498
|
+
return [[name, option]];
|
|
499
|
+
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
500
|
+
}));
|
|
501
|
+
}
|
|
502
|
+
function withBare(args, options) {
|
|
503
|
+
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
504
|
+
if (bare.size === 0)
|
|
505
|
+
return args;
|
|
506
|
+
const separator = args.indexOf("--");
|
|
507
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
508
|
+
return [...own.flatMap((arg, index) => {
|
|
509
|
+
const optional = bare.get(arg);
|
|
510
|
+
const next = own[index + 1];
|
|
511
|
+
const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
|
|
512
|
+
return optional === undefined || value ? [arg] : [arg, optional.bare];
|
|
513
|
+
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
514
|
+
}
|
|
515
|
+
function checkConflicts(values, options) {
|
|
516
|
+
const given = (name) => values[name] !== undefined && values[name] !== false;
|
|
517
|
+
for (const [name, { conflicts = [] }] of Object.entries(options)) {
|
|
518
|
+
const other = given(name) ? conflicts.find(given) : undefined;
|
|
519
|
+
if (other !== undefined)
|
|
520
|
+
badUsage(`--${name} cannot be used with --${other}`);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
function checkChoices(values, options) {
|
|
524
|
+
for (const [name, option] of Object.entries(options)) {
|
|
525
|
+
if (option.choices === undefined)
|
|
526
|
+
continue;
|
|
527
|
+
const given = values[name];
|
|
528
|
+
for (const value of Array.isArray(given) ? given : [given]) {
|
|
529
|
+
if (typeof value === "string")
|
|
530
|
+
oneOf(value, name, option.choices);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
function oneOf(value, name, choices) {
|
|
535
|
+
if (!choices.includes(value))
|
|
536
|
+
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
|
|
537
|
+
return value;
|
|
448
538
|
}
|
|
449
539
|
function checkPositionals(given, names) {
|
|
450
540
|
const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
|
|
@@ -493,18 +583,9 @@ function nearestOption(message, options, allowNegative) {
|
|
|
493
583
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
494
584
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
495
585
|
}
|
|
496
|
-
var WHOLE = /^\d+$/;
|
|
497
|
-
function wholeNumber(value, name, fallback, min = 1) {
|
|
498
|
-
if (value === undefined)
|
|
499
|
-
return fallback;
|
|
500
|
-
const number = Number(value);
|
|
501
|
-
if (!WHOLE.test(value) || !Number.isSafeInteger(number) || number < min)
|
|
502
|
-
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
503
|
-
return number;
|
|
504
|
-
}
|
|
505
586
|
// ../kit/src/process.ts
|
|
506
587
|
import { constants } from "os";
|
|
507
|
-
import
|
|
588
|
+
import process4 from "process";
|
|
508
589
|
var KILL_GRACE_MS = 2000;
|
|
509
590
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
510
591
|
function exitCodeOf(code, signal) {
|
|
@@ -526,7 +607,7 @@ function holdSignals(cleanup) {
|
|
|
526
607
|
},
|
|
527
608
|
release: () => {
|
|
528
609
|
for (const signal of SIGNALS)
|
|
529
|
-
|
|
610
|
+
process4.off(signal, onSignal);
|
|
530
611
|
}
|
|
531
612
|
};
|
|
532
613
|
function onSignal(signal) {
|
|
@@ -539,10 +620,10 @@ function holdSignals(cleanup) {
|
|
|
539
620
|
return;
|
|
540
621
|
held.release();
|
|
541
622
|
cleanup(signal);
|
|
542
|
-
|
|
623
|
+
process4.kill(process4.pid, signal);
|
|
543
624
|
}
|
|
544
625
|
for (const signal of SIGNALS)
|
|
545
|
-
|
|
626
|
+
process4.on(signal, onSignal);
|
|
546
627
|
return held;
|
|
547
628
|
}
|
|
548
629
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -556,7 +637,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
556
637
|
return;
|
|
557
638
|
try {
|
|
558
639
|
if (grouped)
|
|
559
|
-
|
|
640
|
+
process4.kill(-proc.pid, killing);
|
|
560
641
|
else
|
|
561
642
|
proc.kill(killing);
|
|
562
643
|
} catch {}
|
|
@@ -630,15 +711,67 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
630
711
|
var RESET_STYLE = `${ESC}[0m`;
|
|
631
712
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
632
713
|
// ../kit/src/cli.ts
|
|
633
|
-
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
|
|
634
767
|
var LEVEL_OPTIONS = {
|
|
635
768
|
...OUTPUT_OPTIONS,
|
|
636
769
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
637
770
|
};
|
|
638
771
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
639
772
|
function printError(prefix, message, hint, cause) {
|
|
640
|
-
const colors = paint(
|
|
641
|
-
const styled = takesControlCodes(
|
|
773
|
+
const colors = paint(process6.stderr);
|
|
774
|
+
const styled = takesControlCodes(process6.stderr);
|
|
642
775
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
643
776
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
644
777
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -660,49 +793,86 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
|
660
793
|
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
661
794
|
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
662
795
|
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
796
|
+
if (error instanceof UsageError)
|
|
797
|
+
noteUsageError(error.message);
|
|
663
798
|
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
664
799
|
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
665
800
|
return error instanceof Exit ? error.code : 1;
|
|
666
801
|
}
|
|
667
802
|
var COMPLETE = "__complete";
|
|
668
803
|
var FILES = "__files__";
|
|
669
|
-
async function
|
|
804
|
+
async function completingOf(run) {
|
|
670
805
|
completion.active = true;
|
|
671
806
|
try {
|
|
672
807
|
await run([]);
|
|
673
808
|
} catch (error) {
|
|
674
809
|
if (error instanceof Completing)
|
|
675
|
-
return error
|
|
810
|
+
return error;
|
|
676
811
|
} finally {
|
|
677
812
|
completion.active = false;
|
|
678
813
|
}
|
|
679
|
-
return {};
|
|
814
|
+
return new Completing({});
|
|
815
|
+
}
|
|
816
|
+
function candidateLine(candidate) {
|
|
817
|
+
return typeof candidate === "string" ? candidate : candidate.join("\t");
|
|
818
|
+
}
|
|
819
|
+
function positionalBeingTyped(before, { options, positionals }) {
|
|
820
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
821
|
+
let index = 0;
|
|
822
|
+
let at = 0;
|
|
823
|
+
while (at < before.length) {
|
|
824
|
+
const word = before[at];
|
|
825
|
+
if (word === "--") {
|
|
826
|
+
index += before.length - at - 1;
|
|
827
|
+
break;
|
|
828
|
+
}
|
|
829
|
+
if (!word.startsWith("-"))
|
|
830
|
+
index++;
|
|
831
|
+
else if (takesValue(word))
|
|
832
|
+
at++;
|
|
833
|
+
at++;
|
|
834
|
+
}
|
|
835
|
+
const last = positionals.at(-1);
|
|
836
|
+
if (index < positionals.length)
|
|
837
|
+
return positionals[index];
|
|
838
|
+
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
680
839
|
}
|
|
681
840
|
async function leafCandidates(run, words) {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
841
|
+
const completing = await completingOf(run);
|
|
842
|
+
if ((words.at(-1) ?? "").startsWith("-"))
|
|
843
|
+
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
844
|
+
const flag = words.at(-2);
|
|
845
|
+
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
846
|
+
if (option?.type === "string") {
|
|
847
|
+
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
848
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
849
|
+
}
|
|
850
|
+
const name = positionalBeingTyped(words.slice(0, -1), completing);
|
|
851
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
852
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
685
853
|
}
|
|
686
854
|
async function printCandidates(found) {
|
|
687
855
|
for (const line of await found)
|
|
688
856
|
console.log(line);
|
|
689
857
|
return 0;
|
|
690
858
|
}
|
|
691
|
-
async function runMain({ name, version, run, redact }, argv =
|
|
859
|
+
async function runMain({ name, version, run, redact, usage }, argv = process6.argv.slice(2)) {
|
|
692
860
|
if (argv[0] === COMPLETE)
|
|
693
861
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
694
862
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
695
863
|
console.log(version);
|
|
696
864
|
return 0;
|
|
697
865
|
}
|
|
866
|
+
let code;
|
|
698
867
|
try {
|
|
699
|
-
|
|
868
|
+
code = await run(argv);
|
|
700
869
|
} catch (error) {
|
|
701
|
-
|
|
870
|
+
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
702
871
|
}
|
|
872
|
+
if (usage !== false)
|
|
873
|
+
recordUsage(usageEntry(name, undefined, argv, code));
|
|
874
|
+
return code;
|
|
703
875
|
}
|
|
704
|
-
// ../kit/src/logs.ts
|
|
705
|
-
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
706
876
|
// ../kit/src/secrets.ts
|
|
707
877
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
708
878
|
// ../kit/src/sessions.ts
|
|
@@ -710,7 +880,7 @@ var {Glob } = globalThis.Bun;
|
|
|
710
880
|
var SESSION_FILES = new Glob("*.json");
|
|
711
881
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
712
882
|
// package.json
|
|
713
|
-
var version = "0.5.
|
|
883
|
+
var version = "0.5.2";
|
|
714
884
|
|
|
715
885
|
// src/git.ts
|
|
716
886
|
async function git2(args, env) {
|
|
@@ -851,4 +1021,4 @@ ${USAGE}`);
|
|
|
851
1021
|
`));
|
|
852
1022
|
return 0;
|
|
853
1023
|
}
|
|
854
|
-
|
|
1024
|
+
process8.exitCode = await runMain({ name: "gst", version, run: main });
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-git",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.2",
|
|
5
5
|
"description": "gst and gc: a repository's state in one call, and a commit of exactly the paths given, its message checked before anything is staged.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -42,6 +42,6 @@
|
|
|
42
42
|
"gc": "$npm_execpath src/gc.ts"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@kaynooo/cli-kit": "0.
|
|
45
|
+
"@kaynooo/cli-kit": "0.20.0"
|
|
46
46
|
}
|
|
47
47
|
}
|