@kaynooo/cli-git 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +26 -2
- package/dist/gc.js +982 -0
- package/dist/gst.js +964 -0
- package/package.json +45 -4
- package/src/message.ts +77 -0
package/dist/gc.js
ADDED
|
@@ -0,0 +1,982 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// @bun
|
|
3
|
+
|
|
4
|
+
// src/gc.ts
|
|
5
|
+
import process6 from "process";
|
|
6
|
+
|
|
7
|
+
// ../kit/src/args.ts
|
|
8
|
+
import process2 from "process";
|
|
9
|
+
import { parseArgs } from "util";
|
|
10
|
+
|
|
11
|
+
// ../kit/src/style.ts
|
|
12
|
+
import process from "process";
|
|
13
|
+
|
|
14
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
|
|
15
|
+
function x(s) {
|
|
16
|
+
let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
|
|
17
|
+
if (!/^[a-f0-9]+$/.test(r))
|
|
18
|
+
return [0, 0, 0];
|
|
19
|
+
let t = r.length, n = (c) => Number.parseInt(c, 16);
|
|
20
|
+
if (t === 3 || t === 4) {
|
|
21
|
+
let c = n(r[0] + r[0]), u = n(r[1] + r[1]), h = n(r[2] + r[2]), g = t === 4 ? n(r[3] + r[3]) : undefined;
|
|
22
|
+
return g !== undefined ? [c, u, h, g] : [c, u, h];
|
|
23
|
+
}
|
|
24
|
+
if (t !== 6 && t !== 8)
|
|
25
|
+
throw Error(`Invalid hex color length: ${t}`);
|
|
26
|
+
let a = n(r.slice(0, 2)), b = n(r.slice(2, 4)), o = n(r.slice(4, 6)), y = t === 8 ? n(r.slice(6, 8)) : undefined;
|
|
27
|
+
if ([a, b, o].some(Number.isNaN) || y !== undefined && Number.isNaN(y))
|
|
28
|
+
throw Error(`Invalid hex color value: ${s}`);
|
|
29
|
+
return y !== undefined ? [a, b, o, y] : [a, b, o];
|
|
30
|
+
}
|
|
31
|
+
function A(s) {
|
|
32
|
+
let [r, t, n, a] = s;
|
|
33
|
+
if (a)
|
|
34
|
+
return `#${(r << 24 | t << 16 | n << 8 | Math.round((a ?? 1) * 255)).toString(16).padStart(8, "0").toUpperCase()}`;
|
|
35
|
+
return `#${(r << 16 | t << 8 | n).toString(16).padStart(6, "0").toUpperCase()}`;
|
|
36
|
+
}
|
|
37
|
+
function R(s, r, t) {
|
|
38
|
+
s = (s % 360 + 360) % 360, t /= 100;
|
|
39
|
+
let n = r * Math.min(t, 1 - t) / 100, a = (b) => {
|
|
40
|
+
let o = (b + s / 30) % 12, y = t - n * Math.max(Math.min(o - 3, 9 - o, 1), -1);
|
|
41
|
+
return Math.round(255 * y);
|
|
42
|
+
};
|
|
43
|
+
return [a(0), a(8), a(4)];
|
|
44
|
+
}
|
|
45
|
+
function k(s) {
|
|
46
|
+
let [r, t, n] = s;
|
|
47
|
+
r /= 255, t /= 255, n /= 255;
|
|
48
|
+
let a = Math.max(r, t, n), b = Math.min(r, t, n), o = 0, y = 0, c = (a + b) / 2;
|
|
49
|
+
if (a !== b) {
|
|
50
|
+
let u = a - b;
|
|
51
|
+
if (y = c > 0 && c < 1 ? u / (1 - Math.abs(2 * c - 1)) : 0, a === r)
|
|
52
|
+
o = (t - n) / u + (t < n ? 6 : 0);
|
|
53
|
+
else if (a === t)
|
|
54
|
+
o = (n - r) / u + 2;
|
|
55
|
+
else
|
|
56
|
+
o = (r - t) / u + 4;
|
|
57
|
+
o /= 6;
|
|
58
|
+
}
|
|
59
|
+
return [Math.round(o * 360), Math.round(y * 100), Math.round(c * 100)];
|
|
60
|
+
}
|
|
61
|
+
function H(s, r, t) {
|
|
62
|
+
s = (s % 360 + 360) % 360, r /= 100, t /= 100;
|
|
63
|
+
let n = (a) => {
|
|
64
|
+
let b = (a + s / 60) % 6, o = t - t * r * Math.max(Math.min(b, 4 - b, 1), 0);
|
|
65
|
+
return Math.round(255 * o);
|
|
66
|
+
};
|
|
67
|
+
return [n(5), n(3), n(1)];
|
|
68
|
+
}
|
|
69
|
+
function f(s) {
|
|
70
|
+
let [r, t, n] = s;
|
|
71
|
+
r /= 255, t /= 255, n /= 255;
|
|
72
|
+
let a = Math.max(r, t, n), b = Math.min(r, t, n), o = a - b, y = 0, c = a === 0 ? 0 : o / a, u = a;
|
|
73
|
+
if (o !== 0) {
|
|
74
|
+
if (a === r)
|
|
75
|
+
y = (t - n) / o + (t < n ? 6 : 0);
|
|
76
|
+
else if (a === t)
|
|
77
|
+
y = (n - r) / o + 2;
|
|
78
|
+
else
|
|
79
|
+
y = (r - t) / o + 4;
|
|
80
|
+
y /= 6;
|
|
81
|
+
}
|
|
82
|
+
return [Math.round(y * 360), Math.round(c * 100), Math.round(u * 100)];
|
|
83
|
+
}
|
|
84
|
+
function O(s) {
|
|
85
|
+
let r = s[0] / 255, t = s[1] / 255, n = s[2] / 255, a = 1 - Math.max(r, t, n);
|
|
86
|
+
if (a === 1)
|
|
87
|
+
return [0, 0, 0, 100];
|
|
88
|
+
let b = (1 - r - a) / (1 - a), o = (1 - t - a) / (1 - a), y = (1 - n - a) / (1 - a);
|
|
89
|
+
return [Math.round(b * 100), Math.round(o * 100), Math.round(y * 100), Math.round(a * 100)];
|
|
90
|
+
}
|
|
91
|
+
function v(s, r, t, n) {
|
|
92
|
+
return s /= 100, r /= 100, t /= 100, n /= 100, [Math.round(255 * (1 - s) * (1 - n)), Math.round(255 * (1 - r) * (1 - n)), Math.round(255 * (1 - t) * (1 - n))];
|
|
93
|
+
}
|
|
94
|
+
var m = (s) => s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
95
|
+
var p = (s) => s <= 0.0031308 ? 12.92 * s : 1.055 * s ** 0.4166666666666667 - 0.055;
|
|
96
|
+
var i = (s, r) => Math.round(s * 10 ** r) / 10 ** r;
|
|
97
|
+
function T(s) {
|
|
98
|
+
let r = m(s[0] / 255), t = m(s[1] / 255), n = m(s[2] / 255), a = Math.cbrt(0.4122214708 * r + 0.5363325363 * t + 0.0514459929 * n), b = Math.cbrt(0.2119034982 * r + 0.6806995451 * t + 0.1073969566 * n), o = Math.cbrt(0.0883024619 * r + 0.2817188376 * t + 0.6299787005 * n);
|
|
99
|
+
return [i(0.2104542553 * a + 0.793617785 * b - 0.0040720468 * o, 4), i(1.9779984951 * a - 2.428592205 * b + 0.4505937099 * o, 4), i(0.0259040371 * a + 0.7827717662 * b - 0.808675766 * o, 4)];
|
|
100
|
+
}
|
|
101
|
+
function M(s, r, t) {
|
|
102
|
+
let n = (s + 0.3963377774 * r + 0.2158037573 * t) ** 3, a = (s - 0.1055613458 * r - 0.0638541728 * t) ** 3, b = (s - 0.0894841775 * r - 1.291485548 * t) ** 3, o = p(4.0767416621 * n - 3.3077115913 * a + 0.2309699292 * b), y = p(-1.2684380046 * n + 2.6097574011 * a - 0.3413193965 * b), c = p(-0.0041960863 * n - 0.7034186147 * a + 1.707614701 * b), u = (h) => Math.min(255, Math.max(0, Math.round(h * 255)));
|
|
103
|
+
return [u(o), u(y), u(c)];
|
|
104
|
+
}
|
|
105
|
+
function d(s) {
|
|
106
|
+
let [r, t, n] = T(s), a = Math.sqrt(t * t + n * n), b = (Math.atan2(n, t) * 180 / Math.PI + 360) % 360;
|
|
107
|
+
return [i(r, 4), i(a, 4), i(b, 2)];
|
|
108
|
+
}
|
|
109
|
+
function C(s, r, t) {
|
|
110
|
+
let n = t * Math.PI / 180;
|
|
111
|
+
return M(s, r * Math.cos(n), r * Math.sin(n));
|
|
112
|
+
}
|
|
113
|
+
function l(s) {
|
|
114
|
+
let r = s / 255;
|
|
115
|
+
return r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
class e {
|
|
119
|
+
r;
|
|
120
|
+
g;
|
|
121
|
+
b;
|
|
122
|
+
a;
|
|
123
|
+
constructor(s, r, t, n = 1) {
|
|
124
|
+
this.r = s, this.g = r, this.b = t, this.a = n;
|
|
125
|
+
}
|
|
126
|
+
static from(s, r) {
|
|
127
|
+
if (s === "hex") {
|
|
128
|
+
let [t, n, a, b] = x(r);
|
|
129
|
+
return new e(t, n, a, b);
|
|
130
|
+
}
|
|
131
|
+
if (s === "rgb") {
|
|
132
|
+
if (Array.isArray(r)) {
|
|
133
|
+
let [o, y, c, u] = r;
|
|
134
|
+
return new e(o, y, c, u);
|
|
135
|
+
}
|
|
136
|
+
let { r: t, g: n, b: a, a: b } = r;
|
|
137
|
+
return new e(t, n, a, b);
|
|
138
|
+
}
|
|
139
|
+
if (s === "hsl") {
|
|
140
|
+
let t, n, a, b;
|
|
141
|
+
if (Array.isArray(r))
|
|
142
|
+
[t, n, a, b] = r;
|
|
143
|
+
else
|
|
144
|
+
({ h: t, s: n, l: a, a: b } = r);
|
|
145
|
+
let [o, y, c] = R(t, n, a);
|
|
146
|
+
return new e(o, y, c, b);
|
|
147
|
+
}
|
|
148
|
+
if (s === "hsv") {
|
|
149
|
+
let t, n, a, b;
|
|
150
|
+
if (Array.isArray(r))
|
|
151
|
+
[t, n, a, b] = r;
|
|
152
|
+
else
|
|
153
|
+
({ h: t, s: n, v: a, a: b } = r);
|
|
154
|
+
let [o, y, c] = H(t, n, a);
|
|
155
|
+
return new e(o, y, c, b);
|
|
156
|
+
}
|
|
157
|
+
if (s === "cmyk") {
|
|
158
|
+
let t, n, a, b, o;
|
|
159
|
+
if (Array.isArray(r))
|
|
160
|
+
[t, n, a, b, o] = r;
|
|
161
|
+
else
|
|
162
|
+
({ c: t, m: n, y: a, k: b, a: o } = r);
|
|
163
|
+
let [y, c, u] = v(t, n, a, b);
|
|
164
|
+
return new e(y, c, u, o);
|
|
165
|
+
}
|
|
166
|
+
if (s === "oklch") {
|
|
167
|
+
let t, n, a, b;
|
|
168
|
+
if (Array.isArray(r))
|
|
169
|
+
[t, n, a, b] = r;
|
|
170
|
+
else
|
|
171
|
+
({ l: t, c: n, h: a, a: b } = r);
|
|
172
|
+
let [o, y, c] = C(t, n, a);
|
|
173
|
+
return new e(o, y, c, b);
|
|
174
|
+
}
|
|
175
|
+
if (s === "oklab") {
|
|
176
|
+
let t, n, a, b;
|
|
177
|
+
if (Array.isArray(r))
|
|
178
|
+
[t, n, a, b] = r;
|
|
179
|
+
else
|
|
180
|
+
({ l: t, a: n, b: a, alpha: b } = r);
|
|
181
|
+
let [o, y, c] = M(t, n, a);
|
|
182
|
+
return new e(o, y, c, b);
|
|
183
|
+
}
|
|
184
|
+
throw Error("Invalid input");
|
|
185
|
+
}
|
|
186
|
+
to(s) {
|
|
187
|
+
switch (s) {
|
|
188
|
+
case "rgb":
|
|
189
|
+
return [this.r, this.g, this.b];
|
|
190
|
+
case "rgba":
|
|
191
|
+
return [this.r, this.g, this.b, this.a];
|
|
192
|
+
case "hex":
|
|
193
|
+
return A([this.r, this.g, this.b]);
|
|
194
|
+
case "hexa":
|
|
195
|
+
return A([this.r, this.g, this.b, this.a]);
|
|
196
|
+
case "hsl":
|
|
197
|
+
return k([this.r, this.g, this.b]);
|
|
198
|
+
case "hsla":
|
|
199
|
+
return [...k([this.r, this.g, this.b]), this.a];
|
|
200
|
+
case "hsv":
|
|
201
|
+
return f([this.r, this.g, this.b]);
|
|
202
|
+
case "hsva":
|
|
203
|
+
return [...f([this.r, this.g, this.b]), this.a];
|
|
204
|
+
case "cmyk":
|
|
205
|
+
return O([this.r, this.g, this.b]);
|
|
206
|
+
case "cmyka":
|
|
207
|
+
return [...O([this.r, this.g, this.b]), this.a];
|
|
208
|
+
case "oklch":
|
|
209
|
+
return d([this.r, this.g, this.b]);
|
|
210
|
+
case "oklcha":
|
|
211
|
+
return [...d([this.r, this.g, this.b]), this.a];
|
|
212
|
+
case "oklab":
|
|
213
|
+
return T([this.r, this.g, this.b]);
|
|
214
|
+
case "oklaba":
|
|
215
|
+
return [...T([this.r, this.g, this.b]), this.a];
|
|
216
|
+
default:
|
|
217
|
+
return [this.r, this.g, this.b];
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
getLuminance() {
|
|
221
|
+
let s = l(this.r), r = l(this.g), t = l(this.b);
|
|
222
|
+
return 0.2126 * s + 0.7152 * r + 0.0722 * t;
|
|
223
|
+
}
|
|
224
|
+
contrastRatio(s) {
|
|
225
|
+
let r = this.getLuminance(), t = s.getLuminance(), [n, a] = r >= t ? [r, t] : [t, r];
|
|
226
|
+
return (n + 0.05) / (a + 0.05);
|
|
227
|
+
}
|
|
228
|
+
bestContrastForeground() {
|
|
229
|
+
let s = new e(255, 255, 255, 1), r = new e(0, 0, 0, 1), t = this.contrastRatio(s), n = this.contrastRatio(r);
|
|
230
|
+
return t >= n ? s : r;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
|
|
235
|
+
var r = 39;
|
|
236
|
+
var o = 49;
|
|
237
|
+
var f2 = "\x1B[";
|
|
238
|
+
var C2 = { 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, r], red: [31, r], green: [32, r], yellow: [33, r], blue: [34, r], magenta: [35, r], cyan: [36, r], white: [37, r], gray: [90, r], grey: [90, r], blackBright: [90, r], redBright: [91, r], greenBright: [92, r], yellowBright: [93, r], blueBright: [94, r], magentaBright: [95, r], cyanBright: [96, r], whiteBright: [97, r], bgBlack: [40, o], bgRed: [41, o], bgGreen: [42, o], bgYellow: [43, o], bgBlue: [44, o], bgMagenta: [45, o], bgCyan: [46, o], bgWhite: [47, o], bgBlackBright: [100, o], bgRedBright: [101, o], bgGreenBright: [102, o], bgYellowBright: [103, o], bgBlueBright: [104, o], bgMagentaBright: [105, o], bgCyanBright: [106, o], bgWhiteBright: [107, o], rgb: (i, n, a, l = "fg") => [`${l === "fg" ? 38 : 48};2;${i};${n};${a}`, l === "fg" ? r : o], hex: (i, n = "fg") => {
|
|
239
|
+
let [a, l, s] = e.from("hex", i).to("rgb");
|
|
240
|
+
return [`${n === "fg" ? 38 : 48};2;${a};${l};${s}`, n === "fg" ? r : o];
|
|
241
|
+
}, ansi256: (i, n = "fg") => [`${n === "fg" ? 38 : 48};5;${i}`, n === "fg" ? r : o] };
|
|
242
|
+
var b = new Set(["", "1", "2", "3", "true"]);
|
|
243
|
+
function h(i, n = globalThis.process?.env ?? {}) {
|
|
244
|
+
if (n.FORCE_COLOR !== undefined)
|
|
245
|
+
return b.has(n.FORCE_COLOR);
|
|
246
|
+
if (n.NO_COLOR !== undefined || n.NODE_DISABLE_COLORS !== undefined || n.TERM === "dumb")
|
|
247
|
+
return false;
|
|
248
|
+
return i?.isTTY === true;
|
|
249
|
+
}
|
|
250
|
+
function d2(i, n, a) {
|
|
251
|
+
if (!h(a.stream ?? globalThis.process?.stdout, a.env))
|
|
252
|
+
return n;
|
|
253
|
+
let l = "", s = "";
|
|
254
|
+
for (let g = 0, y = i.length;g < y; g++) {
|
|
255
|
+
let [c, p] = i[g];
|
|
256
|
+
l += `${f2}${c}m`, s = `${f2}${p}m${s}`;
|
|
257
|
+
}
|
|
258
|
+
return l + n + s;
|
|
259
|
+
}
|
|
260
|
+
function u(i, n = []) {
|
|
261
|
+
return new Proxy((l) => d2(n, l, i), { get(l, s) {
|
|
262
|
+
let g = C2[s];
|
|
263
|
+
if (Array.isArray(g))
|
|
264
|
+
return u(i, [...n, g]);
|
|
265
|
+
if (typeof g === "function")
|
|
266
|
+
return (...y) => u(i, [...n, g(...y)]);
|
|
267
|
+
throw Error(`Unknown style: ${String(s)}`);
|
|
268
|
+
} });
|
|
269
|
+
}
|
|
270
|
+
function le(i = {}) {
|
|
271
|
+
return u(i);
|
|
272
|
+
}
|
|
273
|
+
var t = le();
|
|
274
|
+
|
|
275
|
+
// ../kit/src/style.ts
|
|
276
|
+
function takesControlCodes(stream, env = process.env) {
|
|
277
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
278
|
+
}
|
|
279
|
+
function paint(stream, env = process.env) {
|
|
280
|
+
return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
281
|
+
}
|
|
282
|
+
var STATUSES = {
|
|
283
|
+
passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
|
|
284
|
+
failed: { symbol: "\u2717", words: ["failed", "failure", "error", "errored"], paint: (colors) => colors.red },
|
|
285
|
+
running: { symbol: "\u25CF", words: ["running", "in_progress", "started"], paint: (colors) => colors.cyan },
|
|
286
|
+
queued: { symbol: "\u25CB", words: ["queued", "waiting", "pending", "created", "blocked", "scheduled"], paint: (colors) => colors.yellow },
|
|
287
|
+
skipped: { symbol: "-", words: ["skipped", "cancelled", "canceled", "manual"], paint: (colors) => colors.dim }
|
|
288
|
+
};
|
|
289
|
+
var STATUS_OF = new Map(Object.entries(STATUSES).flatMap(([status, { words }]) => words.map((word) => [word, status])));
|
|
290
|
+
|
|
291
|
+
// ../kit/src/format.ts
|
|
292
|
+
function upTo(text, separator) {
|
|
293
|
+
const end = text.indexOf(separator);
|
|
294
|
+
return end === -1 ? text : text.slice(0, end);
|
|
295
|
+
}
|
|
296
|
+
var ESCAPE = String.fromCharCode(27);
|
|
297
|
+
function printJson(value) {
|
|
298
|
+
console.log(JSON.stringify(value, undefined, 2));
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// ../kit/src/text.ts
|
|
302
|
+
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
303
|
+
function distance(a, b) {
|
|
304
|
+
let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
|
|
305
|
+
for (const [i, left] of [...a].entries()) {
|
|
306
|
+
const current = [i + 1];
|
|
307
|
+
for (const [j, right] of [...b].entries())
|
|
308
|
+
current.push(Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (left === right ? 0 : 1)));
|
|
309
|
+
previous = current;
|
|
310
|
+
}
|
|
311
|
+
return previous[b.length] ?? 0;
|
|
312
|
+
}
|
|
313
|
+
function closest(name, names) {
|
|
314
|
+
const started = names.find((known) => known.startsWith(name));
|
|
315
|
+
if (started !== undefined)
|
|
316
|
+
return started;
|
|
317
|
+
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
318
|
+
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
// ../kit/src/args.ts
|
|
322
|
+
function jsonOption(holds) {
|
|
323
|
+
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
class Exit extends Error {
|
|
327
|
+
code;
|
|
328
|
+
hint;
|
|
329
|
+
constructor(message, code, hint) {
|
|
330
|
+
super(message);
|
|
331
|
+
this.code = code;
|
|
332
|
+
this.hint = hint;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
function fail(message, code = 2, hint) {
|
|
336
|
+
throw new Exit(message, code, hint);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
class UsageError extends Exit {
|
|
340
|
+
constructor(message, hint) {
|
|
341
|
+
super(message, 2, hint);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function badUsage(message) {
|
|
345
|
+
throw new UsageError(message);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
class HelpShown extends Exit {
|
|
349
|
+
constructor() {
|
|
350
|
+
super("help shown", 0);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
class Completing {
|
|
355
|
+
options;
|
|
356
|
+
positionals;
|
|
357
|
+
candidates;
|
|
358
|
+
constructor(options, positionals = [], candidates = {}) {
|
|
359
|
+
this.options = options;
|
|
360
|
+
this.positionals = positionals;
|
|
361
|
+
this.candidates = candidates;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
var completion = { active: false };
|
|
365
|
+
var OPTIONAL = /\[[^\]]+\]/g;
|
|
366
|
+
var USAGE_PREFIX = /^usage:\s*/i;
|
|
367
|
+
var FULL_STOP = /\.$/;
|
|
368
|
+
var DASHES = /^-+/;
|
|
369
|
+
function usageLine(usage, colors = paint(process2.stdout)) {
|
|
370
|
+
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
371
|
+
}
|
|
372
|
+
function helpText(usage, options, colors = paint(process2.stdout), { examples = [], replaces } = {}) {
|
|
373
|
+
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
|
|
374
|
+
`);
|
|
375
|
+
}
|
|
376
|
+
function replacesRows(replaces, colors = paint(process2.stdout)) {
|
|
377
|
+
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
378
|
+
}
|
|
379
|
+
function wantsHelpJson(env = process2.env) {
|
|
380
|
+
return env.KIT_HELP === "json";
|
|
381
|
+
}
|
|
382
|
+
function description(usage, { examples = [], replaces } = {}) {
|
|
383
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
384
|
+
`);
|
|
385
|
+
const first = lines[0];
|
|
386
|
+
const colon = first.indexOf(": ");
|
|
387
|
+
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
388
|
+
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
389
|
+
return {
|
|
390
|
+
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
391
|
+
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
392
|
+
...replaces === undefined ? {} : { replaces },
|
|
393
|
+
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
function exampleRows(examples, colors = paint(process2.stdout)) {
|
|
397
|
+
if (examples.length === 0)
|
|
398
|
+
return [];
|
|
399
|
+
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
400
|
+
}
|
|
401
|
+
function optionRows(options, colors = paint(process2.stdout)) {
|
|
402
|
+
const rows = Object.entries(options).map(([name, option]) => {
|
|
403
|
+
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
404
|
+
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
405
|
+
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
406
|
+
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
407
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
|
|
408
|
+
});
|
|
409
|
+
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
410
|
+
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
411
|
+
}
|
|
412
|
+
var OUTPUT_OPTIONS = {
|
|
413
|
+
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
414
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
415
|
+
};
|
|
416
|
+
function applyOutput(color, plain, env = process2.env) {
|
|
417
|
+
const when = plain === true ? "never" : color ?? "auto";
|
|
418
|
+
if (when === "auto")
|
|
419
|
+
return;
|
|
420
|
+
if (when !== "always" && when !== "never")
|
|
421
|
+
badUsage(`--color takes auto, always or never, not ${when}`);
|
|
422
|
+
if (when === "always") {
|
|
423
|
+
env.FORCE_COLOR = "1";
|
|
424
|
+
delete env.NO_COLOR;
|
|
425
|
+
} else {
|
|
426
|
+
env.NO_COLOR = "1";
|
|
427
|
+
delete env.FORCE_COLOR;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
function parse(args, usage, options, settings = {}) {
|
|
431
|
+
const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
|
|
432
|
+
const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
|
|
433
|
+
const listing = listed(all, settings.allowNegative === true);
|
|
434
|
+
if (completion.active)
|
|
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);
|
|
437
|
+
let parsed;
|
|
438
|
+
try {
|
|
439
|
+
parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
440
|
+
} catch (error) {
|
|
441
|
+
const message = parseError(error);
|
|
442
|
+
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
443
|
+
}
|
|
444
|
+
const values = parsed.values;
|
|
445
|
+
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
446
|
+
if (values.help === true) {
|
|
447
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
|
|
448
|
+
throw new HelpShown;
|
|
449
|
+
}
|
|
450
|
+
checkChoices(parsed.values, all);
|
|
451
|
+
checkConflicts(parsed.values, all);
|
|
452
|
+
if (settings.positionals !== undefined)
|
|
453
|
+
checkPositionals(parsed.positionals, settings.positionals);
|
|
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;
|
|
525
|
+
}
|
|
526
|
+
function checkPositionals(given, names) {
|
|
527
|
+
const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
|
|
528
|
+
const required = names.filter((name) => !name.startsWith("[")).length;
|
|
529
|
+
if (given.length < required)
|
|
530
|
+
badUsage(`missing ${names[given.length]}`);
|
|
531
|
+
if (!variadic && given.length > names.length)
|
|
532
|
+
badUsage(`unexpected argument ${given[names.length]}`);
|
|
533
|
+
}
|
|
534
|
+
function joinDashValues(args, options) {
|
|
535
|
+
const longOf = new Map(Object.entries(options).flatMap(([name, option]) => option.short === undefined ? [[`--${name}`, name]] : [[`--${name}`, name], [`-${option.short}`, name]]));
|
|
536
|
+
const isOption = (arg) => arg === "--" || longOf.has(arg.includes("=") ? arg.slice(0, arg.indexOf("=")) : arg);
|
|
537
|
+
const joined = [];
|
|
538
|
+
for (let i = 0;i < args.length; i++) {
|
|
539
|
+
const arg = args[i] ?? "";
|
|
540
|
+
if (arg === "--")
|
|
541
|
+
return [...joined, ...args.slice(i)];
|
|
542
|
+
const name = longOf.get(arg);
|
|
543
|
+
const next = args[i + 1];
|
|
544
|
+
if (name !== undefined && options[name]?.type === "string" && next !== undefined && next.startsWith("-") && next !== "-" && !isOption(next)) {
|
|
545
|
+
joined.push(`--${name}=${next}`);
|
|
546
|
+
i++;
|
|
547
|
+
} else {
|
|
548
|
+
joined.push(arg);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
return joined;
|
|
552
|
+
}
|
|
553
|
+
function parseError(error) {
|
|
554
|
+
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
555
|
+
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
556
|
+
}
|
|
557
|
+
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
558
|
+
function nearestOption(message, options, allowNegative) {
|
|
559
|
+
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
560
|
+
if (typed === undefined)
|
|
561
|
+
return;
|
|
562
|
+
const word = typed.replace(DASHES, "");
|
|
563
|
+
if (word.length < 2 && !typed.startsWith("--"))
|
|
564
|
+
return;
|
|
565
|
+
const known = Object.entries(options).flatMap(([name, option]) => [
|
|
566
|
+
...option.short === undefined ? [] : [`-${option.short}`],
|
|
567
|
+
`--${name}`,
|
|
568
|
+
...allowNegative && option.type === "boolean" ? [`--no-${name}`] : []
|
|
569
|
+
]);
|
|
570
|
+
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
571
|
+
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
572
|
+
}
|
|
573
|
+
var WHOLE = /^\d+$/;
|
|
574
|
+
function wholeNumber(value, name, fallback, min = 1) {
|
|
575
|
+
if (value === undefined)
|
|
576
|
+
return fallback;
|
|
577
|
+
const number = Number(value);
|
|
578
|
+
if (!WHOLE.test(value) || !Number.isSafeInteger(number) || number < min)
|
|
579
|
+
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
580
|
+
return number;
|
|
581
|
+
}
|
|
582
|
+
// ../kit/src/process.ts
|
|
583
|
+
import { constants } from "os";
|
|
584
|
+
import process3 from "process";
|
|
585
|
+
var KILL_GRACE_MS = 2000;
|
|
586
|
+
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
587
|
+
function exitCodeOf(code, signal) {
|
|
588
|
+
if (code !== null)
|
|
589
|
+
return code;
|
|
590
|
+
if (typeof signal === "number")
|
|
591
|
+
return 128 + signal;
|
|
592
|
+
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
593
|
+
}
|
|
594
|
+
function holdSignals(cleanup) {
|
|
595
|
+
let received;
|
|
596
|
+
let child;
|
|
597
|
+
const held = {
|
|
598
|
+
get signal() {
|
|
599
|
+
return received;
|
|
600
|
+
},
|
|
601
|
+
forward: (to) => {
|
|
602
|
+
child = to;
|
|
603
|
+
},
|
|
604
|
+
release: () => {
|
|
605
|
+
for (const signal of SIGNALS)
|
|
606
|
+
process3.off(signal, onSignal);
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
function onSignal(signal) {
|
|
610
|
+
received = signal;
|
|
611
|
+
if (child !== undefined) {
|
|
612
|
+
child.kill(signal);
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
if (cleanup === undefined)
|
|
616
|
+
return;
|
|
617
|
+
held.release();
|
|
618
|
+
cleanup(signal);
|
|
619
|
+
process3.kill(process3.pid, signal);
|
|
620
|
+
}
|
|
621
|
+
for (const signal of SIGNALS)
|
|
622
|
+
process3.on(signal, onSignal);
|
|
623
|
+
return held;
|
|
624
|
+
}
|
|
625
|
+
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
626
|
+
const chunks = [];
|
|
627
|
+
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
628
|
+
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
629
|
+
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
630
|
+
const timers = [];
|
|
631
|
+
const killGroup = (killing) => {
|
|
632
|
+
if (state.done)
|
|
633
|
+
return;
|
|
634
|
+
try {
|
|
635
|
+
if (grouped)
|
|
636
|
+
process3.kill(-proc.pid, killing);
|
|
637
|
+
else
|
|
638
|
+
proc.kill(killing);
|
|
639
|
+
} catch {}
|
|
640
|
+
};
|
|
641
|
+
const stop = () => {
|
|
642
|
+
killGroup("SIGTERM");
|
|
643
|
+
timers.push(setTimeout(killGroup, KILL_GRACE_MS, "SIGKILL"));
|
|
644
|
+
};
|
|
645
|
+
const onAbort = () => stop();
|
|
646
|
+
if (timeoutMs !== undefined) {
|
|
647
|
+
timers.push(setTimeout(() => {
|
|
648
|
+
state.timedOut = true;
|
|
649
|
+
stop();
|
|
650
|
+
}, timeoutMs));
|
|
651
|
+
}
|
|
652
|
+
if (signal?.aborted === true)
|
|
653
|
+
onAbort();
|
|
654
|
+
else
|
|
655
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
656
|
+
onStart?.({ kill: (killing) => killGroup(killing) });
|
|
657
|
+
const drain = async (stream, name) => {
|
|
658
|
+
for await (const data of stream) {
|
|
659
|
+
if (state.failure !== undefined)
|
|
660
|
+
continue;
|
|
661
|
+
try {
|
|
662
|
+
onChunk?.({ stream: name, data });
|
|
663
|
+
} catch (error) {
|
|
664
|
+
state.failure = error;
|
|
665
|
+
stop();
|
|
666
|
+
continue;
|
|
667
|
+
}
|
|
668
|
+
if (state.kept + data.length > maxBytes) {
|
|
669
|
+
state.truncated = true;
|
|
670
|
+
continue;
|
|
671
|
+
}
|
|
672
|
+
state.kept += data.length;
|
|
673
|
+
chunks.push({ stream: name, data });
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
try {
|
|
677
|
+
await Promise.all([drain(proc.stdout, "stdout"), drain(proc.stderr, "stderr")]);
|
|
678
|
+
await proc.exited;
|
|
679
|
+
} finally {
|
|
680
|
+
state.done = true;
|
|
681
|
+
for (const timer of timers)
|
|
682
|
+
clearTimeout(timer);
|
|
683
|
+
signal?.removeEventListener("abort", onAbort);
|
|
684
|
+
}
|
|
685
|
+
if (state.failure !== undefined)
|
|
686
|
+
throw state.failure;
|
|
687
|
+
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
688
|
+
let output;
|
|
689
|
+
let text;
|
|
690
|
+
return {
|
|
691
|
+
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
692
|
+
chunks,
|
|
693
|
+
timedOut: state.timedOut,
|
|
694
|
+
truncated: state.truncated,
|
|
695
|
+
get output() {
|
|
696
|
+
return output ??= joined();
|
|
697
|
+
},
|
|
698
|
+
get text() {
|
|
699
|
+
return text ??= (output ??= joined()).toString();
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
// ../kit/src/progress.ts
|
|
705
|
+
var ESC = String.fromCharCode(27);
|
|
706
|
+
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
707
|
+
var RESET_STYLE = `${ESC}[0m`;
|
|
708
|
+
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
709
|
+
// ../kit/src/cli.ts
|
|
710
|
+
import process4 from "process";
|
|
711
|
+
var LEVEL_OPTIONS = {
|
|
712
|
+
...OUTPUT_OPTIONS,
|
|
713
|
+
help: { type: "boolean", short: "h", description: "show this help" }
|
|
714
|
+
};
|
|
715
|
+
var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
|
|
716
|
+
function printError(prefix, message, hint, cause) {
|
|
717
|
+
const colors = paint(process4.stderr);
|
|
718
|
+
const styled = takesControlCodes(process4.stderr);
|
|
719
|
+
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
720
|
+
const under = (label, text, tint) => text === undefined ? "" : `
|
|
721
|
+
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
722
|
+
console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
|
|
723
|
+
}
|
|
724
|
+
function runHint(command, effect) {
|
|
725
|
+
return `run \`${command}\`${effect === undefined ? "" : ` to ${effect}`}`;
|
|
726
|
+
}
|
|
727
|
+
function printJsonError(message, hint, cause) {
|
|
728
|
+
console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
|
|
729
|
+
}
|
|
730
|
+
function wantsJson(argv) {
|
|
731
|
+
const end = argv.indexOf("--");
|
|
732
|
+
return (end === -1 ? argv : argv.slice(0, end)).includes("--json");
|
|
733
|
+
}
|
|
734
|
+
function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
735
|
+
if (error instanceof HelpShown)
|
|
736
|
+
return 0;
|
|
737
|
+
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
738
|
+
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
739
|
+
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
740
|
+
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
741
|
+
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
742
|
+
return error instanceof Exit ? error.code : 1;
|
|
743
|
+
}
|
|
744
|
+
var COMPLETE = "__complete";
|
|
745
|
+
var FILES = "__files__";
|
|
746
|
+
async function completingOf(run) {
|
|
747
|
+
completion.active = true;
|
|
748
|
+
try {
|
|
749
|
+
await run([]);
|
|
750
|
+
} catch (error) {
|
|
751
|
+
if (error instanceof Completing)
|
|
752
|
+
return error;
|
|
753
|
+
} finally {
|
|
754
|
+
completion.active = false;
|
|
755
|
+
}
|
|
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;
|
|
781
|
+
}
|
|
782
|
+
async function leafCandidates(run, words) {
|
|
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);
|
|
795
|
+
}
|
|
796
|
+
async function printCandidates(found) {
|
|
797
|
+
for (const line of await found)
|
|
798
|
+
console.log(line);
|
|
799
|
+
return 0;
|
|
800
|
+
}
|
|
801
|
+
async function runMain({ name, version, run, redact }, argv = process4.argv.slice(2)) {
|
|
802
|
+
if (argv[0] === COMPLETE)
|
|
803
|
+
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
804
|
+
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
805
|
+
console.log(version);
|
|
806
|
+
return 0;
|
|
807
|
+
}
|
|
808
|
+
try {
|
|
809
|
+
return await run(argv);
|
|
810
|
+
} catch (error) {
|
|
811
|
+
return reportThrown(name, error, redact, wantsJson(argv));
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
// ../kit/src/logs.ts
|
|
815
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
816
|
+
// ../kit/src/secrets.ts
|
|
817
|
+
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
818
|
+
// ../kit/src/sessions.ts
|
|
819
|
+
var {Glob } = globalThis.Bun;
|
|
820
|
+
var SESSION_FILES = new Glob("*.json");
|
|
821
|
+
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
822
|
+
// package.json
|
|
823
|
+
var version = "0.5.1";
|
|
824
|
+
|
|
825
|
+
// src/git.ts
|
|
826
|
+
async function git2(args, env) {
|
|
827
|
+
const ran = await runCommand(["git", "--no-optional-locks", "-c", "core.quotePath=false", ...args], env === undefined ? {} : { env });
|
|
828
|
+
const text = (stream) => Buffer.concat(ran.chunks.filter((chunk) => chunk.stream === stream).map((chunk) => chunk.data)).toString();
|
|
829
|
+
return { code: ran.code, stdout: text("stdout"), stderr: text("stderr") };
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
// src/message.ts
|
|
833
|
+
var CONVENTIONAL = /^(?:feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\([^()\n]+\))?!?: \S/;
|
|
834
|
+
var MAX_TITLE = 100;
|
|
835
|
+
var GIT_MADE = /^(?:Merge |Revert "|fixup! |squash! |amend! )/;
|
|
836
|
+
var TICKET = /^(?:[\w.-]+\/[\w.-]+)?#\d+ - /;
|
|
837
|
+
var BREAKING = /^BREAKING[ -]CHANGE: /;
|
|
838
|
+
var BREAKING_TITLE = /^[a-z]+(?:\([^()\n]+\))?!: /;
|
|
839
|
+
var TRAILER = /^(?:co-authored-by|signed-off-by|reviewed-by|acked-by|tested-by|reported-by|suggested-by|helped-by|change-id):|^\W*generated with \W*claude/i;
|
|
840
|
+
var BULLET = /^\s*(?:[-*+]|\d+[.)])\s/;
|
|
841
|
+
var SENTENCE_END = /[.!?:;)\]`'"]$/;
|
|
842
|
+
var LOWER_START = /^\p{Ll}/u;
|
|
843
|
+
var RULE = 'The rule: a `type(scope): title` line, `!` after the scope for a breaking change, type and scope taken from the repository\'s history; then optionally a blank line and one or two lines on what changed, never a bullet list or a hard-wrapped sentence; then a blank line and one line per ticket, its title copied verbatim, `#<n> - <title>` (`owner/repo#<n> - <title>` for another repository). The message ends there: no Co-Authored-By, Signed-off-by or "Generated with" trailer. Only a breaking change gives full details.';
|
|
844
|
+
var TITLE = `The title is no Conventional Commit. ${RULE}`;
|
|
845
|
+
var TITLE_TOO_LONG = `The title runs past ${MAX_TITLE} characters: shorten it and move the detail to the body. ${RULE}`;
|
|
846
|
+
var TITLE_LINE = `The title takes one line and a blank line follows it. ${RULE}`;
|
|
847
|
+
var TRAILERS = `No trailers, ever: no Co-Authored-By, Signed-off-by or "Generated with" line, no --signoff or --trailer. ${RULE}`;
|
|
848
|
+
var BULLETS = `The body names what changed in a line or two, never a bullet list narrating the diff. ${RULE}`;
|
|
849
|
+
var TOO_LONG = `The body holds at most two lines besides the ticket lines; what goes beyond belongs in the reply. ${RULE}`;
|
|
850
|
+
var WRAPPED = `A body sentence stays on one line however long it runs: never hard-wrap it. ${RULE}`;
|
|
851
|
+
function isDescription(line) {
|
|
852
|
+
return line !== undefined && line !== "" && !TICKET.test(line);
|
|
853
|
+
}
|
|
854
|
+
function commitMessageViolation(message) {
|
|
855
|
+
const lines = message.split(`
|
|
856
|
+
`).map((line) => line.trimEnd());
|
|
857
|
+
while (lines[0] === "")
|
|
858
|
+
lines.shift();
|
|
859
|
+
while (lines.at(-1) === "")
|
|
860
|
+
lines.pop();
|
|
861
|
+
const [title = "", second, ...body] = lines;
|
|
862
|
+
if (title === "")
|
|
863
|
+
return null;
|
|
864
|
+
if (lines.some((line) => TRAILER.test(line)))
|
|
865
|
+
return TRAILERS;
|
|
866
|
+
if (!CONVENTIONAL.test(title) && !GIT_MADE.test(title))
|
|
867
|
+
return TITLE;
|
|
868
|
+
if (second !== undefined && second !== "")
|
|
869
|
+
return TITLE_LINE;
|
|
870
|
+
if (!GIT_MADE.test(title) && title.length > MAX_TITLE)
|
|
871
|
+
return TITLE_TOO_LONG;
|
|
872
|
+
if (BREAKING_TITLE.test(title))
|
|
873
|
+
return null;
|
|
874
|
+
const footer = body.findIndex((line) => BREAKING.test(line));
|
|
875
|
+
const described = footer === -1 ? body : body.slice(0, footer);
|
|
876
|
+
const descriptions = described.filter(isDescription);
|
|
877
|
+
if (descriptions.some((line) => BULLET.test(line)))
|
|
878
|
+
return BULLETS;
|
|
879
|
+
if (descriptions.length > 2)
|
|
880
|
+
return TOO_LONG;
|
|
881
|
+
const isWrapped = described.some((line, i) => isDescription(line) && isDescription(described[i + 1]) && !SENTENCE_END.test(line) && LOWER_START.test(described[i + 1] ?? ""));
|
|
882
|
+
return isWrapped ? WRAPPED : null;
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
// src/gc.ts
|
|
886
|
+
var USAGE = `gc <title> [-m <line>]... [--ticket <line>]... -- <path>...: commits exactly the paths given, its message checked before anything is staged
|
|
887
|
+
|
|
888
|
+
Exits 0 when it committed, 1 when the message is refused or git fails (nothing is committed), 2 on a usage error or outside a git repository, 128 plus the signal when interrupted.`;
|
|
889
|
+
var OPTIONS = {
|
|
890
|
+
message: { type: "string", short: "m", multiple: true, description: "a line on what changed, at most two" },
|
|
891
|
+
ticket: { type: "string", multiple: true, description: "a ticket line, `#<n> - <title>` (`owner/repo#<n> - <title>` across repositories) copied verbatim from the ticket" }
|
|
892
|
+
};
|
|
893
|
+
var RENAME = /^[RC]\d*$/;
|
|
894
|
+
var NOT_A_REPOSITORY = /not a git repository/i;
|
|
895
|
+
var LITERAL = { ...process6.env, GIT_LITERAL_PATHSPECS: "1" };
|
|
896
|
+
function messageOf(title, lines, tickets) {
|
|
897
|
+
return [title, lines.join(`
|
|
898
|
+
`), tickets.join(`
|
|
899
|
+
`)].filter((block) => block !== "").join(`
|
|
900
|
+
|
|
901
|
+
`);
|
|
902
|
+
}
|
|
903
|
+
async function checked(args) {
|
|
904
|
+
const { code, stdout, stderr } = await git2(args, LITERAL);
|
|
905
|
+
if (code !== 0)
|
|
906
|
+
fail(`git ${args[0]} failed, nothing committed:
|
|
907
|
+
${stderr.trim()}`, NOT_A_REPOSITORY.test(stderr) ? 2 : 1);
|
|
908
|
+
return stdout;
|
|
909
|
+
}
|
|
910
|
+
async function stagedElsewhere(paths) {
|
|
911
|
+
const [all, given] = await Promise.all([checked(["diff", "--cached", "--name-only", "-z"]), checked(["diff", "--cached", "--name-only", "-z", "--", ...paths])]);
|
|
912
|
+
const ours = new Set(given.split("\x00"));
|
|
913
|
+
return all.split("\x00").filter((path) => path !== "" && !ours.has(path));
|
|
914
|
+
}
|
|
915
|
+
async function unstage(paths) {
|
|
916
|
+
const hasHead = (await git2(["rev-parse", "--verify", "-q", "HEAD"], LITERAL)).code === 0;
|
|
917
|
+
await git2(hasHead ? ["reset", "-q", "--", ...paths] : ["rm", "-r", "-q", "--cached", "--", ...paths], LITERAL);
|
|
918
|
+
}
|
|
919
|
+
function fileLine(line) {
|
|
920
|
+
const [letter = "", from = "", to] = line.split("\t");
|
|
921
|
+
return RENAME.test(letter) ? ` ${letter[0]} ${from} -> ${to}` : ` ${letter} ${from}`;
|
|
922
|
+
}
|
|
923
|
+
async function main(argv) {
|
|
924
|
+
const parsed = parse(argv, USAGE, OPTIONS, { rest: true, replaces: "git add, git status and git commit chained", examples: ['gc "fix(api): retry a timed-out fetch" -- src/api.ts', ['gc "feat(ui): a dark theme" -m "The toggle sits in the header." --ticket "#12 - Dark theme" -- src/theme.ts src/header.ts', "a body line and a ticket"]] });
|
|
925
|
+
const { values, positionals, rest = [] } = parsed;
|
|
926
|
+
const paths = [...new Set(rest)];
|
|
927
|
+
if (positionals.length !== 1)
|
|
928
|
+
fail(`give the title as one quoted argument and the paths after --
|
|
929
|
+
|
|
930
|
+
${USAGE}`);
|
|
931
|
+
if (paths.length === 0)
|
|
932
|
+
fail(`give the paths to commit after --
|
|
933
|
+
|
|
934
|
+
${USAGE}`);
|
|
935
|
+
const title = positionals[0]?.trim() ?? "";
|
|
936
|
+
const tickets = values.ticket ?? [];
|
|
937
|
+
const wrong = tickets.find((line) => !TICKET.test(line));
|
|
938
|
+
if (wrong !== undefined)
|
|
939
|
+
fail(`nothing staged: a ticket line reads \`#<n> - <title>\` or \`owner/repo#<n> - <title>\`, copied verbatim from the ticket, not: ${wrong}. ${RULE}`, 1);
|
|
940
|
+
if (title === "")
|
|
941
|
+
fail(`the title is empty
|
|
942
|
+
|
|
943
|
+
${USAGE}`);
|
|
944
|
+
const message = messageOf(title, values.message ?? [], tickets);
|
|
945
|
+
const violation = commitMessageViolation(message);
|
|
946
|
+
if (violation !== null)
|
|
947
|
+
fail(`nothing staged: ${violation}`, 1);
|
|
948
|
+
const statuses = await Promise.all(paths.map(async (path) => checked(["status", "--porcelain", "--untracked-files=all", "--", path])));
|
|
949
|
+
const unchanged = paths.filter((_, i) => statuses[i] === "");
|
|
950
|
+
const addable = paths.filter((_, i) => !(statuses[i] ?? "").trimEnd().split(`
|
|
951
|
+
`).every((line) => line.startsWith("D ")));
|
|
952
|
+
if (unchanged.length > 0)
|
|
953
|
+
fail(`nothing staged: no change to commit in ${unchanged.join(", ")} (unchanged, ignored or missing)`, 1, runHint("gst", "see what changed"));
|
|
954
|
+
const others = await stagedElsewhere(paths);
|
|
955
|
+
if (others.length > 0)
|
|
956
|
+
fail(`nothing staged: the index already holds ${others.join(", ")}, which this commit would carry along`, 1, runHint(`git restore --staged -- ${others.join(" ")}`, "unstage them, or name them in the paths too"));
|
|
957
|
+
const signals = holdSignals();
|
|
958
|
+
try {
|
|
959
|
+
if (addable.length > 0)
|
|
960
|
+
await checked(["add", "--", ...addable]);
|
|
961
|
+
if (signals.signal !== undefined) {
|
|
962
|
+
await unstage(paths);
|
|
963
|
+
return exitCodeOf(null, signals.signal);
|
|
964
|
+
}
|
|
965
|
+
const commit = await git2(["commit", "--only", "--cleanup=whitespace", "-m", message, "--", ...paths.map((path) => `:(literal)${path}`)]);
|
|
966
|
+
if (commit.code !== 0) {
|
|
967
|
+
await unstage(paths);
|
|
968
|
+
console.error(`gc: git commit failed, the paths were unstaged:
|
|
969
|
+
${(commit.stderr + commit.stdout).trim()}`);
|
|
970
|
+
return 1;
|
|
971
|
+
}
|
|
972
|
+
const files = await checked(["show", "--format=%h %s", "--name-status", "-M", "HEAD"]);
|
|
973
|
+
const [head = "", ...lines] = files.trimEnd().split(`
|
|
974
|
+
`);
|
|
975
|
+
console.log([head, ...lines.filter(Boolean).map(fileLine)].join(`
|
|
976
|
+
`));
|
|
977
|
+
return signals.signal === undefined ? 0 : exitCodeOf(null, signals.signal);
|
|
978
|
+
} finally {
|
|
979
|
+
signals.release();
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
process6.exitCode = await runMain({ name: "gc", version, run: main });
|