@kaynooo/cli-git 0.13.0 → 0.14.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 +15 -4
- package/dist/gb.js +183 -59
- package/dist/gc.js +159 -39
- package/dist/gp.js +1369 -0
- package/dist/gst.js +271 -63
- package/package.json +8 -6
package/dist/gst.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/gst.ts
|
|
5
|
-
import
|
|
5
|
+
import process18 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process9 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -10,6 +10,24 @@ import { parseArgs } from "util";
|
|
|
10
10
|
// ../kit/src/format.ts
|
|
11
11
|
import process7 from "process";
|
|
12
12
|
|
|
13
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
14
|
+
var N = new Map;
|
|
15
|
+
var Nt = /\s+\S*$/;
|
|
16
|
+
var Y = /\s/;
|
|
17
|
+
function ko(t, e, r = "...") {
|
|
18
|
+
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
19
|
+
if (t.length <= e)
|
|
20
|
+
return t;
|
|
21
|
+
let l = Math.max(0, e), c = t.substring(0, Math.max(0, s ? l - n.length : l));
|
|
22
|
+
if (o && !Y.test(t[c.length] ?? " "))
|
|
23
|
+
c = c.replace(Nt, "") || c;
|
|
24
|
+
if (o)
|
|
25
|
+
c = c.trimEnd();
|
|
26
|
+
return s ? (c + n).slice(0, l) : c + n;
|
|
27
|
+
}
|
|
28
|
+
var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
29
|
+
var z = new Map;
|
|
30
|
+
|
|
13
31
|
// ../kit/src/mode.ts
|
|
14
32
|
import process2 from "process";
|
|
15
33
|
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
@@ -35,10 +53,10 @@ function isInteractive(streams = process2) {
|
|
|
35
53
|
import process6 from "process";
|
|
36
54
|
|
|
37
55
|
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
38
|
-
var
|
|
56
|
+
var G2 = /^[a-f0-9]+$/i;
|
|
39
57
|
function b(r) {
|
|
40
58
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
41
|
-
if (!
|
|
59
|
+
if (!G2.test(e))
|
|
42
60
|
return [0, 0, 0];
|
|
43
61
|
if (e.length === 3 || e.length === 4)
|
|
44
62
|
return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
|
|
@@ -46,7 +64,7 @@ function b(r) {
|
|
|
46
64
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
47
65
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
48
66
|
}
|
|
49
|
-
var
|
|
67
|
+
var B2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
50
68
|
let [l, n, c] = b(r);
|
|
51
69
|
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
52
70
|
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
@@ -64,7 +82,7 @@ function f(r, e = []) {
|
|
|
64
82
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
65
83
|
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
66
84
|
return new Proxy(c, { get(t, i) {
|
|
67
|
-
let a =
|
|
85
|
+
let a = B2[i];
|
|
68
86
|
if (Array.isArray(a)) {
|
|
69
87
|
let s = g.get(i);
|
|
70
88
|
if (s === undefined)
|
|
@@ -304,12 +322,22 @@ function activeTheme() {
|
|
|
304
322
|
}
|
|
305
323
|
|
|
306
324
|
// ../kit/src/style.ts
|
|
325
|
+
var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
307
326
|
function takesControlCodes(stream, env = process6.env) {
|
|
308
327
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
309
328
|
}
|
|
310
329
|
function paint(stream, env = process6.env) {
|
|
311
330
|
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
312
331
|
}
|
|
332
|
+
function marked(mark, text, stream, detail, env = process6.env) {
|
|
333
|
+
const colors = paint(stream, env);
|
|
334
|
+
let head = MARK_WORDS[mark];
|
|
335
|
+
if (takesControlCodes(stream, env)) {
|
|
336
|
+
const { theme } = activeTheme();
|
|
337
|
+
head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
|
|
338
|
+
}
|
|
339
|
+
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
340
|
+
}
|
|
313
341
|
function role(name, stream, env = process6.env) {
|
|
314
342
|
const colors = paint(stream, env);
|
|
315
343
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
@@ -324,11 +352,78 @@ var STATUS_WORDS = {
|
|
|
324
352
|
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
325
353
|
|
|
326
354
|
// ../kit/src/format.ts
|
|
355
|
+
var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
356
|
+
function formatSeconds(total) {
|
|
357
|
+
let rest = Math.max(0, Math.round(total));
|
|
358
|
+
const amounts = UNITS.map(([unit, size]) => {
|
|
359
|
+
const amount = Math.floor(rest / size);
|
|
360
|
+
rest -= amount * size;
|
|
361
|
+
return `${amount}${unit}`;
|
|
362
|
+
});
|
|
363
|
+
const first = amounts.findIndex((amount) => !amount.startsWith("0"));
|
|
364
|
+
if (first === -1)
|
|
365
|
+
return "0s";
|
|
366
|
+
const next = amounts[first + 1];
|
|
367
|
+
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
368
|
+
}
|
|
327
369
|
function upTo(text, separator) {
|
|
328
370
|
const end = text.indexOf(separator);
|
|
329
371
|
return end === -1 ? text : text.slice(0, end);
|
|
330
372
|
}
|
|
373
|
+
function formatAge(date, now = Date.now()) {
|
|
374
|
+
const at = typeof date === "number" ? date : Date.parse(date);
|
|
375
|
+
if (Number.isNaN(at))
|
|
376
|
+
return "-";
|
|
377
|
+
const seconds = (now - at) / 1000;
|
|
378
|
+
return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
|
|
379
|
+
}
|
|
380
|
+
function truncate(text, width) {
|
|
381
|
+
return ko(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
382
|
+
}
|
|
383
|
+
var LINE_BREAKS = /\s*\n\s*/g;
|
|
331
384
|
var ESCAPE = String.fromCharCode(27);
|
|
385
|
+
function textWidth(text) {
|
|
386
|
+
return Bun.stringWidth(text);
|
|
387
|
+
}
|
|
388
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
|
|
389
|
+
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
390
|
+
if (outputMode(stream, env) === "agent")
|
|
391
|
+
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
392
|
+
`);
|
|
393
|
+
const widths = [];
|
|
394
|
+
for (const row of cells) {
|
|
395
|
+
for (const [index, cell] of row.entries())
|
|
396
|
+
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
397
|
+
}
|
|
398
|
+
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
399
|
+
const colors = paint(stream);
|
|
400
|
+
const lines = shown.map((row) => row.map((cell, index) => {
|
|
401
|
+
const width = widths[index] ?? 0;
|
|
402
|
+
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
403
|
+
if (align[index] === "right")
|
|
404
|
+
return `${gap}${cell}`;
|
|
405
|
+
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
406
|
+
}).join(" ").trimEnd());
|
|
407
|
+
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
408
|
+
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
409
|
+
`);
|
|
410
|
+
}
|
|
411
|
+
function narrow(rows, widths, limit) {
|
|
412
|
+
const used = () => widths.reduce((sum, width) => sum + width, 0) + 2 * Math.max(0, widths.length - 1);
|
|
413
|
+
const cuttable = (index) => rows.every((row) => !(row[index] ?? "").includes(ESCAPE));
|
|
414
|
+
const floor = 8;
|
|
415
|
+
while (used() > limit) {
|
|
416
|
+
let widest = -1;
|
|
417
|
+
for (const [index, width] of widths.entries()) {
|
|
418
|
+
if (cuttable(index) && width > floor && width > (widths[widest] ?? 0))
|
|
419
|
+
widest = index;
|
|
420
|
+
}
|
|
421
|
+
if (widest === -1)
|
|
422
|
+
break;
|
|
423
|
+
widths[widest] = Math.max(floor, (widths[widest] ?? 0) - (used() - limit));
|
|
424
|
+
}
|
|
425
|
+
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
426
|
+
}
|
|
332
427
|
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
333
428
|
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
334
429
|
}
|
|
@@ -651,9 +746,33 @@ function nearestOption(message, options, allowNegative) {
|
|
|
651
746
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
652
747
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
653
748
|
}
|
|
749
|
+
// ../kit/src/argv.ts
|
|
750
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
751
|
+
import { resolve as resolve3 } from "path";
|
|
752
|
+
import process10 from "process";
|
|
753
|
+
function commandLine() {
|
|
754
|
+
try {
|
|
755
|
+
return readFileSync2("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
756
|
+
} catch {
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
function realPath(word) {
|
|
761
|
+
try {
|
|
762
|
+
return realpathSync(resolve3(word));
|
|
763
|
+
} catch {
|
|
764
|
+
return;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
|
|
768
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
769
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
770
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
771
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
772
|
+
}
|
|
654
773
|
// ../kit/src/process.ts
|
|
655
774
|
import { constants } from "os";
|
|
656
|
-
import
|
|
775
|
+
import process11 from "process";
|
|
657
776
|
var KILL_GRACE_MS = 2000;
|
|
658
777
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
659
778
|
function exitCodeOf(code, signal) {
|
|
@@ -675,7 +794,7 @@ function holdSignals(cleanup) {
|
|
|
675
794
|
},
|
|
676
795
|
release: () => {
|
|
677
796
|
for (const signal of SIGNALS)
|
|
678
|
-
|
|
797
|
+
process11.off(signal, onSignal);
|
|
679
798
|
}
|
|
680
799
|
};
|
|
681
800
|
function onSignal(signal) {
|
|
@@ -688,10 +807,10 @@ function holdSignals(cleanup) {
|
|
|
688
807
|
return;
|
|
689
808
|
held.release();
|
|
690
809
|
cleanup(signal);
|
|
691
|
-
|
|
810
|
+
process11.kill(process11.pid, signal);
|
|
692
811
|
}
|
|
693
812
|
for (const signal of SIGNALS)
|
|
694
|
-
|
|
813
|
+
process11.on(signal, onSignal);
|
|
695
814
|
return held;
|
|
696
815
|
}
|
|
697
816
|
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
@@ -705,7 +824,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
705
824
|
return;
|
|
706
825
|
try {
|
|
707
826
|
if (grouped)
|
|
708
|
-
|
|
827
|
+
process11.kill(-proc.pid, killing);
|
|
709
828
|
else
|
|
710
829
|
proc.kill(killing);
|
|
711
830
|
} catch {}
|
|
@@ -779,15 +898,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
779
898
|
var RESET_STYLE = `${ESC}[0m`;
|
|
780
899
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
781
900
|
// ../kit/src/cli.ts
|
|
782
|
-
import { readFileSync as
|
|
901
|
+
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
783
902
|
import { dirname as dirname3, join as join5 } from "path";
|
|
784
|
-
import
|
|
903
|
+
import process13 from "process";
|
|
785
904
|
|
|
786
905
|
// ../kit/src/usage.ts
|
|
787
906
|
import { appendFileSync, mkdirSync } from "fs";
|
|
788
907
|
import { homedir as homedir3 } from "os";
|
|
789
908
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
790
|
-
import
|
|
909
|
+
import process12 from "process";
|
|
791
910
|
|
|
792
911
|
// ../kit/src/logs.ts
|
|
793
912
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -801,14 +920,14 @@ var usageError;
|
|
|
801
920
|
function noteUsageError(message) {
|
|
802
921
|
usageError = message;
|
|
803
922
|
}
|
|
804
|
-
function stateHome(env =
|
|
923
|
+
function stateHome(env = process12.env) {
|
|
805
924
|
const dir = env.XDG_STATE_HOME;
|
|
806
925
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
807
926
|
}
|
|
808
|
-
function usagePath(env =
|
|
927
|
+
function usagePath(env = process12.env) {
|
|
809
928
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
810
929
|
}
|
|
811
|
-
function usageRecorded(env =
|
|
930
|
+
function usageRecorded(env = process12.env) {
|
|
812
931
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
813
932
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
814
933
|
}
|
|
@@ -822,7 +941,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
822
941
|
usageError = undefined;
|
|
823
942
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
824
943
|
}
|
|
825
|
-
function recordUsage(entry, env =
|
|
944
|
+
function recordUsage(entry, env = process12.env) {
|
|
826
945
|
if (!usageRecorded(env))
|
|
827
946
|
return;
|
|
828
947
|
try {
|
|
@@ -840,8 +959,8 @@ var LEVEL_OPTIONS = {
|
|
|
840
959
|
};
|
|
841
960
|
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
842
961
|
function printError(prefix, message, hint, cause) {
|
|
843
|
-
const colors = paint(
|
|
844
|
-
const styled = takesControlCodes(
|
|
962
|
+
const colors = paint(process13.stderr);
|
|
963
|
+
const styled = takesControlCodes(process13.stderr);
|
|
845
964
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
846
965
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
847
966
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -888,24 +1007,24 @@ function candidateLine(candidate) {
|
|
|
888
1007
|
}
|
|
889
1008
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
890
1009
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
891
|
-
|
|
1010
|
+
const typed = [];
|
|
892
1011
|
let at = 0;
|
|
893
1012
|
while (at < before.length) {
|
|
894
1013
|
const word = before[at];
|
|
895
1014
|
if (word === "--") {
|
|
896
|
-
|
|
1015
|
+
typed.push(...before.slice(at + 1));
|
|
897
1016
|
break;
|
|
898
1017
|
}
|
|
899
1018
|
if (!word.startsWith("-"))
|
|
900
|
-
|
|
1019
|
+
typed.push(word);
|
|
901
1020
|
else if (takesValue(word))
|
|
902
1021
|
at++;
|
|
903
1022
|
at++;
|
|
904
1023
|
}
|
|
905
1024
|
const last = positionals.at(-1);
|
|
906
|
-
if (
|
|
907
|
-
return positionals[
|
|
908
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
1025
|
+
if (typed.length < positionals.length)
|
|
1026
|
+
return { name: positionals[typed.length], typed };
|
|
1027
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
909
1028
|
}
|
|
910
1029
|
async function leafCandidates(run, words) {
|
|
911
1030
|
const completing = await completingOf(run);
|
|
@@ -913,12 +1032,12 @@ async function leafCandidates(run, words) {
|
|
|
913
1032
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
914
1033
|
const flag = words.at(-2);
|
|
915
1034
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1035
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
916
1036
|
if (option?.type === "string") {
|
|
917
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
1037
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
918
1038
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
919
1039
|
}
|
|
920
|
-
const
|
|
921
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
1040
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
922
1041
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
923
1042
|
}
|
|
924
1043
|
async function printCandidates(found) {
|
|
@@ -927,9 +1046,9 @@ async function printCandidates(found) {
|
|
|
927
1046
|
return 0;
|
|
928
1047
|
}
|
|
929
1048
|
function packageVersion(entry = Bun.main) {
|
|
930
|
-
for (let dir = dirname3(
|
|
1049
|
+
for (let dir = dirname3(realpathSync2(entry));; dir = dirname3(dir)) {
|
|
931
1050
|
try {
|
|
932
|
-
const { version } = JSON.parse(
|
|
1051
|
+
const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
|
|
933
1052
|
if (typeof version === "string")
|
|
934
1053
|
return version;
|
|
935
1054
|
} catch {}
|
|
@@ -937,7 +1056,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
937
1056
|
return "0.0.0";
|
|
938
1057
|
}
|
|
939
1058
|
}
|
|
940
|
-
async function runMain({ name, version, run, redact, usage }, argv =
|
|
1059
|
+
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
941
1060
|
if (argv[0] === COMPLETE)
|
|
942
1061
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
943
1062
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
@@ -966,7 +1085,7 @@ var {Glob } = globalThis.Bun;
|
|
|
966
1085
|
var SESSION_FILES = new Glob("*.json");
|
|
967
1086
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
968
1087
|
// ../kit/src/watch.ts
|
|
969
|
-
import
|
|
1088
|
+
import process14 from "process";
|
|
970
1089
|
import { format } from "util";
|
|
971
1090
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
972
1091
|
var DEFAULT_SECONDS = 2;
|
|
@@ -988,7 +1107,7 @@ function withoutWatch(args) {
|
|
|
988
1107
|
}
|
|
989
1108
|
return rest;
|
|
990
1109
|
}
|
|
991
|
-
async function watching(value, step, stream =
|
|
1110
|
+
async function watching(value, step, stream = process14.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
992
1111
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
993
1112
|
if (!takesControlCodes(stream))
|
|
994
1113
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -996,12 +1115,12 @@ async function watching(value, step, stream = process13.stdout, sleep = Bun.slee
|
|
|
996
1115
|
for (let round = 0;round < rounds; round++) {
|
|
997
1116
|
const held = [];
|
|
998
1117
|
const { log, info } = console;
|
|
999
|
-
const write =
|
|
1118
|
+
const write = process14.stdout.write.bind(process14.stdout);
|
|
1000
1119
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1001
1120
|
`);
|
|
1002
1121
|
console.log = hold;
|
|
1003
1122
|
console.info = hold;
|
|
1004
|
-
|
|
1123
|
+
process14.stdout.write = (text) => {
|
|
1005
1124
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1006
1125
|
return true;
|
|
1007
1126
|
};
|
|
@@ -1010,7 +1129,7 @@ async function watching(value, step, stream = process13.stdout, sleep = Bun.slee
|
|
|
1010
1129
|
} finally {
|
|
1011
1130
|
console.log = log;
|
|
1012
1131
|
console.info = info;
|
|
1013
|
-
|
|
1132
|
+
process14.stdout.write = write;
|
|
1014
1133
|
}
|
|
1015
1134
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1016
1135
|
await sleep(interval);
|
|
@@ -1018,8 +1137,8 @@ async function watching(value, step, stream = process13.stdout, sleep = Bun.slee
|
|
|
1018
1137
|
return code;
|
|
1019
1138
|
}
|
|
1020
1139
|
// src/colour.ts
|
|
1021
|
-
import
|
|
1022
|
-
function letter(status, stream =
|
|
1140
|
+
import process16 from "process";
|
|
1141
|
+
function letter(status, stream = process16.stdout) {
|
|
1023
1142
|
const colors = paint(stream);
|
|
1024
1143
|
const tint = { A: colors.green, M: colors.yellow, D: colors.red, U: colors.red, R: colors.cyan, C: colors.cyan }[status] ?? colors.dim;
|
|
1025
1144
|
return tint(status);
|
|
@@ -1032,6 +1151,11 @@ async function git2(args, env) {
|
|
|
1032
1151
|
return { code: ran.code, stdout: text("stdout"), stderr: text("stderr") };
|
|
1033
1152
|
}
|
|
1034
1153
|
|
|
1154
|
+
// src/repos.ts
|
|
1155
|
+
import { readdir } from "fs/promises";
|
|
1156
|
+
import { join as join6, relative, resolve as resolve4 } from "path";
|
|
1157
|
+
import process17 from "process";
|
|
1158
|
+
|
|
1035
1159
|
// src/status.ts
|
|
1036
1160
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
1037
1161
|
var OCTAL = /[0-7]/;
|
|
@@ -1104,30 +1228,126 @@ function summary(status, head) {
|
|
|
1104
1228
|
return `${on}, ${tracking}; ${files} files${last}`;
|
|
1105
1229
|
}
|
|
1106
1230
|
|
|
1231
|
+
// src/repos.ts
|
|
1232
|
+
var SKIPPED = new Set(["node_modules", "vendor", "dist"]);
|
|
1233
|
+
var DEPTH = 4;
|
|
1234
|
+
async function reposUnder(root, depth = DEPTH) {
|
|
1235
|
+
const found = [];
|
|
1236
|
+
async function walk(dir, left) {
|
|
1237
|
+
let entries;
|
|
1238
|
+
try {
|
|
1239
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
1240
|
+
} catch {
|
|
1241
|
+
return;
|
|
1242
|
+
}
|
|
1243
|
+
if (entries.some((entry) => entry.name === ".git"))
|
|
1244
|
+
found.push(dir);
|
|
1245
|
+
if (left === 0)
|
|
1246
|
+
return;
|
|
1247
|
+
await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(join6(dir, entry.name), left - 1)));
|
|
1248
|
+
}
|
|
1249
|
+
await walk(resolve4(root), depth);
|
|
1250
|
+
return found.sort();
|
|
1251
|
+
}
|
|
1252
|
+
async function toplevelOf(dir) {
|
|
1253
|
+
const read = await git2(["-C", dir, "rev-parse", "--show-toplevel"]);
|
|
1254
|
+
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
1255
|
+
}
|
|
1256
|
+
async function reposOf(roots) {
|
|
1257
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process17.cwd()];
|
|
1258
|
+
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
1259
|
+
return [...new Set(found.flat())].sort();
|
|
1260
|
+
}
|
|
1261
|
+
async function repoState(dir) {
|
|
1262
|
+
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
1263
|
+
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
1264
|
+
return { path: relative(process17.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
|
|
1265
|
+
}
|
|
1266
|
+
function trackingOf(status) {
|
|
1267
|
+
if (status.upstream === null)
|
|
1268
|
+
return "no upstream";
|
|
1269
|
+
if (status.aheadBehind === null)
|
|
1270
|
+
return "upstream gone";
|
|
1271
|
+
const { ahead, behind } = status.aheadBehind;
|
|
1272
|
+
const parts = [ahead > 0 ? `${ahead} ahead` : "", behind > 0 ? `${behind} behind` : ""].filter(Boolean);
|
|
1273
|
+
return parts.length === 0 ? "up to date" : parts.join(", ");
|
|
1274
|
+
}
|
|
1275
|
+
function changesOf(status) {
|
|
1276
|
+
const { changes, untracked, conflicted } = status;
|
|
1277
|
+
const parts = [changes.length > 0 ? `${changes.length} changed` : "", untracked.length > 0 ? `${untracked.length} untracked` : "", conflicted.length > 0 ? `${conflicted.length} conflicted` : ""].filter(Boolean);
|
|
1278
|
+
return parts.length === 0 ? "clean" : parts.join(", ");
|
|
1279
|
+
}
|
|
1280
|
+
function branchOf(status) {
|
|
1281
|
+
return status.branch === "(detached)" ? `detached at ${status.oid.slice(0, 7)}` : status.branch;
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1107
1284
|
// src/gst.ts
|
|
1108
|
-
var USAGE = `gst [
|
|
1285
|
+
var USAGE = `gst [-n N]: the repository's branch, upstream, changed files and HEAD in one line, then the changed paths by staged, unstaged and untracked
|
|
1286
|
+
|
|
1287
|
+
gst --repos [dir]... lists every repository at and below the current one's toplevel (or below each dir given, the current directory outside a repository), four levels down, past node_modules, vendor, dist and hidden folders: one line each with its path, branch, how it stands against its upstream as of the last fetch, and the files left to commit.
|
|
1109
1288
|
|
|
1110
1289
|
Exits 0 when it printed the status, 2 outside a git repository or on a usage error.`;
|
|
1111
1290
|
var OPTIONS = {
|
|
1112
|
-
|
|
1291
|
+
limit: { type: "string", short: "n", description: "add the last N commits as <sha7> <title>" },
|
|
1292
|
+
log: { type: "string", short: "l", description: "the former spelling of --limit" },
|
|
1293
|
+
repos: { type: "boolean", short: "r", description: "one line for each repository nested below, the current one included", conflicts: ["limit", "log"] },
|
|
1113
1294
|
watch: watchOption("the status"),
|
|
1114
|
-
json: jsonOption("{branch, oid, upstream, ahead, behind, head, staged, unstaged, untracked, conflicted, commits}")
|
|
1295
|
+
json: jsonOption("{branch, oid, upstream, ahead, behind, head, staged, unstaged, untracked, conflicted, commits}; with --repos an array of them, each with its path and no commits, a repository git cannot read being {path, error}")
|
|
1115
1296
|
};
|
|
1297
|
+
function jsonOf(status, head, commits) {
|
|
1298
|
+
return {
|
|
1299
|
+
branch: status.branch,
|
|
1300
|
+
oid: status.oid,
|
|
1301
|
+
upstream: status.upstream,
|
|
1302
|
+
ahead: status.aheadBehind?.ahead ?? null,
|
|
1303
|
+
behind: status.aheadBehind?.behind ?? null,
|
|
1304
|
+
head,
|
|
1305
|
+
staged: status.changes.filter((change) => change.index !== ".").map(({ index, path, from }) => ({ status: index, path, ...from === undefined ? {} : { from } })),
|
|
1306
|
+
unstaged: status.changes.filter((change) => change.worktree !== ".").map(({ worktree, path }) => ({ status: worktree, path })),
|
|
1307
|
+
untracked: status.untracked,
|
|
1308
|
+
conflicted: status.conflicted,
|
|
1309
|
+
...commits === undefined ? {} : { commits: commits.map(([commitSha = "", commitTitle = ""]) => ({ sha: commitSha, title: commitTitle })) }
|
|
1310
|
+
};
|
|
1311
|
+
}
|
|
1312
|
+
async function listRepos(roots, json) {
|
|
1313
|
+
const dirs = await reposOf(roots);
|
|
1314
|
+
if (dirs.length === 0)
|
|
1315
|
+
fail(`no git repository at or below ${roots.length === 0 ? "the current directory" : roots.join(", ")}`);
|
|
1316
|
+
const repos = await Promise.all(dirs.map(repoState));
|
|
1317
|
+
if (json) {
|
|
1318
|
+
printJson(repos.map(({ path, status, head }) => status === null ? { path, error: "git could not read it" } : { path, ...jsonOf(status, head) }));
|
|
1319
|
+
return 0;
|
|
1320
|
+
}
|
|
1321
|
+
const dim = paint(process18.stdout).dim;
|
|
1322
|
+
const cells = (repo) => {
|
|
1323
|
+
if (repo.status === null)
|
|
1324
|
+
return [role("path", process18.stdout)(repo.path), "", "", "git could not read it"];
|
|
1325
|
+
const changes = changesOf(repo.status);
|
|
1326
|
+
return [role("path", process18.stdout)(repo.path), branchOf(repo.status), trackingOf(repo.status), changes === "clean" ? dim(changes) : changes];
|
|
1327
|
+
};
|
|
1328
|
+
console.log(table(repos.map(cells)));
|
|
1329
|
+
return 0;
|
|
1330
|
+
}
|
|
1116
1331
|
function group(title, lines) {
|
|
1117
|
-
return lines.length === 0 ? [] : [paint(
|
|
1332
|
+
return lines.length === 0 ? [] : [paint(process18.stdout).bold(`${title}:`), ...lines.map((line) => ` ${line}`)];
|
|
1118
1333
|
}
|
|
1119
1334
|
function staged({ index, from, path }) {
|
|
1120
1335
|
return `${letter(index)} ${from === undefined ? "" : `${from} -> `}${path}`;
|
|
1121
1336
|
}
|
|
1122
1337
|
async function main(argv) {
|
|
1123
|
-
const parsed = parse(argv, USAGE, OPTIONS, { replaces: "git status --short
|
|
1124
|
-
if (parsed.positionals.length > 0)
|
|
1125
|
-
fail(`gst takes
|
|
1338
|
+
const parsed = parse(argv, USAGE, OPTIONS, { positionals: ["[dir]..."], replaces: "git status --short, git log --oneline and a git -C <repo> status per nested repository", examples: ["gst", ["gst -n 5", "with the last five commits"], ["gst --repos", "the repositories nested in this one"]] });
|
|
1339
|
+
if (parsed.positionals.length > 0 && parsed.values.repos !== true)
|
|
1340
|
+
fail(`gst takes dirs with --repos alone
|
|
1126
1341
|
|
|
1127
1342
|
${USAGE}`);
|
|
1128
1343
|
if (parsed.values.watch !== undefined)
|
|
1129
1344
|
return watching(parsed.values.watch, async () => main(withoutWatch(argv)));
|
|
1130
|
-
|
|
1345
|
+
if (parsed.values.repos === true)
|
|
1346
|
+
return listRepos(parsed.positionals, parsed.values.json === true);
|
|
1347
|
+
if (parsed.values.limit !== undefined && parsed.values.log !== undefined)
|
|
1348
|
+
fail("--limit and --log are the same flag, give one");
|
|
1349
|
+
const asked = parsed.values.limit ?? parsed.values.log;
|
|
1350
|
+
const count = asked === undefined ? 0 : wholeNumber(asked, "limit", 1);
|
|
1131
1351
|
const [read, head, log] = await Promise.all([
|
|
1132
1352
|
git2(["status", "--porcelain=v2", "--branch"]),
|
|
1133
1353
|
git2(["log", "-1", "--format=%h%x00%s"]),
|
|
@@ -1140,31 +1360,19 @@ ${USAGE}`);
|
|
|
1140
1360
|
`).filter(Boolean).map((line) => line.split("\x00")) : [];
|
|
1141
1361
|
if (parsed.values.json === true) {
|
|
1142
1362
|
const [sha, title] = head.code === 0 && head.stdout.trim() !== "" ? head.stdout.trim().split("\x00") : [];
|
|
1143
|
-
printJson({
|
|
1144
|
-
branch: status.branch,
|
|
1145
|
-
oid: status.oid,
|
|
1146
|
-
upstream: status.upstream,
|
|
1147
|
-
ahead: status.aheadBehind?.ahead ?? null,
|
|
1148
|
-
behind: status.aheadBehind?.behind ?? null,
|
|
1149
|
-
head: sha === undefined ? null : { sha, title: title ?? "" },
|
|
1150
|
-
staged: status.changes.filter((change) => change.index !== ".").map(({ index, path, from }) => ({ status: index, path, ...from === undefined ? {} : { from } })),
|
|
1151
|
-
unstaged: status.changes.filter((change) => change.worktree !== ".").map(({ worktree, path }) => ({ status: worktree, path })),
|
|
1152
|
-
untracked: status.untracked,
|
|
1153
|
-
conflicted: status.conflicted,
|
|
1154
|
-
commits: commits.map(([commitSha = "", commitTitle = ""]) => ({ sha: commitSha, title: commitTitle }))
|
|
1155
|
-
});
|
|
1363
|
+
printJson(jsonOf(status, sha === undefined ? null : { sha, title: title ?? "" }, commits));
|
|
1156
1364
|
return 0;
|
|
1157
1365
|
}
|
|
1158
1366
|
const lines = [
|
|
1159
1367
|
summary(status, head.code === 0 ? head.stdout : ""),
|
|
1160
1368
|
...group("staged", status.changes.filter((change) => change.index !== ".").map(staged)),
|
|
1161
1369
|
...group("unstaged", status.changes.filter((change) => change.worktree !== ".").map((change) => `${letter(change.worktree)} ${change.path}`)),
|
|
1162
|
-
...group("untracked", status.untracked.map((file) => paint(
|
|
1163
|
-
...group("conflicted", status.conflicted.map((file) => paint(
|
|
1164
|
-
...group("commits", commits.map(([commitSha = "", commitTitle = ""]) => `${role("id",
|
|
1370
|
+
...group("untracked", status.untracked.map((file) => paint(process18.stdout).dim(file))),
|
|
1371
|
+
...group("conflicted", status.conflicted.map((file) => paint(process18.stdout).red(file))),
|
|
1372
|
+
...group("commits", commits.map(([commitSha = "", commitTitle = ""]) => `${role("id", process18.stdout)(commitSha)} ${commitTitle}`))
|
|
1165
1373
|
];
|
|
1166
1374
|
console.log(lines.join(`
|
|
1167
1375
|
`));
|
|
1168
1376
|
return 0;
|
|
1169
1377
|
}
|
|
1170
|
-
|
|
1378
|
+
process18.exitCode = await runMain({ name: "gst", run: main });
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-git",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "gst, gc and
|
|
4
|
+
"version": "0.14.0",
|
|
5
|
+
"description": "gst, gc, gb and gp: a repository's state in one call, a commit of exactly the paths given, its message checked before anything is staged, a branch picked, and the branches of nested repositories pushed.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"homepage": "https://git.kaynooo.fr/kaynooo/cli/src/branch/main/packages/git#readme",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"bin": {
|
|
26
26
|
"gst": "./dist/gst.js",
|
|
27
27
|
"gc": "./dist/gc.js",
|
|
28
|
-
"gb": "./dist/gb.js"
|
|
28
|
+
"gb": "./dist/gb.js",
|
|
29
|
+
"gp": "./dist/gp.js"
|
|
29
30
|
},
|
|
30
31
|
"files": [
|
|
31
32
|
"dist",
|
|
@@ -38,12 +39,13 @@
|
|
|
38
39
|
"registry": "https://git.kaynooo.fr/api/packages/kaynooo/npm/"
|
|
39
40
|
},
|
|
40
41
|
"scripts": {
|
|
41
|
-
"build": "$npm_execpath build src/gst.ts src/gc.ts src/gb.ts --target bun --outdir dist",
|
|
42
|
+
"build": "$npm_execpath build src/gst.ts src/gc.ts src/gb.ts src/gp.ts --target bun --outdir dist",
|
|
42
43
|
"gst": "$npm_execpath src/gst.ts",
|
|
43
44
|
"gc": "$npm_execpath src/gc.ts",
|
|
44
|
-
"gb": "$npm_execpath src/gb.ts"
|
|
45
|
+
"gb": "$npm_execpath src/gb.ts",
|
|
46
|
+
"gp": "$npm_execpath src/gp.ts"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
|
-
"@kaynooo/cli-kit": "0.
|
|
49
|
+
"@kaynooo/cli-kit": "0.38.1"
|
|
48
50
|
}
|
|
49
51
|
}
|