@kaynooo/cli-git 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gc.js +130 -20
- package/dist/gst.js +129 -19
- package/package.json +2 -2
package/dist/gc.js
CHANGED
|
@@ -11,7 +11,7 @@ import { parseArgs } from "util";
|
|
|
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[";
|
|
@@ -353,8 +353,12 @@ class HelpShown extends Exit {
|
|
|
353
353
|
|
|
354
354
|
class Completing {
|
|
355
355
|
options;
|
|
356
|
-
|
|
356
|
+
positionals;
|
|
357
|
+
candidates;
|
|
358
|
+
constructor(options, positionals = [], candidates = {}) {
|
|
357
359
|
this.options = options;
|
|
360
|
+
this.positionals = positionals;
|
|
361
|
+
this.candidates = candidates;
|
|
358
362
|
}
|
|
359
363
|
}
|
|
360
364
|
var completion = { active: false };
|
|
@@ -397,8 +401,10 @@ function exampleRows(examples, colors = paint(process2.stdout)) {
|
|
|
397
401
|
function optionRows(options, colors = paint(process2.stdout)) {
|
|
398
402
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
399
403
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
400
|
-
const
|
|
401
|
-
|
|
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 ?? "" };
|
|
402
408
|
});
|
|
403
409
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
404
410
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
@@ -424,14 +430,13 @@ function applyOutput(color, plain, env = process2.env) {
|
|
|
424
430
|
function parse(args, usage, options, settings = {}) {
|
|
425
431
|
const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
|
|
426
432
|
const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
|
|
433
|
+
const listing = listed(all, settings.allowNegative === true);
|
|
427
434
|
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);
|
|
435
|
+
throw new Completing(listing, settings.positionals, settings.candidates);
|
|
436
|
+
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
432
437
|
let parsed;
|
|
433
438
|
try {
|
|
434
|
-
parsed = parseArgs({ args: joinDashValues(own, all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
439
|
+
parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
435
440
|
} catch (error) {
|
|
436
441
|
const message = parseError(error);
|
|
437
442
|
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
@@ -439,12 +444,84 @@ function parse(args, usage, options, settings = {}) {
|
|
|
439
444
|
const values = parsed.values;
|
|
440
445
|
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
441
446
|
if (values.help === true) {
|
|
442
|
-
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage,
|
|
447
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
|
|
443
448
|
throw new HelpShown;
|
|
444
449
|
}
|
|
450
|
+
checkChoices(parsed.values, all);
|
|
451
|
+
checkConflicts(parsed.values, all);
|
|
445
452
|
if (settings.positionals !== undefined)
|
|
446
453
|
checkPositionals(parsed.positionals, settings.positionals);
|
|
447
|
-
return { ...parsed, positionals: parsed.positionals, rest };
|
|
454
|
+
return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
|
|
455
|
+
}
|
|
456
|
+
function splitRest(args, passes) {
|
|
457
|
+
const separator = passes ? args.indexOf("--") : -1;
|
|
458
|
+
return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
|
|
459
|
+
}
|
|
460
|
+
function splitTrailing(args, options, count) {
|
|
461
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
462
|
+
let seen = 0;
|
|
463
|
+
if (count === 0)
|
|
464
|
+
return { own: args, rest: undefined };
|
|
465
|
+
for (let at = 0;at < args.length; at++) {
|
|
466
|
+
const word = args[at];
|
|
467
|
+
if (word === "--")
|
|
468
|
+
break;
|
|
469
|
+
if (word.startsWith("-")) {
|
|
470
|
+
if (takesValue(word))
|
|
471
|
+
at++;
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
seen++;
|
|
475
|
+
if (seen === count)
|
|
476
|
+
return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
|
|
477
|
+
}
|
|
478
|
+
return { own: args, rest: undefined };
|
|
479
|
+
}
|
|
480
|
+
function listed(options, allowNegative) {
|
|
481
|
+
if (!allowNegative)
|
|
482
|
+
return options;
|
|
483
|
+
return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
|
|
484
|
+
if (option.type !== "boolean" || option.negative === undefined)
|
|
485
|
+
return [[name, option]];
|
|
486
|
+
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
487
|
+
}));
|
|
488
|
+
}
|
|
489
|
+
function withBare(args, options) {
|
|
490
|
+
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
491
|
+
if (bare.size === 0)
|
|
492
|
+
return args;
|
|
493
|
+
const separator = args.indexOf("--");
|
|
494
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
495
|
+
return [...own.flatMap((arg, index) => {
|
|
496
|
+
const optional = bare.get(arg);
|
|
497
|
+
const next = own[index + 1];
|
|
498
|
+
const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
|
|
499
|
+
return optional === undefined || value ? [arg] : [arg, optional.bare];
|
|
500
|
+
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
501
|
+
}
|
|
502
|
+
function checkConflicts(values, options) {
|
|
503
|
+
const given = (name) => values[name] !== undefined && values[name] !== false;
|
|
504
|
+
for (const [name, { conflicts = [] }] of Object.entries(options)) {
|
|
505
|
+
const other = given(name) ? conflicts.find(given) : undefined;
|
|
506
|
+
if (other !== undefined)
|
|
507
|
+
badUsage(`--${name} cannot be used with --${other}`);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
function checkChoices(values, options) {
|
|
511
|
+
for (const [name, option] of Object.entries(options)) {
|
|
512
|
+
if (option.choices === undefined)
|
|
513
|
+
continue;
|
|
514
|
+
const given = values[name];
|
|
515
|
+
for (const value of Array.isArray(given) ? given : [given]) {
|
|
516
|
+
if (typeof value === "string")
|
|
517
|
+
oneOf(value, name, option.choices);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
function oneOf(value, name, choices) {
|
|
522
|
+
if (!choices.includes(value))
|
|
523
|
+
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
|
|
524
|
+
return value;
|
|
448
525
|
}
|
|
449
526
|
function checkPositionals(given, names) {
|
|
450
527
|
const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
|
|
@@ -666,22 +743,55 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
|
666
743
|
}
|
|
667
744
|
var COMPLETE = "__complete";
|
|
668
745
|
var FILES = "__files__";
|
|
669
|
-
async function
|
|
746
|
+
async function completingOf(run) {
|
|
670
747
|
completion.active = true;
|
|
671
748
|
try {
|
|
672
749
|
await run([]);
|
|
673
750
|
} catch (error) {
|
|
674
751
|
if (error instanceof Completing)
|
|
675
|
-
return error
|
|
752
|
+
return error;
|
|
676
753
|
} finally {
|
|
677
754
|
completion.active = false;
|
|
678
755
|
}
|
|
679
|
-
return {};
|
|
756
|
+
return new Completing({});
|
|
757
|
+
}
|
|
758
|
+
function candidateLine(candidate) {
|
|
759
|
+
return typeof candidate === "string" ? candidate : candidate.join("\t");
|
|
760
|
+
}
|
|
761
|
+
function positionalBeingTyped(before, { options, positionals }) {
|
|
762
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
763
|
+
let index = 0;
|
|
764
|
+
let at = 0;
|
|
765
|
+
while (at < before.length) {
|
|
766
|
+
const word = before[at];
|
|
767
|
+
if (word === "--") {
|
|
768
|
+
index += before.length - at - 1;
|
|
769
|
+
break;
|
|
770
|
+
}
|
|
771
|
+
if (!word.startsWith("-"))
|
|
772
|
+
index++;
|
|
773
|
+
else if (takesValue(word))
|
|
774
|
+
at++;
|
|
775
|
+
at++;
|
|
776
|
+
}
|
|
777
|
+
const last = positionals.at(-1);
|
|
778
|
+
if (index < positionals.length)
|
|
779
|
+
return positionals[index];
|
|
780
|
+
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
680
781
|
}
|
|
681
782
|
async function leafCandidates(run, words) {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
783
|
+
const completing = await completingOf(run);
|
|
784
|
+
if ((words.at(-1) ?? "").startsWith("-"))
|
|
785
|
+
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
786
|
+
const flag = words.at(-2);
|
|
787
|
+
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
788
|
+
if (option?.type === "string") {
|
|
789
|
+
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
790
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
791
|
+
}
|
|
792
|
+
const name = positionalBeingTyped(words.slice(0, -1), completing);
|
|
793
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
794
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
685
795
|
}
|
|
686
796
|
async function printCandidates(found) {
|
|
687
797
|
for (const line of await found)
|
|
@@ -710,7 +820,7 @@ var {Glob } = globalThis.Bun;
|
|
|
710
820
|
var SESSION_FILES = new Glob("*.json");
|
|
711
821
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
712
822
|
// package.json
|
|
713
|
-
var version = "0.5.
|
|
823
|
+
var version = "0.5.1";
|
|
714
824
|
|
|
715
825
|
// src/git.ts
|
|
716
826
|
async function git2(args, env) {
|
|
@@ -852,7 +962,7 @@ ${USAGE}`);
|
|
|
852
962
|
await unstage(paths);
|
|
853
963
|
return exitCodeOf(null, signals.signal);
|
|
854
964
|
}
|
|
855
|
-
const commit = await git2(["commit", "--only", "--cleanup=whitespace", "-m", message, "--", ...paths
|
|
965
|
+
const commit = await git2(["commit", "--only", "--cleanup=whitespace", "-m", message, "--", ...paths.map((path) => `:(literal)${path}`)]);
|
|
856
966
|
if (commit.code !== 0) {
|
|
857
967
|
await unstage(paths);
|
|
858
968
|
console.error(`gc: git commit failed, the paths were unstaged:
|
package/dist/gst.js
CHANGED
|
@@ -11,7 +11,7 @@ import { parseArgs } from "util";
|
|
|
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[";
|
|
@@ -353,8 +353,12 @@ class HelpShown extends Exit {
|
|
|
353
353
|
|
|
354
354
|
class Completing {
|
|
355
355
|
options;
|
|
356
|
-
|
|
356
|
+
positionals;
|
|
357
|
+
candidates;
|
|
358
|
+
constructor(options, positionals = [], candidates = {}) {
|
|
357
359
|
this.options = options;
|
|
360
|
+
this.positionals = positionals;
|
|
361
|
+
this.candidates = candidates;
|
|
358
362
|
}
|
|
359
363
|
}
|
|
360
364
|
var completion = { active: false };
|
|
@@ -397,8 +401,10 @@ function exampleRows(examples, colors = paint(process2.stdout)) {
|
|
|
397
401
|
function optionRows(options, colors = paint(process2.stdout)) {
|
|
398
402
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
399
403
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
400
|
-
const
|
|
401
|
-
|
|
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 ?? "" };
|
|
402
408
|
});
|
|
403
409
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
404
410
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
@@ -424,14 +430,13 @@ function applyOutput(color, plain, env = process2.env) {
|
|
|
424
430
|
function parse(args, usage, options, settings = {}) {
|
|
425
431
|
const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
|
|
426
432
|
const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
|
|
433
|
+
const listing = listed(all, settings.allowNegative === true);
|
|
427
434
|
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);
|
|
435
|
+
throw new Completing(listing, settings.positionals, settings.candidates);
|
|
436
|
+
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
432
437
|
let parsed;
|
|
433
438
|
try {
|
|
434
|
-
parsed = parseArgs({ args: joinDashValues(own, all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
439
|
+
parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
435
440
|
} catch (error) {
|
|
436
441
|
const message = parseError(error);
|
|
437
442
|
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
@@ -439,12 +444,84 @@ function parse(args, usage, options, settings = {}) {
|
|
|
439
444
|
const values = parsed.values;
|
|
440
445
|
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
441
446
|
if (values.help === true) {
|
|
442
|
-
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage,
|
|
447
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
|
|
443
448
|
throw new HelpShown;
|
|
444
449
|
}
|
|
450
|
+
checkChoices(parsed.values, all);
|
|
451
|
+
checkConflicts(parsed.values, all);
|
|
445
452
|
if (settings.positionals !== undefined)
|
|
446
453
|
checkPositionals(parsed.positionals, settings.positionals);
|
|
447
|
-
return { ...parsed, positionals: parsed.positionals, rest };
|
|
454
|
+
return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
|
|
455
|
+
}
|
|
456
|
+
function splitRest(args, passes) {
|
|
457
|
+
const separator = passes ? args.indexOf("--") : -1;
|
|
458
|
+
return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
|
|
459
|
+
}
|
|
460
|
+
function splitTrailing(args, options, count) {
|
|
461
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
462
|
+
let seen = 0;
|
|
463
|
+
if (count === 0)
|
|
464
|
+
return { own: args, rest: undefined };
|
|
465
|
+
for (let at = 0;at < args.length; at++) {
|
|
466
|
+
const word = args[at];
|
|
467
|
+
if (word === "--")
|
|
468
|
+
break;
|
|
469
|
+
if (word.startsWith("-")) {
|
|
470
|
+
if (takesValue(word))
|
|
471
|
+
at++;
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
seen++;
|
|
475
|
+
if (seen === count)
|
|
476
|
+
return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
|
|
477
|
+
}
|
|
478
|
+
return { own: args, rest: undefined };
|
|
479
|
+
}
|
|
480
|
+
function listed(options, allowNegative) {
|
|
481
|
+
if (!allowNegative)
|
|
482
|
+
return options;
|
|
483
|
+
return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
|
|
484
|
+
if (option.type !== "boolean" || option.negative === undefined)
|
|
485
|
+
return [[name, option]];
|
|
486
|
+
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
487
|
+
}));
|
|
488
|
+
}
|
|
489
|
+
function withBare(args, options) {
|
|
490
|
+
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
491
|
+
if (bare.size === 0)
|
|
492
|
+
return args;
|
|
493
|
+
const separator = args.indexOf("--");
|
|
494
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
495
|
+
return [...own.flatMap((arg, index) => {
|
|
496
|
+
const optional = bare.get(arg);
|
|
497
|
+
const next = own[index + 1];
|
|
498
|
+
const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
|
|
499
|
+
return optional === undefined || value ? [arg] : [arg, optional.bare];
|
|
500
|
+
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
501
|
+
}
|
|
502
|
+
function checkConflicts(values, options) {
|
|
503
|
+
const given = (name) => values[name] !== undefined && values[name] !== false;
|
|
504
|
+
for (const [name, { conflicts = [] }] of Object.entries(options)) {
|
|
505
|
+
const other = given(name) ? conflicts.find(given) : undefined;
|
|
506
|
+
if (other !== undefined)
|
|
507
|
+
badUsage(`--${name} cannot be used with --${other}`);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
function checkChoices(values, options) {
|
|
511
|
+
for (const [name, option] of Object.entries(options)) {
|
|
512
|
+
if (option.choices === undefined)
|
|
513
|
+
continue;
|
|
514
|
+
const given = values[name];
|
|
515
|
+
for (const value of Array.isArray(given) ? given : [given]) {
|
|
516
|
+
if (typeof value === "string")
|
|
517
|
+
oneOf(value, name, option.choices);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
function oneOf(value, name, choices) {
|
|
522
|
+
if (!choices.includes(value))
|
|
523
|
+
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
|
|
524
|
+
return value;
|
|
448
525
|
}
|
|
449
526
|
function checkPositionals(given, names) {
|
|
450
527
|
const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
|
|
@@ -666,22 +743,55 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
|
666
743
|
}
|
|
667
744
|
var COMPLETE = "__complete";
|
|
668
745
|
var FILES = "__files__";
|
|
669
|
-
async function
|
|
746
|
+
async function completingOf(run) {
|
|
670
747
|
completion.active = true;
|
|
671
748
|
try {
|
|
672
749
|
await run([]);
|
|
673
750
|
} catch (error) {
|
|
674
751
|
if (error instanceof Completing)
|
|
675
|
-
return error
|
|
752
|
+
return error;
|
|
676
753
|
} finally {
|
|
677
754
|
completion.active = false;
|
|
678
755
|
}
|
|
679
|
-
return {};
|
|
756
|
+
return new Completing({});
|
|
757
|
+
}
|
|
758
|
+
function candidateLine(candidate) {
|
|
759
|
+
return typeof candidate === "string" ? candidate : candidate.join("\t");
|
|
760
|
+
}
|
|
761
|
+
function positionalBeingTyped(before, { options, positionals }) {
|
|
762
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
763
|
+
let index = 0;
|
|
764
|
+
let at = 0;
|
|
765
|
+
while (at < before.length) {
|
|
766
|
+
const word = before[at];
|
|
767
|
+
if (word === "--") {
|
|
768
|
+
index += before.length - at - 1;
|
|
769
|
+
break;
|
|
770
|
+
}
|
|
771
|
+
if (!word.startsWith("-"))
|
|
772
|
+
index++;
|
|
773
|
+
else if (takesValue(word))
|
|
774
|
+
at++;
|
|
775
|
+
at++;
|
|
776
|
+
}
|
|
777
|
+
const last = positionals.at(-1);
|
|
778
|
+
if (index < positionals.length)
|
|
779
|
+
return positionals[index];
|
|
780
|
+
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
680
781
|
}
|
|
681
782
|
async function leafCandidates(run, words) {
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
783
|
+
const completing = await completingOf(run);
|
|
784
|
+
if ((words.at(-1) ?? "").startsWith("-"))
|
|
785
|
+
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
786
|
+
const flag = words.at(-2);
|
|
787
|
+
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
788
|
+
if (option?.type === "string") {
|
|
789
|
+
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
790
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
791
|
+
}
|
|
792
|
+
const name = positionalBeingTyped(words.slice(0, -1), completing);
|
|
793
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
794
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
685
795
|
}
|
|
686
796
|
async function printCandidates(found) {
|
|
687
797
|
for (const line of await found)
|
|
@@ -710,7 +820,7 @@ var {Glob } = globalThis.Bun;
|
|
|
710
820
|
var SESSION_FILES = new Glob("*.json");
|
|
711
821
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
712
822
|
// package.json
|
|
713
|
-
var version = "0.5.
|
|
823
|
+
var version = "0.5.1";
|
|
714
824
|
|
|
715
825
|
// src/git.ts
|
|
716
826
|
async function git2(args, env) {
|
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.1",
|
|
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.17.0"
|
|
46
46
|
}
|
|
47
47
|
}
|