@kaynooo/cli-git 0.16.1 → 0.17.3
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 +4 -4
- package/dist/gb.js +1728 -1143
- package/dist/gc.js +1173 -178
- package/dist/gcl.js +1165 -181
- package/dist/gd.js +1152 -183
- package/dist/gf.js +1172 -182
- package/dist/gm.js +1799 -1172
- package/dist/gp.js +1153 -181
- package/dist/gst.js +1149 -185
- package/dist/gu.js +1152 -178
- package/package.json +5 -5
package/dist/gcl.js
CHANGED
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
2
|
// @bun
|
|
3
|
+
var __esm = (fn, res, err) => () => {
|
|
4
|
+
if (fn)
|
|
5
|
+
try {
|
|
6
|
+
res = fn(fn = 0);
|
|
7
|
+
} catch (e) {
|
|
8
|
+
err = [e];
|
|
9
|
+
}
|
|
10
|
+
if (err)
|
|
11
|
+
throw err[0];
|
|
12
|
+
return res;
|
|
13
|
+
};
|
|
3
14
|
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
import { homedir as homedir5 } from "os";
|
|
7
|
-
import { basename, join as join8, resolve as resolve6 } from "path";
|
|
8
|
-
import process20 from "process";
|
|
9
|
-
// ../kit/src/args.ts
|
|
10
|
-
import process9 from "process";
|
|
11
|
-
import { parseArgs } from "util";
|
|
12
|
-
|
|
13
|
-
// ../kit/src/format.ts
|
|
14
|
-
import process7 from "process";
|
|
15
|
-
|
|
16
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
17
|
-
var N = new Map;
|
|
18
|
-
var Nt = /\s+\S*$/;
|
|
19
|
-
var Y = /\s/;
|
|
20
|
-
function ko(t, e, r = "...") {
|
|
15
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rkhsft4a.js
|
|
16
|
+
function Ao(t, e, r = "...") {
|
|
21
17
|
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
22
18
|
if (t.length <= e)
|
|
23
19
|
return t;
|
|
@@ -28,13 +24,22 @@ function ko(t, e, r = "...") {
|
|
|
28
24
|
c = c.trimEnd();
|
|
29
25
|
return s ? (c + n).slice(0, l) : c + n;
|
|
30
26
|
}
|
|
31
|
-
var
|
|
32
|
-
var
|
|
27
|
+
var N, Nt, Y, be, W;
|
|
28
|
+
var init_chunk_rkhsft4a = __esm(() => {
|
|
29
|
+
N = new Map;
|
|
30
|
+
Nt = /\s+\S*$/;
|
|
31
|
+
Y = /\s/;
|
|
32
|
+
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));
|
|
33
|
+
W = new Map;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
|
|
37
|
+
var init_text = __esm(() => {
|
|
38
|
+
init_chunk_rkhsft4a();
|
|
39
|
+
});
|
|
33
40
|
|
|
34
41
|
// ../kit/src/mode.ts
|
|
35
42
|
import process2 from "process";
|
|
36
|
-
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
37
|
-
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
38
43
|
function isSet(value) {
|
|
39
44
|
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
40
45
|
}
|
|
@@ -51,12 +56,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
51
56
|
function isInteractive(streams = process2) {
|
|
52
57
|
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
53
58
|
}
|
|
59
|
+
var MODES, AGENT_VARIABLES;
|
|
60
|
+
var init_mode = __esm(() => {
|
|
61
|
+
MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
62
|
+
AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
63
|
+
});
|
|
54
64
|
|
|
55
|
-
//
|
|
56
|
-
import process6 from "process";
|
|
57
|
-
|
|
58
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
59
|
-
var G2 = /^[a-f0-9]+$/i;
|
|
65
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
60
66
|
function b(r) {
|
|
61
67
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
62
68
|
if (!G2.test(e))
|
|
@@ -67,11 +73,6 @@ function b(r) {
|
|
|
67
73
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
68
74
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
69
75
|
}
|
|
70
|
-
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") => {
|
|
71
|
-
let [l, n, c] = b(r);
|
|
72
|
-
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
73
|
-
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
74
|
-
var h = new Set(["", "1", "2", "3", "true"]);
|
|
75
76
|
function C(r, e = globalThis.process?.env ?? {}) {
|
|
76
77
|
if (e.FORCE_COLOR !== undefined)
|
|
77
78
|
return h.has(e.FORCE_COLOR);
|
|
@@ -85,7 +86,7 @@ function f(r, e = []) {
|
|
|
85
86
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
86
87
|
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
87
88
|
return new Proxy(c, { get(t, i) {
|
|
88
|
-
let a =
|
|
89
|
+
let a = B[i];
|
|
89
90
|
if (Array.isArray(a)) {
|
|
90
91
|
let s = g.get(i);
|
|
91
92
|
if (s === undefined)
|
|
@@ -108,13 +109,21 @@ function f(r, e = []) {
|
|
|
108
109
|
function Fe(r = {}) {
|
|
109
110
|
return f(r);
|
|
110
111
|
}
|
|
111
|
-
var
|
|
112
|
+
var G2, B, h, o;
|
|
113
|
+
var init_chunk_x450vn3m = __esm(() => {
|
|
114
|
+
G2 = /^[a-f0-9]+$/i;
|
|
115
|
+
B = { 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") => {
|
|
116
|
+
let [l, n, c] = b(r);
|
|
117
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
118
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
119
|
+
h = new Set(["", "1", "2", "3", "true"]);
|
|
120
|
+
o = Fe();
|
|
121
|
+
});
|
|
112
122
|
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
import process5 from "process";
|
|
123
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
|
|
124
|
+
var init_colors = __esm(() => {
|
|
125
|
+
init_chunk_x450vn3m();
|
|
126
|
+
});
|
|
118
127
|
|
|
119
128
|
// ../kit/src/config.ts
|
|
120
129
|
import { existsSync } from "fs";
|
|
@@ -130,15 +139,21 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
130
139
|
return;
|
|
131
140
|
}
|
|
132
141
|
}
|
|
142
|
+
var init_config = __esm(() => {
|
|
143
|
+
init_args();
|
|
144
|
+
});
|
|
133
145
|
|
|
134
146
|
// ../kit/src/user-config.ts
|
|
135
147
|
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
136
148
|
import { homedir } from "os";
|
|
137
|
-
import { join as join2 } from "path";
|
|
149
|
+
import { isAbsolute, join as join2 } from "path";
|
|
138
150
|
import process4 from "process";
|
|
151
|
+
function xdgFolder(value, fallback) {
|
|
152
|
+
return value !== undefined && isAbsolute(value) ? value : fallback;
|
|
153
|
+
}
|
|
139
154
|
function configBase(where = {}) {
|
|
140
155
|
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
141
|
-
return xdg
|
|
156
|
+
return xdgFolder(xdg, join2(where.home ?? homedir(), ".config"));
|
|
142
157
|
}
|
|
143
158
|
function userConfigPath(bin, where = {}) {
|
|
144
159
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
@@ -161,13 +176,17 @@ function readUserConfig(bin, where = {}, legacy = []) {
|
|
|
161
176
|
return {};
|
|
162
177
|
}
|
|
163
178
|
}
|
|
179
|
+
var init_user_config = () => {};
|
|
164
180
|
|
|
165
181
|
// ../kit/src/theme.ts
|
|
182
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "fs";
|
|
183
|
+
import { homedir as homedir2 } from "os";
|
|
184
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
185
|
+
import process5 from "process";
|
|
166
186
|
function toLinear(channel) {
|
|
167
187
|
const value = channel / 255;
|
|
168
188
|
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
169
189
|
}
|
|
170
|
-
var fromLinear = (value) => Math.round(255 * Math.min(1, Math.max(0, value <= 0.0031308 ? value * 12.92 : 1.055 * value ** (1 / 2.4) - 0.055)));
|
|
171
190
|
function toOklab(hex) {
|
|
172
191
|
const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
|
|
173
192
|
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
@@ -182,7 +201,6 @@ function fromOklab([lightness, a, b]) {
|
|
|
182
201
|
const channels = [4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s, -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s, -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s];
|
|
183
202
|
return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
|
|
184
203
|
}
|
|
185
|
-
var ENDS = new Map;
|
|
186
204
|
function gradientAt(theme, ratio) {
|
|
187
205
|
if (theme.gradient === undefined)
|
|
188
206
|
return;
|
|
@@ -196,33 +214,11 @@ function gradientAt(theme, ratio) {
|
|
|
196
214
|
const [from, to] = ends;
|
|
197
215
|
return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
|
|
198
216
|
}
|
|
199
|
-
var DEFAULT = {
|
|
200
|
-
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
201
|
-
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
|
|
202
|
-
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
203
|
-
bins: {},
|
|
204
|
-
gradient: ["#c084fc", "#67e8f9"]
|
|
205
|
-
};
|
|
206
|
-
var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", plan: "magentaBright", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
207
|
-
var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", plan: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
208
|
-
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
209
|
-
var PRESETS = {
|
|
210
|
-
default: {},
|
|
211
|
-
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
212
|
-
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
213
|
-
ascii: { glyphs: ASCII }
|
|
214
|
-
};
|
|
215
|
-
var STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
|
|
216
|
-
var HEX = /^#[0-9a-f]{6}$/i;
|
|
217
|
-
var CONTROL = /\p{Cc}/u;
|
|
218
|
-
var MAX_FILE_BYTES = 64 * 1024;
|
|
219
|
-
var SPACES = /\s+/;
|
|
220
217
|
function isColorSpec(spec) {
|
|
221
218
|
if (typeof spec === "number")
|
|
222
219
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
223
220
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
224
221
|
}
|
|
225
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
226
222
|
function cubeLevel(channel) {
|
|
227
223
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
228
224
|
}
|
|
@@ -330,7 +326,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
330
326
|
function endsWalk(home) {
|
|
331
327
|
return (dir) => dir === resolve2(home) || existsSync3(join3(dir, ".git"));
|
|
332
328
|
}
|
|
333
|
-
var warned = new Set;
|
|
334
329
|
function warnOnce(message) {
|
|
335
330
|
if (warned.has(message))
|
|
336
331
|
return;
|
|
@@ -367,8 +362,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
367
362
|
}
|
|
368
363
|
return { theme, sources, preset };
|
|
369
364
|
}
|
|
370
|
-
var current;
|
|
371
|
-
var currentKey = "";
|
|
372
365
|
function activeTheme() {
|
|
373
366
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
374
367
|
if (current === undefined || key !== currentKey) {
|
|
@@ -377,9 +370,38 @@ function activeTheme() {
|
|
|
377
370
|
}
|
|
378
371
|
return current;
|
|
379
372
|
}
|
|
373
|
+
var fromLinear = (value) => Math.round(255 * Math.min(1, Math.max(0, value <= 0.0031308 ? value * 12.92 : 1.055 * value ** (1 / 2.4) - 0.055))), ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
|
|
374
|
+
var init_theme = __esm(() => {
|
|
375
|
+
init_config();
|
|
376
|
+
init_user_config();
|
|
377
|
+
ENDS = new Map;
|
|
378
|
+
DEFAULT = {
|
|
379
|
+
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
380
|
+
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
|
|
381
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
382
|
+
bins: {},
|
|
383
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
384
|
+
};
|
|
385
|
+
BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", plan: "magentaBright", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
386
|
+
MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", plan: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
387
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
388
|
+
PRESETS = {
|
|
389
|
+
default: {},
|
|
390
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
391
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
392
|
+
ascii: { glyphs: ASCII }
|
|
393
|
+
};
|
|
394
|
+
STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
|
|
395
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
396
|
+
CONTROL = /\p{Cc}/u;
|
|
397
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
398
|
+
SPACES = /\s+/;
|
|
399
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
400
|
+
warned = new Set;
|
|
401
|
+
});
|
|
380
402
|
|
|
381
403
|
// ../kit/src/style.ts
|
|
382
|
-
|
|
404
|
+
import process6 from "process";
|
|
383
405
|
function takesControlCodes(stream, env = process6.env) {
|
|
384
406
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
385
407
|
}
|
|
@@ -399,17 +421,24 @@ function role(name, stream, env = process6.env) {
|
|
|
399
421
|
const colors = paint(stream, env);
|
|
400
422
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
401
423
|
}
|
|
402
|
-
var STATUS_WORDS
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
424
|
+
var MARK_WORDS, STATUS_WORDS, STATUS_OF;
|
|
425
|
+
var init_style = __esm(() => {
|
|
426
|
+
init_colors();
|
|
427
|
+
init_mode();
|
|
428
|
+
init_theme();
|
|
429
|
+
MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
430
|
+
STATUS_WORDS = {
|
|
431
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
432
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
433
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
434
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
435
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
436
|
+
};
|
|
437
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
438
|
+
});
|
|
410
439
|
|
|
411
440
|
// ../kit/src/format.ts
|
|
412
|
-
|
|
441
|
+
import process7 from "process";
|
|
413
442
|
function formatSeconds(total) {
|
|
414
443
|
let rest = Math.max(0, Math.round(total));
|
|
415
444
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -441,10 +470,8 @@ function formatAge(date, now = Date.now()) {
|
|
|
441
470
|
return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
|
|
442
471
|
}
|
|
443
472
|
function truncate(text, width) {
|
|
444
|
-
return
|
|
473
|
+
return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
445
474
|
}
|
|
446
|
-
var LINE_BREAKS = /\s*\n\s*/g;
|
|
447
|
-
var ESCAPE = String.fromCharCode(27);
|
|
448
475
|
function textWidth(text) {
|
|
449
476
|
return Bun.stringWidth(text);
|
|
450
477
|
}
|
|
@@ -493,14 +520,40 @@ function jsonText(value, replacer, { stream = process7.stdout, env = process7.en
|
|
|
493
520
|
function printJson(value) {
|
|
494
521
|
console.log(jsonText(value));
|
|
495
522
|
}
|
|
523
|
+
var UNITS, LINE_BREAKS, ESCAPE;
|
|
524
|
+
var init_format = __esm(() => {
|
|
525
|
+
init_text();
|
|
526
|
+
init_mode();
|
|
527
|
+
init_style();
|
|
528
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
529
|
+
LINE_BREAKS = /\s*\n\s*/g;
|
|
530
|
+
ESCAPE = String.fromCharCode(27);
|
|
531
|
+
});
|
|
496
532
|
|
|
497
533
|
// ../kit/src/help.ts
|
|
498
534
|
import process8 from "process";
|
|
499
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
500
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
501
|
-
var FULL_STOP = /\.$/;
|
|
502
535
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
503
|
-
|
|
536
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
537
|
+
`);
|
|
538
|
+
const blank = lines.indexOf("");
|
|
539
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
540
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
541
|
+
const colon = synopses[0].indexOf(": ");
|
|
542
|
+
const inline = synopses[0].slice(colon + 2);
|
|
543
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
544
|
+
if (colon !== -1)
|
|
545
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
546
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
547
|
+
`)}`;
|
|
548
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
549
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
550
|
+
return [head, ...lead, ...rest].join(`
|
|
551
|
+
`);
|
|
552
|
+
}
|
|
553
|
+
function prose(line, colors) {
|
|
554
|
+
if (colors.cyan("x") === "x")
|
|
555
|
+
return line;
|
|
556
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
504
557
|
}
|
|
505
558
|
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
506
559
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -535,7 +588,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
535
588
|
return [];
|
|
536
589
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
537
590
|
}
|
|
538
|
-
var MAX_INLINE_CHOICES = 24;
|
|
539
591
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
540
592
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
541
593
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -550,9 +602,17 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
550
602
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
551
603
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
552
604
|
}
|
|
605
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
606
|
+
var init_help = __esm(() => {
|
|
607
|
+
init_mode();
|
|
608
|
+
init_style();
|
|
609
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
610
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
611
|
+
FULL_STOP = /\.$/;
|
|
612
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
613
|
+
});
|
|
553
614
|
|
|
554
615
|
// ../kit/src/text.ts
|
|
555
|
-
var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
556
616
|
function distance(a, b) {
|
|
557
617
|
const left = [...a];
|
|
558
618
|
const right = [...b];
|
|
@@ -578,8 +638,12 @@ function closest(name, names) {
|
|
|
578
638
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
579
639
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
580
640
|
}
|
|
641
|
+
var ANSI;
|
|
642
|
+
var init_text2 = __esm(() => {
|
|
643
|
+
ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
644
|
+
});
|
|
645
|
+
|
|
581
646
|
// ../kit/src/input.ts
|
|
582
|
-
var WHOLE = /^\d+$/;
|
|
583
647
|
function wholeNumber(value, name, fallback, min = 1) {
|
|
584
648
|
if (value === undefined)
|
|
585
649
|
return fallback;
|
|
@@ -588,8 +652,6 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
588
652
|
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
589
653
|
return number;
|
|
590
654
|
}
|
|
591
|
-
var DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
592
|
-
var UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
593
655
|
function duration(value, name, fallback, unit = "s") {
|
|
594
656
|
if (value === undefined)
|
|
595
657
|
return fallback;
|
|
@@ -599,40 +661,27 @@ function duration(value, name, fallback, unit = "s") {
|
|
|
599
661
|
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
600
662
|
return ms;
|
|
601
663
|
}
|
|
664
|
+
var WHOLE, DURATION, UNIT_MS;
|
|
665
|
+
var init_input = __esm(() => {
|
|
666
|
+
init_args();
|
|
667
|
+
WHOLE = /^\d+$/;
|
|
668
|
+
DURATION = /^(\d+(?:\.\d+)?)(ms|[smhd])?$/;
|
|
669
|
+
UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
670
|
+
});
|
|
602
671
|
|
|
603
672
|
// ../kit/src/args.ts
|
|
604
|
-
|
|
673
|
+
import process9 from "process";
|
|
674
|
+
import { parseArgs } from "util";
|
|
605
675
|
function jsonOption(holds) {
|
|
606
676
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
607
677
|
}
|
|
608
|
-
class Exit extends Error {
|
|
609
|
-
code;
|
|
610
|
-
hint;
|
|
611
|
-
constructor(message, code, hint) {
|
|
612
|
-
super(message);
|
|
613
|
-
this.code = code;
|
|
614
|
-
this.hint = hint;
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
678
|
function fail(message, code = 2, hint) {
|
|
618
679
|
throw new Exit(message, code, hint);
|
|
619
680
|
}
|
|
620
|
-
|
|
621
|
-
class UsageError extends Exit {
|
|
622
|
-
constructor(message, hint) {
|
|
623
|
-
super(message, 2, hint);
|
|
624
|
-
}
|
|
625
|
-
}
|
|
626
681
|
function badUsage(message) {
|
|
627
682
|
throw new UsageError(message);
|
|
628
683
|
}
|
|
629
684
|
|
|
630
|
-
class HelpShown extends Exit {
|
|
631
|
-
constructor() {
|
|
632
|
-
super("help shown", 0);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
|
|
636
685
|
class Completing {
|
|
637
686
|
options;
|
|
638
687
|
positionals;
|
|
@@ -643,11 +692,6 @@ class Completing {
|
|
|
643
692
|
this.candidates = candidates;
|
|
644
693
|
}
|
|
645
694
|
}
|
|
646
|
-
var completion = { active: false };
|
|
647
|
-
var OUTPUT_OPTIONS = {
|
|
648
|
-
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
649
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
650
|
-
};
|
|
651
695
|
function applyOutput(color, plain, env = process9.env) {
|
|
652
696
|
const when = plain === true ? "never" : color ?? "auto";
|
|
653
697
|
if (when === "auto")
|
|
@@ -801,7 +845,6 @@ function parseError(error) {
|
|
|
801
845
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
802
846
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
803
847
|
}
|
|
804
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
805
848
|
function nearestOption(message, options, allowNegative) {
|
|
806
849
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
807
850
|
if (typed === undefined)
|
|
@@ -817,6 +860,695 @@ function nearestOption(message, options, allowNegative) {
|
|
|
817
860
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
818
861
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
819
862
|
}
|
|
863
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
864
|
+
var init_args = __esm(() => {
|
|
865
|
+
init_format();
|
|
866
|
+
init_help();
|
|
867
|
+
init_text2();
|
|
868
|
+
init_help();
|
|
869
|
+
init_input();
|
|
870
|
+
DASHES = /^-+/;
|
|
871
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
872
|
+
Exit = class Exit extends Error {
|
|
873
|
+
code;
|
|
874
|
+
hint;
|
|
875
|
+
[EXIT] = true;
|
|
876
|
+
constructor(message, code, hint) {
|
|
877
|
+
super(message);
|
|
878
|
+
this.code = code;
|
|
879
|
+
this.hint = hint;
|
|
880
|
+
}
|
|
881
|
+
static [Symbol.hasInstance](value) {
|
|
882
|
+
if (this !== Exit)
|
|
883
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
884
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
885
|
+
}
|
|
886
|
+
};
|
|
887
|
+
UsageError = class UsageError extends Exit {
|
|
888
|
+
constructor(message, hint) {
|
|
889
|
+
super(message, 2, hint);
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
HelpShown = class HelpShown extends Exit {
|
|
893
|
+
constructor() {
|
|
894
|
+
super("help shown", 0);
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
completion = { active: false };
|
|
898
|
+
OUTPUT_OPTIONS = {
|
|
899
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
900
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
901
|
+
};
|
|
902
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
903
|
+
});
|
|
904
|
+
|
|
905
|
+
// ../kit/src/folders.ts
|
|
906
|
+
import { homedir as homedir3 } from "os";
|
|
907
|
+
import { join as join4 } from "path";
|
|
908
|
+
import process13 from "process";
|
|
909
|
+
function cacheFolder({ home = homedir3(), env = process13.env } = {}) {
|
|
910
|
+
return xdgFolder(env.XDG_CACHE_HOME, join4(home, ".cache"));
|
|
911
|
+
}
|
|
912
|
+
var SKIPPED_FOLDERS;
|
|
913
|
+
var init_folders = __esm(() => {
|
|
914
|
+
init_user_config();
|
|
915
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
// ../kit/src/answers.ts
|
|
919
|
+
import { mkdirSync, readFileSync as readFileSync5, writeFileSync } from "fs";
|
|
920
|
+
import { dirname as dirname2, join as join5 } from "path";
|
|
921
|
+
function answersFile() {
|
|
922
|
+
return join5(cacheFolder(), "kaynooo-cli", "answers.json");
|
|
923
|
+
}
|
|
924
|
+
function stored() {
|
|
925
|
+
try {
|
|
926
|
+
const parsed = JSON.parse(readFileSync5(answersFile(), "utf-8"));
|
|
927
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
928
|
+
return {};
|
|
929
|
+
return Object.fromEntries(Object.entries(parsed).filter((entry) => Array.isArray(entry[1]) && entry[1].every((answer) => typeof answer === "string")));
|
|
930
|
+
} catch {
|
|
931
|
+
return {};
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
function earlierAnswers(key) {
|
|
935
|
+
return stored()[key] ?? [];
|
|
936
|
+
}
|
|
937
|
+
function rememberAnswer(key, answer) {
|
|
938
|
+
const all = stored();
|
|
939
|
+
const file = answersFile();
|
|
940
|
+
all[key] = [answer, ...(all[key] ?? []).filter((earlier) => earlier !== answer)].slice(0, KEPT);
|
|
941
|
+
try {
|
|
942
|
+
mkdirSync(dirname2(file), { recursive: true });
|
|
943
|
+
writeFileSync(file, JSON.stringify(all));
|
|
944
|
+
} catch {}
|
|
945
|
+
}
|
|
946
|
+
var KEPT = 50;
|
|
947
|
+
var init_answers = __esm(() => {
|
|
948
|
+
init_folders();
|
|
949
|
+
});
|
|
950
|
+
|
|
951
|
+
// ../kit/src/job.ts
|
|
952
|
+
import process14 from "process";
|
|
953
|
+
function stopJob() {
|
|
954
|
+
process14.kill(0, "SIGTSTP");
|
|
955
|
+
}
|
|
956
|
+
var init_job = () => {};
|
|
957
|
+
|
|
958
|
+
// ../kit/src/picker/line.ts
|
|
959
|
+
function isEditKey(key) {
|
|
960
|
+
return EDIT_KEYS.has(key);
|
|
961
|
+
}
|
|
962
|
+
function endsKills(key) {
|
|
963
|
+
return typeof key !== "object" && !isEditKey(key);
|
|
964
|
+
}
|
|
965
|
+
function isWord(char) {
|
|
966
|
+
return char !== undefined && WORD_CHARACTER.test(char);
|
|
967
|
+
}
|
|
968
|
+
function wordStart(chars, from) {
|
|
969
|
+
let at = from;
|
|
970
|
+
while (at > 0 && !isWord(chars[at - 1]))
|
|
971
|
+
at--;
|
|
972
|
+
while (at > 0 && isWord(chars[at - 1]))
|
|
973
|
+
at--;
|
|
974
|
+
return at;
|
|
975
|
+
}
|
|
976
|
+
function wordEnd(chars, from) {
|
|
977
|
+
let at = from;
|
|
978
|
+
while (at < chars.length && !isWord(chars[at]))
|
|
979
|
+
at++;
|
|
980
|
+
while (at < chars.length && isWord(chars[at]))
|
|
981
|
+
at++;
|
|
982
|
+
return at;
|
|
983
|
+
}
|
|
984
|
+
function spacedStart(chars, from) {
|
|
985
|
+
let at = from;
|
|
986
|
+
while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
|
|
987
|
+
at--;
|
|
988
|
+
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
989
|
+
at--;
|
|
990
|
+
return at;
|
|
991
|
+
}
|
|
992
|
+
function cut(chars, from, to) {
|
|
993
|
+
return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
|
|
994
|
+
}
|
|
995
|
+
function insert(chars, at, text) {
|
|
996
|
+
const typed = [...text];
|
|
997
|
+
return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
|
|
998
|
+
}
|
|
999
|
+
function editLine(line, key) {
|
|
1000
|
+
const { killed = "", chained = false } = line;
|
|
1001
|
+
const chars = [...line.text];
|
|
1002
|
+
const at = Math.min(Math.max(line.caret, 0), chars.length);
|
|
1003
|
+
const edited = edit(chars, at, key, killed);
|
|
1004
|
+
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
1005
|
+
return line.killed === undefined ? edited : { ...edited, killed };
|
|
1006
|
+
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
1007
|
+
if (taken === "")
|
|
1008
|
+
return { ...edited, killed, chained };
|
|
1009
|
+
if (!chained)
|
|
1010
|
+
return { ...edited, killed: taken, chained: true };
|
|
1011
|
+
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
1012
|
+
}
|
|
1013
|
+
function edit(chars, at, key, killed) {
|
|
1014
|
+
const text = chars.join("");
|
|
1015
|
+
if (typeof key === "object")
|
|
1016
|
+
return insert(chars, at, key.text);
|
|
1017
|
+
switch (key) {
|
|
1018
|
+
case "left":
|
|
1019
|
+
return { text, caret: Math.max(at - 1, 0) };
|
|
1020
|
+
case "right":
|
|
1021
|
+
return { text, caret: Math.min(at + 1, chars.length) };
|
|
1022
|
+
case "wordleft":
|
|
1023
|
+
return { text, caret: wordStart(chars, at) };
|
|
1024
|
+
case "wordright":
|
|
1025
|
+
return { text, caret: wordEnd(chars, at) };
|
|
1026
|
+
case "linestart":
|
|
1027
|
+
return { text, caret: 0 };
|
|
1028
|
+
case "lineend":
|
|
1029
|
+
return { text, caret: chars.length };
|
|
1030
|
+
case "erase":
|
|
1031
|
+
return cut(chars, Math.max(at - 1, 0), at);
|
|
1032
|
+
case "delete":
|
|
1033
|
+
return cut(chars, at, Math.min(at + 1, chars.length));
|
|
1034
|
+
case "word":
|
|
1035
|
+
return cut(chars, spacedStart(chars, at), at);
|
|
1036
|
+
case "killword":
|
|
1037
|
+
return cut(chars, wordStart(chars, at), at);
|
|
1038
|
+
case "killnext":
|
|
1039
|
+
return cut(chars, at, wordEnd(chars, at));
|
|
1040
|
+
case "clear":
|
|
1041
|
+
return cut(chars, 0, at);
|
|
1042
|
+
case "killend":
|
|
1043
|
+
return cut(chars, at, chars.length);
|
|
1044
|
+
case "yank":
|
|
1045
|
+
return insert(chars, at, killed);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
function visible({ text, caret }, room) {
|
|
1049
|
+
const chars = [...text];
|
|
1050
|
+
const at = Math.min(Math.max(caret, 0), chars.length);
|
|
1051
|
+
const cells = at === chars.length ? [...chars, " "] : chars;
|
|
1052
|
+
const widths = cells.map((char) => Bun.stringWidth(char));
|
|
1053
|
+
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
1054
|
+
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
1055
|
+
let start = at;
|
|
1056
|
+
let end = at + 1;
|
|
1057
|
+
while (start > 0 && fits(start - 1, end))
|
|
1058
|
+
start--;
|
|
1059
|
+
while (end < cells.length && fits(start, end + 1))
|
|
1060
|
+
end++;
|
|
1061
|
+
const left = start > 0 ? "\u2026" : "";
|
|
1062
|
+
const right = end < cells.length ? "\u2026" : "";
|
|
1063
|
+
return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
|
|
1064
|
+
}
|
|
1065
|
+
var EDIT_KEYS, BACKWARD_KILLS, FORWARD_KILLS, WORD_CHARACTER, SPACE;
|
|
1066
|
+
var init_line = __esm(() => {
|
|
1067
|
+
EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
1068
|
+
BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
1069
|
+
FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
1070
|
+
WORD_CHARACTER = /[\p{L}\p{N}_]/u;
|
|
1071
|
+
SPACE = /\s/;
|
|
1072
|
+
});
|
|
1073
|
+
|
|
1074
|
+
// ../kit/src/picker/score.ts
|
|
1075
|
+
function startsWord(text, index) {
|
|
1076
|
+
if (index === 0)
|
|
1077
|
+
return true;
|
|
1078
|
+
const before = text[index - 1];
|
|
1079
|
+
return BOUNDARY_AFTER.has(before) || LOWER.test(before) && UPPER.test(text[index]);
|
|
1080
|
+
}
|
|
1081
|
+
function fuzzy(query, text) {
|
|
1082
|
+
if (query === "")
|
|
1083
|
+
return { score: 0, positions: [] };
|
|
1084
|
+
const exact = query !== query.toLowerCase();
|
|
1085
|
+
const needle = exact ? query : query.toLowerCase();
|
|
1086
|
+
const haystack = exact ? text : text.toLowerCase();
|
|
1087
|
+
if (haystack.length !== text.length || needle.length > haystack.length)
|
|
1088
|
+
return;
|
|
1089
|
+
const width = haystack.length;
|
|
1090
|
+
const best = Array.from({ length: needle.length }, () => new Array(width).fill(NONE));
|
|
1091
|
+
const from = Array.from({ length: needle.length }, () => new Array(width).fill(-1));
|
|
1092
|
+
for (let j = 0;j < needle.length; j++) {
|
|
1093
|
+
let run = NONE;
|
|
1094
|
+
let runAt = -1;
|
|
1095
|
+
for (let i = j;i < width; i++) {
|
|
1096
|
+
if (j > 0 && i - 2 >= j - 1) {
|
|
1097
|
+
const candidate = best[j - 1][i - 2] + (i - 2) * GAP;
|
|
1098
|
+
if (candidate > run) {
|
|
1099
|
+
run = candidate;
|
|
1100
|
+
runAt = i - 2;
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
if (haystack[i] !== needle[j])
|
|
1104
|
+
continue;
|
|
1105
|
+
const here = MATCH + (startsWord(text, i) ? BOUNDARY : 0) + (i === 0 ? PREFIX : 0);
|
|
1106
|
+
if (j === 0) {
|
|
1107
|
+
best[0][i] = here - i * GAP;
|
|
1108
|
+
continue;
|
|
1109
|
+
}
|
|
1110
|
+
const joined = best[j - 1][i - 1] + CONSECUTIVE;
|
|
1111
|
+
const skipped = run - (i - 1) * GAP;
|
|
1112
|
+
if (joined > NONE && joined >= skipped) {
|
|
1113
|
+
best[j][i] = joined + here;
|
|
1114
|
+
from[j][i] = i - 1;
|
|
1115
|
+
} else if (skipped > NONE) {
|
|
1116
|
+
best[j][i] = skipped + here;
|
|
1117
|
+
from[j][i] = runAt;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
const last = best[needle.length - 1];
|
|
1122
|
+
let end = -1;
|
|
1123
|
+
for (let i = 0;i < width; i++) {
|
|
1124
|
+
if (last[i] > NONE && (end === -1 || last[i] > last[end]))
|
|
1125
|
+
end = i;
|
|
1126
|
+
}
|
|
1127
|
+
if (end === -1)
|
|
1128
|
+
return;
|
|
1129
|
+
const positions = [];
|
|
1130
|
+
for (let j = needle.length - 1, i = end;j >= 0; j--) {
|
|
1131
|
+
positions.unshift(i);
|
|
1132
|
+
i = from[j][i];
|
|
1133
|
+
}
|
|
1134
|
+
return { score: last[end], positions };
|
|
1135
|
+
}
|
|
1136
|
+
function rank(query, lines) {
|
|
1137
|
+
if (query === "")
|
|
1138
|
+
return lines.map((_, index) => ({ index, positions: [] }));
|
|
1139
|
+
const found = [];
|
|
1140
|
+
for (const [index, line] of lines.entries()) {
|
|
1141
|
+
const match = fuzzy(query, line);
|
|
1142
|
+
if (match !== undefined)
|
|
1143
|
+
found.push({ index, positions: match.positions, score: match.score });
|
|
1144
|
+
}
|
|
1145
|
+
return found.sort((a, b) => b.score - a.score || lines[a.index].length - lines[b.index].length || a.index - b.index);
|
|
1146
|
+
}
|
|
1147
|
+
var MATCH = 16, CONSECUTIVE = 12, BOUNDARY = 10, PREFIX = 8, GAP = 1, BOUNDARY_AFTER, UPPER, LOWER, NONE;
|
|
1148
|
+
var init_score = __esm(() => {
|
|
1149
|
+
BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
1150
|
+
UPPER = /\p{Lu}/u;
|
|
1151
|
+
LOWER = /\p{Ll}/u;
|
|
1152
|
+
NONE = Number.NEGATIVE_INFINITY;
|
|
1153
|
+
});
|
|
1154
|
+
|
|
1155
|
+
// ../kit/src/picker/state.ts
|
|
1156
|
+
function repeat(value, count) {
|
|
1157
|
+
return Array.from({ length: count }).fill(value);
|
|
1158
|
+
}
|
|
1159
|
+
function styled(line) {
|
|
1160
|
+
let text = "";
|
|
1161
|
+
const styles = [];
|
|
1162
|
+
let active = "";
|
|
1163
|
+
let colored = false;
|
|
1164
|
+
let last = 0;
|
|
1165
|
+
function add(chunk) {
|
|
1166
|
+
const flat = chunk.replace(CONTROL2, " ");
|
|
1167
|
+
text += flat;
|
|
1168
|
+
colored ||= active !== "" && flat !== "";
|
|
1169
|
+
styles.push(...repeat(active, flat.length));
|
|
1170
|
+
}
|
|
1171
|
+
for (const found of line.matchAll(ANSI)) {
|
|
1172
|
+
add(line.slice(last, found.index));
|
|
1173
|
+
last = found.index + found[0].length;
|
|
1174
|
+
if (SGR.test(found[0]))
|
|
1175
|
+
active = RESET.test(found[0]) ? "" : active + found[0];
|
|
1176
|
+
}
|
|
1177
|
+
add(line.slice(last));
|
|
1178
|
+
return { text, styles: colored ? styles : undefined };
|
|
1179
|
+
}
|
|
1180
|
+
function lay(rows, searched) {
|
|
1181
|
+
const parsed = rows.map((row) => row.cells.map(styled));
|
|
1182
|
+
const widths = (parsed[0] ?? []).map((_, column) => Math.max(...parsed.map((cells) => Bun.stringWidth(cells[column]?.text ?? ""))));
|
|
1183
|
+
return parsed.map((cells, at) => {
|
|
1184
|
+
let text = "";
|
|
1185
|
+
const styles = [];
|
|
1186
|
+
let colored = false;
|
|
1187
|
+
let searchEnd = 0;
|
|
1188
|
+
for (const [column, cell] of cells.entries()) {
|
|
1189
|
+
const last = column === cells.length - 1;
|
|
1190
|
+
const shown = cells.length > 1 && last ? cell.text.trimEnd() : cell.text;
|
|
1191
|
+
text += shown;
|
|
1192
|
+
colored ||= cell.styles !== undefined;
|
|
1193
|
+
styles.push(...cell.styles?.slice(0, shown.length) ?? repeat("", shown.length));
|
|
1194
|
+
if (column < searched)
|
|
1195
|
+
searchEnd = cells.length > 1 ? text.trimEnd().length : text.length;
|
|
1196
|
+
if (!last) {
|
|
1197
|
+
const pad = widths[column] - Bun.stringWidth(cell.text) + COLUMN_GAP;
|
|
1198
|
+
text += " ".repeat(pad);
|
|
1199
|
+
styles.push(...repeat("", pad));
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
return { text, styles: colored ? styles : undefined, searchable: rows[at].search ?? text.slice(0, searchEnd) };
|
|
1203
|
+
});
|
|
1204
|
+
}
|
|
1205
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
1206
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
1207
|
+
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
1208
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
1209
|
+
if (wheel !== undefined)
|
|
1210
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
1211
|
+
const named = codes.get(sequence);
|
|
1212
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
1213
|
+
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
1214
|
+
paste.active = sequence === PASTE_START;
|
|
1215
|
+
return [];
|
|
1216
|
+
}
|
|
1217
|
+
if (paste.active && (sequence === "\r" || sequence === `
|
|
1218
|
+
`))
|
|
1219
|
+
return [];
|
|
1220
|
+
if (key !== undefined)
|
|
1221
|
+
return [key];
|
|
1222
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
function createState(rows, { multi = false, prompt = "> ", query = "", header = "", expect = [], searched = Number.POSITIVE_INFINITY } = {}) {
|
|
1226
|
+
const state = { rows: [], items: [], styles: [], searchable: [], searched, header, expect, key: "", status: "", query, caret: [...query].length, killed: "", chained: false, matches: [], cursor: 0, help: false, page: 10, marked: new Set, multi, prompt, done: undefined };
|
|
1227
|
+
return withRows(state, rows);
|
|
1228
|
+
}
|
|
1229
|
+
function withRows(state, rows, header = state.header) {
|
|
1230
|
+
const cells = rows.map((row) => typeof row === "string" ? { hidden: [], cells: [row] } : row);
|
|
1231
|
+
const laid = lay(cells, state.searched);
|
|
1232
|
+
const searchable = laid.map((row) => row.searchable);
|
|
1233
|
+
const matches = rank(state.query, searchable);
|
|
1234
|
+
return { ...state, rows: cells, items: laid.map((row) => row.text), styles: laid.map((row) => row.styles), searchable, header, matches, cursor: Math.max(0, Math.min(matches.length - 1, state.cursor)), marked: new Set };
|
|
1235
|
+
}
|
|
1236
|
+
function withQuery(state, key) {
|
|
1237
|
+
const { text, caret, killed = "", chained = false } = editLine({ text: state.query, caret: state.caret, killed: state.killed, chained: state.chained }, key);
|
|
1238
|
+
return text === state.query ? { ...state, caret, killed, chained } : { ...state, query: text, caret, killed, chained, matches: rank(text, state.searchable), cursor: 0 };
|
|
1239
|
+
}
|
|
1240
|
+
function move(state, by) {
|
|
1241
|
+
return { ...state, cursor: Math.max(0, Math.min(state.matches.length - 1, state.cursor + by)) };
|
|
1242
|
+
}
|
|
1243
|
+
function highlighted(state) {
|
|
1244
|
+
return state.matches[state.cursor]?.index;
|
|
1245
|
+
}
|
|
1246
|
+
function press(state, key) {
|
|
1247
|
+
if (state.done !== undefined)
|
|
1248
|
+
return state;
|
|
1249
|
+
if (state.chained && endsKills(key))
|
|
1250
|
+
state = { ...state, chained: false };
|
|
1251
|
+
if (state.help)
|
|
1252
|
+
return { ...state, help: false };
|
|
1253
|
+
if (typeof key === "object") {
|
|
1254
|
+
if ("text" in key)
|
|
1255
|
+
return withQuery(state, key);
|
|
1256
|
+
return state.expect.includes(key.ctrl) ? { ...state, done: "accept", key: key.ctrl } : state;
|
|
1257
|
+
}
|
|
1258
|
+
if (isEditKey(key))
|
|
1259
|
+
return withQuery(state, key);
|
|
1260
|
+
switch (key) {
|
|
1261
|
+
case "up":
|
|
1262
|
+
return move(state, -1);
|
|
1263
|
+
case "down":
|
|
1264
|
+
return move(state, 1);
|
|
1265
|
+
case "pageup":
|
|
1266
|
+
return move(state, -state.page);
|
|
1267
|
+
case "pagedown":
|
|
1268
|
+
return move(state, state.page);
|
|
1269
|
+
case "home":
|
|
1270
|
+
return move(state, -state.matches.length);
|
|
1271
|
+
case "end":
|
|
1272
|
+
return move(state, state.matches.length);
|
|
1273
|
+
case "cancel":
|
|
1274
|
+
return { ...state, done: "cancel" };
|
|
1275
|
+
case "help":
|
|
1276
|
+
return { ...state, help: true };
|
|
1277
|
+
case "suspend":
|
|
1278
|
+
return state;
|
|
1279
|
+
case "enter":
|
|
1280
|
+
return state.matches.length === 0 && state.marked.size === 0 ? state : { ...state, done: "accept" };
|
|
1281
|
+
case "tab": {
|
|
1282
|
+
const at = highlighted(state);
|
|
1283
|
+
if (!state.multi || at === undefined)
|
|
1284
|
+
return state;
|
|
1285
|
+
const marked = new Set(state.marked);
|
|
1286
|
+
if (!marked.delete(at))
|
|
1287
|
+
marked.add(at);
|
|
1288
|
+
return move({ ...state, marked }, 1);
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
function chosen(state) {
|
|
1293
|
+
if (state.marked.size > 0)
|
|
1294
|
+
return state.rows.filter((_, index) => state.marked.has(index));
|
|
1295
|
+
const at = highlighted(state);
|
|
1296
|
+
return at === undefined ? [] : [state.rows[at]];
|
|
1297
|
+
}
|
|
1298
|
+
var CONTROL2, IS_CONTROL, SGR, RESET, COLUMN_GAP = 2, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, MOUSE, WHEEL_LINES = 3, KEYS, CTRL_KEY;
|
|
1299
|
+
var init_state = __esm(() => {
|
|
1300
|
+
init_text2();
|
|
1301
|
+
init_line();
|
|
1302
|
+
init_score();
|
|
1303
|
+
CONTROL2 = /[\x00-\x1F\x7F-\x9F]/g;
|
|
1304
|
+
IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1305
|
+
SGR = /^\x1B\[[0-9;]*m$/;
|
|
1306
|
+
RESET = /^\x1B\[0?m$/;
|
|
1307
|
+
KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1308
|
+
MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1309
|
+
KEYS = {
|
|
1310
|
+
"\x1B[A": "up",
|
|
1311
|
+
"\x1BOA": "up",
|
|
1312
|
+
"\x10": "up",
|
|
1313
|
+
"\x1B[B": "down",
|
|
1314
|
+
"\x1BOB": "down",
|
|
1315
|
+
"\x0E": "down",
|
|
1316
|
+
"\x1B[5~": "pageup",
|
|
1317
|
+
"\x1B[6~": "pagedown",
|
|
1318
|
+
"\x1B[H": "home",
|
|
1319
|
+
"\x1B[1~": "home",
|
|
1320
|
+
"\x1BOH": "home",
|
|
1321
|
+
"\x1B[F": "end",
|
|
1322
|
+
"\x1B[4~": "end",
|
|
1323
|
+
"\x1BOF": "end",
|
|
1324
|
+
"\r": "enter",
|
|
1325
|
+
"\n": "enter",
|
|
1326
|
+
"\x03": "cancel",
|
|
1327
|
+
"\x1B": "cancel",
|
|
1328
|
+
"\x1B[D": "left",
|
|
1329
|
+
"\x1BOD": "left",
|
|
1330
|
+
"\x1B[C": "right",
|
|
1331
|
+
"\x1BOC": "right",
|
|
1332
|
+
"\x1B[1;5D": "wordleft",
|
|
1333
|
+
"\x1B[1;3D": "wordleft",
|
|
1334
|
+
"\x1Bb": "wordleft",
|
|
1335
|
+
"\x1B[1;5C": "wordright",
|
|
1336
|
+
"\x1B[1;3C": "wordright",
|
|
1337
|
+
"\x1Bf": "wordright",
|
|
1338
|
+
"\x01": "linestart",
|
|
1339
|
+
"\x05": "lineend",
|
|
1340
|
+
"\x7F": "erase",
|
|
1341
|
+
"\x1B[3~": "delete",
|
|
1342
|
+
"\b": "killword",
|
|
1343
|
+
"\x1B\x7F": "killword",
|
|
1344
|
+
"\x1B[3;5~": "killnext",
|
|
1345
|
+
"\x1Bd": "killnext",
|
|
1346
|
+
"\x15": "clear",
|
|
1347
|
+
"\v": "killend",
|
|
1348
|
+
"\x17": "word",
|
|
1349
|
+
"\x19": "yank",
|
|
1350
|
+
"\x1A": "suspend",
|
|
1351
|
+
"\t": "tab",
|
|
1352
|
+
"\x1F": "help",
|
|
1353
|
+
"\x1BOP": "help",
|
|
1354
|
+
"\x1B[11~": "help"
|
|
1355
|
+
};
|
|
1356
|
+
CTRL_KEY = /^ctrl-[abd-gkln-z]$/;
|
|
1357
|
+
});
|
|
1358
|
+
|
|
1359
|
+
// ../kit/src/redraw.ts
|
|
1360
|
+
function overwrite(lines, columns) {
|
|
1361
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
1362
|
+
`);
|
|
1363
|
+
}
|
|
1364
|
+
function rowsTaken(lines, columns) {
|
|
1365
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
1366
|
+
}
|
|
1367
|
+
var SYNC_START = "\x1B[?2026h", SYNC_END = "\x1B[?2026l";
|
|
1368
|
+
var init_redraw = __esm(() => {
|
|
1369
|
+
init_format();
|
|
1370
|
+
});
|
|
1371
|
+
|
|
1372
|
+
// ../kit/src/prompt.ts
|
|
1373
|
+
import process15 from "process";
|
|
1374
|
+
function readKeys(input, paste = { active: false }) {
|
|
1375
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
1376
|
+
}
|
|
1377
|
+
function roomAfter(question, columns) {
|
|
1378
|
+
return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
|
|
1379
|
+
}
|
|
1380
|
+
function withCaret(colors, line, room, dim = false) {
|
|
1381
|
+
const { before, at, after } = visible(line, room);
|
|
1382
|
+
const tone = dim ? colors.dim : (text) => text;
|
|
1383
|
+
return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
|
|
1384
|
+
}
|
|
1385
|
+
function sharedStart(texts) {
|
|
1386
|
+
const [first = [], ...rest] = texts.map((text) => [...text]);
|
|
1387
|
+
let length = first.length;
|
|
1388
|
+
for (const chars of rest) {
|
|
1389
|
+
const differs = chars.findIndex((char, index) => char !== first[index]);
|
|
1390
|
+
length = Math.min(length, differs === -1 ? chars.length : differs);
|
|
1391
|
+
}
|
|
1392
|
+
return first.slice(0, length).join("");
|
|
1393
|
+
}
|
|
1394
|
+
function listed2(colors, found, columns) {
|
|
1395
|
+
const shared = sharedStart(found);
|
|
1396
|
+
const cut = Math.max(shared.lastIndexOf("/"), shared.lastIndexOf(" ")) + 1;
|
|
1397
|
+
const names = found.slice(0, MAX_LISTED).map((each) => each.slice(cut));
|
|
1398
|
+
const more = found.length > MAX_LISTED ? ` \u2026 ${found.length - MAX_LISTED} more` : "";
|
|
1399
|
+
return ` ${colors.dim(truncate(names.join(" ") + more, Math.max(columns - 3, 1)))}`;
|
|
1400
|
+
}
|
|
1401
|
+
async function input2(question, { default: fallback, mask = false, validate, history, complete, ...settings } = {}) {
|
|
1402
|
+
let line = { text: "", caret: 0 };
|
|
1403
|
+
let invalid;
|
|
1404
|
+
let completions = [];
|
|
1405
|
+
const remembered = history === undefined || mask ? undefined : history;
|
|
1406
|
+
const earlier = remembered === undefined ? [] : earlierAnswers(remembered);
|
|
1407
|
+
let recalled = -1;
|
|
1408
|
+
let draft = line;
|
|
1409
|
+
const taken = () => line.text === "" ? fallback ?? "" : line.text;
|
|
1410
|
+
const shown = () => mask ? "*".repeat([...taken()].length) : taken();
|
|
1411
|
+
const accepted = await ask(question, settings, (colors, state, { columns }) => {
|
|
1412
|
+
if (state !== "asking")
|
|
1413
|
+
return [answer(colors, question, state, shown())];
|
|
1414
|
+
const typed = line.text === "" ? { text: shown(), caret: [...shown()].length } : { text: shown(), caret: line.caret };
|
|
1415
|
+
return [`${colors.cyan("?")} ${question} ${withCaret(colors, typed, roomAfter(question, columns), line.text === "")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`], ...completions.length > 1 ? [listed2(colors, completions, columns)] : []];
|
|
1416
|
+
}, (key) => {
|
|
1417
|
+
if (key === "cancel")
|
|
1418
|
+
return "cancel";
|
|
1419
|
+
invalid = undefined;
|
|
1420
|
+
completions = [];
|
|
1421
|
+
if (line.chained === true && endsKills(key))
|
|
1422
|
+
line = { ...line, chained: false };
|
|
1423
|
+
if (key === "tab") {
|
|
1424
|
+
const chars = [...line.text];
|
|
1425
|
+
const before = chars.slice(0, line.caret).join("");
|
|
1426
|
+
const found = complete?.(before) ?? [];
|
|
1427
|
+
const filled = sharedStart(found);
|
|
1428
|
+
if ([...filled].length > [...before].length)
|
|
1429
|
+
line = { ...line, text: filled + chars.slice(line.caret).join(""), caret: [...filled].length };
|
|
1430
|
+
else
|
|
1431
|
+
completions = found;
|
|
1432
|
+
return;
|
|
1433
|
+
}
|
|
1434
|
+
if (key === "enter") {
|
|
1435
|
+
invalid = validate?.(taken());
|
|
1436
|
+
return invalid === undefined ? "enter" : undefined;
|
|
1437
|
+
}
|
|
1438
|
+
if (key === "up" || key === "down") {
|
|
1439
|
+
const to = Math.min(Math.max(recalled + (key === "up" ? 1 : -1), -1), earlier.length - 1);
|
|
1440
|
+
if (recalled === -1)
|
|
1441
|
+
draft = line;
|
|
1442
|
+
recalled = to;
|
|
1443
|
+
const shown = to === -1 ? draft : { text: earlier[to], caret: [...earlier[to]].length };
|
|
1444
|
+
line = { ...shown, killed: line.killed ?? "" };
|
|
1445
|
+
return;
|
|
1446
|
+
}
|
|
1447
|
+
const edit = { home: "linestart", end: "lineend" }[key] ?? key;
|
|
1448
|
+
if (typeof edit === "object" || isEditKey(edit))
|
|
1449
|
+
line = editLine(line, edit);
|
|
1450
|
+
return;
|
|
1451
|
+
});
|
|
1452
|
+
if (!accepted)
|
|
1453
|
+
return;
|
|
1454
|
+
if (remembered !== undefined && taken() !== "")
|
|
1455
|
+
rememberAnswer(remembered, taken());
|
|
1456
|
+
return taken();
|
|
1457
|
+
}
|
|
1458
|
+
function answer(colors, question, state, picked) {
|
|
1459
|
+
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
1460
|
+
}
|
|
1461
|
+
async function ask(question, { hint, terminal = process15 }, render, press) {
|
|
1462
|
+
const { stdin, stderr } = terminal;
|
|
1463
|
+
if (!isInteractive(terminal))
|
|
1464
|
+
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
1465
|
+
const colors = paint(stderr);
|
|
1466
|
+
let current = "asking";
|
|
1467
|
+
let outcome;
|
|
1468
|
+
const columns = () => stderr.columns || 80;
|
|
1469
|
+
const draw = (state, last = false) => {
|
|
1470
|
+
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
1471
|
+
const rows = rowsTaken(frame, columns());
|
|
1472
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
1473
|
+
current = state;
|
|
1474
|
+
};
|
|
1475
|
+
const redraw = () => draw(current);
|
|
1476
|
+
const paste = { active: false };
|
|
1477
|
+
const stop = terminal.stop ?? (terminal === process15 ? stopJob : undefined);
|
|
1478
|
+
const suspend = () => {
|
|
1479
|
+
if (stop === undefined)
|
|
1480
|
+
return;
|
|
1481
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
1482
|
+
stdin.setRawMode(false);
|
|
1483
|
+
stop();
|
|
1484
|
+
stdin.setRawMode(true);
|
|
1485
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1486
|
+
};
|
|
1487
|
+
try {
|
|
1488
|
+
stderr.on?.("resize", redraw);
|
|
1489
|
+
stdin.setRawMode(true);
|
|
1490
|
+
stdin.resume();
|
|
1491
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1492
|
+
draw("asking");
|
|
1493
|
+
return await new Promise((resolve) => {
|
|
1494
|
+
function onData(data) {
|
|
1495
|
+
for (const key of readKeys(data.toString(), paste)) {
|
|
1496
|
+
if (key === "suspend") {
|
|
1497
|
+
suspend();
|
|
1498
|
+
continue;
|
|
1499
|
+
}
|
|
1500
|
+
const pressed = press(key);
|
|
1501
|
+
if (pressed !== undefined) {
|
|
1502
|
+
settle(pressed);
|
|
1503
|
+
return;
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
draw("asking");
|
|
1507
|
+
}
|
|
1508
|
+
function onEnd() {
|
|
1509
|
+
settle("cancel");
|
|
1510
|
+
}
|
|
1511
|
+
function settle(settled) {
|
|
1512
|
+
outcome = settled;
|
|
1513
|
+
stdin.off("data", onData);
|
|
1514
|
+
stdin.off("end", onEnd);
|
|
1515
|
+
resolve(settled === "enter");
|
|
1516
|
+
}
|
|
1517
|
+
stdin.on("data", onData);
|
|
1518
|
+
stdin.on("end", onEnd);
|
|
1519
|
+
});
|
|
1520
|
+
} finally {
|
|
1521
|
+
stderr.off?.("resize", redraw);
|
|
1522
|
+
draw(outcome ?? "cancel", true);
|
|
1523
|
+
stderr.write(`
|
|
1524
|
+
\x1B[?25h\x1B[?2004l`);
|
|
1525
|
+
stdin.setRawMode(false);
|
|
1526
|
+
stdin.pause();
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
var PROMPT_KEYS, MAX_LISTED = 12;
|
|
1530
|
+
var init_prompt = __esm(() => {
|
|
1531
|
+
init_answers();
|
|
1532
|
+
init_args();
|
|
1533
|
+
init_format();
|
|
1534
|
+
init_job();
|
|
1535
|
+
init_mode();
|
|
1536
|
+
init_line();
|
|
1537
|
+
init_state();
|
|
1538
|
+
init_redraw();
|
|
1539
|
+
init_style();
|
|
1540
|
+
PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
1541
|
+
});
|
|
1542
|
+
|
|
1543
|
+
// src/gcl.ts
|
|
1544
|
+
import { existsSync as existsSync4, readdirSync, realpathSync as realpathSync3, statSync as statSync2 } from "fs";
|
|
1545
|
+
import { homedir as homedir6 } from "os";
|
|
1546
|
+
import { basename, join as join11, resolve as resolve6 } from "path";
|
|
1547
|
+
import process24 from "process";
|
|
1548
|
+
|
|
1549
|
+
// ../kit/src/index.ts
|
|
1550
|
+
init_args();
|
|
1551
|
+
|
|
820
1552
|
// ../kit/src/argv.ts
|
|
821
1553
|
import { readFileSync as readFileSync3, realpathSync } from "fs";
|
|
822
1554
|
import { resolve as resolve3 } from "path";
|
|
@@ -841,14 +1573,26 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
|
|
|
841
1573
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
842
1574
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
843
1575
|
}
|
|
1576
|
+
// ../kit/src/chart.ts
|
|
1577
|
+
init_format();
|
|
1578
|
+
init_mode();
|
|
1579
|
+
init_style();
|
|
1580
|
+
init_theme();
|
|
1581
|
+
// ../kit/src/ci.ts
|
|
1582
|
+
init_args();
|
|
1583
|
+
init_format();
|
|
1584
|
+
|
|
844
1585
|
// ../kit/src/progress.ts
|
|
1586
|
+
init_format();
|
|
845
1587
|
import process12 from "process";
|
|
846
1588
|
|
|
847
1589
|
// ../kit/src/process.ts
|
|
1590
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
848
1591
|
import { constants } from "os";
|
|
849
1592
|
import process11 from "process";
|
|
850
1593
|
var KILL_GRACE_MS = 2000;
|
|
851
1594
|
var SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
1595
|
+
var GROUP_SIGNALS = new Set(["SIGINT", "SIGHUP"]);
|
|
852
1596
|
function exitCodeOf(code, signal) {
|
|
853
1597
|
if (code !== null)
|
|
854
1598
|
return code;
|
|
@@ -856,6 +1600,21 @@ function exitCodeOf(code, signal) {
|
|
|
856
1600
|
return 128 + signal;
|
|
857
1601
|
return signal === null ? 129 : 128 + constants.signals[signal];
|
|
858
1602
|
}
|
|
1603
|
+
function groupsOf(pid) {
|
|
1604
|
+
try {
|
|
1605
|
+
const stat = readFileSync4(`/proc/${pid}/stat`, "utf8");
|
|
1606
|
+
const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
1607
|
+
return { group: Number(fields[2]), foreground: Number(fields[5]) };
|
|
1608
|
+
} catch {
|
|
1609
|
+
return;
|
|
1610
|
+
}
|
|
1611
|
+
}
|
|
1612
|
+
function heardTheTerminal(child) {
|
|
1613
|
+
if (child.pid === undefined)
|
|
1614
|
+
return false;
|
|
1615
|
+
const own = groupsOf("self");
|
|
1616
|
+
return own !== undefined && own.group === own.foreground && groupsOf(child.pid)?.group === own.group;
|
|
1617
|
+
}
|
|
859
1618
|
function holdSignals(cleanup) {
|
|
860
1619
|
let received;
|
|
861
1620
|
let child;
|
|
@@ -874,7 +1633,8 @@ function holdSignals(cleanup) {
|
|
|
874
1633
|
function onSignal(signal) {
|
|
875
1634
|
received = signal;
|
|
876
1635
|
if (child !== undefined) {
|
|
877
|
-
|
|
1636
|
+
if (!GROUP_SIGNALS.has(signal) || !heardTheTerminal(child))
|
|
1637
|
+
child.kill(signal);
|
|
878
1638
|
return;
|
|
879
1639
|
}
|
|
880
1640
|
if (cleanup === undefined)
|
|
@@ -887,10 +1647,10 @@ function holdSignals(cleanup) {
|
|
|
887
1647
|
process11.on(signal, onSignal);
|
|
888
1648
|
return held;
|
|
889
1649
|
}
|
|
890
|
-
async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
1650
|
+
async function runCommand(argv, { cwd, env, stdin = "ignore", input, timeoutMs, signal, maxBytes = Infinity, onChunk, onStart } = {}) {
|
|
891
1651
|
const chunks = [];
|
|
892
1652
|
const grouped = timeoutMs !== undefined || signal !== undefined || onStart !== undefined || onChunk !== undefined;
|
|
893
|
-
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin, stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
1653
|
+
const proc = Bun.spawn(argv, { ...cwd === undefined ? {} : { cwd }, ...env === undefined ? {} : { env }, stdin: input === undefined ? stdin : new TextEncoder().encode(input), stdout: "pipe", stderr: "pipe", ...grouped ? { detached: true } : {} });
|
|
894
1654
|
const state = { kept: 0, truncated: false, timedOut: false, failure: undefined, done: false };
|
|
895
1655
|
const timers = [];
|
|
896
1656
|
const killGroup = (killing) => {
|
|
@@ -930,12 +1690,19 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
930
1690
|
stop();
|
|
931
1691
|
continue;
|
|
932
1692
|
}
|
|
1693
|
+
if (state.truncated)
|
|
1694
|
+
continue;
|
|
1695
|
+
let kept = data;
|
|
933
1696
|
if (state.kept + data.length > maxBytes) {
|
|
1697
|
+
let cut = maxBytes - state.kept;
|
|
1698
|
+
while (cut > 0 && ((data[cut] ?? 0) & 192) === 128)
|
|
1699
|
+
cut--;
|
|
1700
|
+
kept = data.subarray(0, cut);
|
|
934
1701
|
state.truncated = true;
|
|
935
|
-
continue;
|
|
936
1702
|
}
|
|
937
|
-
state.kept +=
|
|
938
|
-
|
|
1703
|
+
state.kept += kept.length;
|
|
1704
|
+
if (kept.length > 0)
|
|
1705
|
+
chunks.push({ stream: name, data: kept });
|
|
939
1706
|
}
|
|
940
1707
|
};
|
|
941
1708
|
try {
|
|
@@ -952,6 +1719,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
952
1719
|
const joined = () => Buffer.concat(chunks.map(({ data }) => data));
|
|
953
1720
|
let output;
|
|
954
1721
|
let text;
|
|
1722
|
+
let stdout;
|
|
955
1723
|
return {
|
|
956
1724
|
code: exitCodeOf(proc.exitCode, proc.signalCode),
|
|
957
1725
|
chunks,
|
|
@@ -962,11 +1730,16 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
962
1730
|
},
|
|
963
1731
|
get text() {
|
|
964
1732
|
return text ??= (output ??= joined()).toString();
|
|
1733
|
+
},
|
|
1734
|
+
get stdout() {
|
|
1735
|
+
return stdout ??= Buffer.concat(chunks.filter((chunk) => chunk.stream === "stdout").map((chunk) => chunk.data)).toString();
|
|
965
1736
|
}
|
|
966
1737
|
};
|
|
967
1738
|
}
|
|
968
1739
|
|
|
969
1740
|
// ../kit/src/progress.ts
|
|
1741
|
+
init_style();
|
|
1742
|
+
init_theme();
|
|
970
1743
|
var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
971
1744
|
var FRAME_MS = 200;
|
|
972
1745
|
var BAR_WIDTH = 20;
|
|
@@ -984,10 +1757,14 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
984
1757
|
}, print: (text) => void stream.write(`${text}
|
|
985
1758
|
`), stop: () => {
|
|
986
1759
|
return;
|
|
1760
|
+
}, pause: () => () => {
|
|
1761
|
+
return;
|
|
987
1762
|
} };
|
|
988
1763
|
const write = stream.write.bind(stream);
|
|
989
1764
|
let frame = 0;
|
|
990
1765
|
let drawn = false;
|
|
1766
|
+
let paused = false;
|
|
1767
|
+
let stopped = false;
|
|
991
1768
|
const columns = () => {
|
|
992
1769
|
const now = stream.getWindowSize?.()[0] ?? stream.columns;
|
|
993
1770
|
return now === undefined || now === 0 ? 80 : now;
|
|
@@ -998,6 +1775,8 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
998
1775
|
drawn = false;
|
|
999
1776
|
};
|
|
1000
1777
|
const draw = () => {
|
|
1778
|
+
if (paused)
|
|
1779
|
+
return;
|
|
1001
1780
|
const width = columns() - 1;
|
|
1002
1781
|
const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
|
|
1003
1782
|
const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
|
|
@@ -1009,16 +1788,17 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
1009
1788
|
`)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
|
|
1010
1789
|
drawn = true;
|
|
1011
1790
|
};
|
|
1012
|
-
|
|
1791
|
+
let timer = setInterval(draw, FRAME_MS);
|
|
1013
1792
|
stream.on?.("resize", draw);
|
|
1014
|
-
|
|
1015
|
-
|
|
1793
|
+
let restore = interceptOutput(clear);
|
|
1794
|
+
let release = swallowInput();
|
|
1016
1795
|
const onExit = () => {
|
|
1017
1796
|
clear();
|
|
1018
1797
|
release();
|
|
1019
1798
|
};
|
|
1020
1799
|
const signals = holdSignals(stop);
|
|
1021
1800
|
function stop() {
|
|
1801
|
+
stopped = true;
|
|
1022
1802
|
clearInterval(timer);
|
|
1023
1803
|
stream.off?.("resize", draw);
|
|
1024
1804
|
clear();
|
|
@@ -1027,6 +1807,29 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
1027
1807
|
process12.off("exit", onExit);
|
|
1028
1808
|
signals.release();
|
|
1029
1809
|
}
|
|
1810
|
+
function pause() {
|
|
1811
|
+
if (paused || stopped)
|
|
1812
|
+
return () => {
|
|
1813
|
+
return;
|
|
1814
|
+
};
|
|
1815
|
+
paused = true;
|
|
1816
|
+
clearInterval(timer);
|
|
1817
|
+
stream.off?.("resize", draw);
|
|
1818
|
+
clear();
|
|
1819
|
+
restore();
|
|
1820
|
+
release();
|
|
1821
|
+
return () => {
|
|
1822
|
+
if (!paused || stopped)
|
|
1823
|
+
return;
|
|
1824
|
+
paused = false;
|
|
1825
|
+
timer = setInterval(draw, FRAME_MS);
|
|
1826
|
+
timer.unref();
|
|
1827
|
+
stream.on?.("resize", draw);
|
|
1828
|
+
restore = interceptOutput(clear);
|
|
1829
|
+
release = swallowInput();
|
|
1830
|
+
draw();
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1030
1833
|
timer.unref();
|
|
1031
1834
|
process12.on("exit", onExit);
|
|
1032
1835
|
return {
|
|
@@ -1037,7 +1840,8 @@ function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
|
1037
1840
|
`);
|
|
1038
1841
|
draw();
|
|
1039
1842
|
},
|
|
1040
|
-
stop
|
|
1843
|
+
stop,
|
|
1844
|
+
pause
|
|
1041
1845
|
};
|
|
1042
1846
|
}
|
|
1043
1847
|
function progressLine(stream = process12.stderr, env = process12.env) {
|
|
@@ -1062,6 +1866,7 @@ function progressLine(stream = process12.stderr, env = process12.env) {
|
|
|
1062
1866
|
}
|
|
1063
1867
|
},
|
|
1064
1868
|
stop: region.stop,
|
|
1869
|
+
pause: region.pause,
|
|
1065
1870
|
done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
|
|
1066
1871
|
failed: (text) => end(marked("problem", text, stream, undefined, env))
|
|
1067
1872
|
};
|
|
@@ -1150,10 +1955,127 @@ function interceptOutput(clear) {
|
|
|
1150
1955
|
}
|
|
1151
1956
|
};
|
|
1152
1957
|
}
|
|
1958
|
+
|
|
1959
|
+
// ../kit/src/ci.ts
|
|
1960
|
+
init_style();
|
|
1961
|
+
|
|
1962
|
+
// ../kit/src/tool.ts
|
|
1963
|
+
init_format();
|
|
1153
1964
|
// ../kit/src/cli.ts
|
|
1154
|
-
|
|
1155
|
-
import {
|
|
1156
|
-
import
|
|
1965
|
+
init_args();
|
|
1966
|
+
import { readFileSync as readFileSync6, realpathSync as realpathSync2 } from "fs";
|
|
1967
|
+
import { dirname as dirname4, join as join8 } from "path";
|
|
1968
|
+
import process19 from "process";
|
|
1969
|
+
|
|
1970
|
+
// ../kit/src/askpass.ts
|
|
1971
|
+
import { chmodSync, mkdtempSync, rmSync, writeFileSync as writeFileSync2 } from "fs";
|
|
1972
|
+
import { tmpdir } from "os";
|
|
1973
|
+
import { join as join6 } from "path";
|
|
1974
|
+
import process16 from "process";
|
|
1975
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1976
|
+
var ECHOED = /username|yes\/no/i;
|
|
1977
|
+
var quoted = (text) => `'${text.replaceAll("'", `'\\''`)}'`;
|
|
1978
|
+
function askpass(pause = () => () => {
|
|
1979
|
+
return;
|
|
1980
|
+
}) {
|
|
1981
|
+
if (process16.stdin.isTTY !== true || process16.stderr.isTTY !== true || process16.argv[1] === undefined)
|
|
1982
|
+
return;
|
|
1983
|
+
const dir = mkdtempSync(join6(tmpdir(), "kaynooo-askpass-"));
|
|
1984
|
+
const socketPath = join6(dir, "socket");
|
|
1985
|
+
const script = join6(dir, "askpass");
|
|
1986
|
+
let turn = Promise.resolve();
|
|
1987
|
+
const answer = async ({ prompt, notice }) => {
|
|
1988
|
+
const resume = pause();
|
|
1989
|
+
try {
|
|
1990
|
+
if (notice === true) {
|
|
1991
|
+
process16.stderr.write(`${prompt.trim()}
|
|
1992
|
+
`);
|
|
1993
|
+
return {};
|
|
1994
|
+
}
|
|
1995
|
+
await Promise.resolve().then(() => init_prompt());
|
|
1996
|
+
return { answer: await input2(prompt.trim(), { mask: !ECHOED.test(prompt) }) };
|
|
1997
|
+
} finally {
|
|
1998
|
+
resume();
|
|
1999
|
+
}
|
|
2000
|
+
};
|
|
2001
|
+
const respond = async (socket, request) => {
|
|
2002
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
2003
|
+
const previous = turn;
|
|
2004
|
+
let reply = {};
|
|
2005
|
+
turn = promise;
|
|
2006
|
+
await previous;
|
|
2007
|
+
try {
|
|
2008
|
+
reply = await answer(request);
|
|
2009
|
+
} catch {} finally {
|
|
2010
|
+
socket.end(`${JSON.stringify(reply)}
|
|
2011
|
+
`);
|
|
2012
|
+
resolve();
|
|
2013
|
+
}
|
|
2014
|
+
};
|
|
2015
|
+
const server = Bun.listen({
|
|
2016
|
+
unix: socketPath,
|
|
2017
|
+
socket: {
|
|
2018
|
+
open: (socket) => {
|
|
2019
|
+
socket.data = { buffered: "" };
|
|
2020
|
+
},
|
|
2021
|
+
data: (socket, chunk) => {
|
|
2022
|
+
const before = socket.data.buffered;
|
|
2023
|
+
socket.data.buffered += chunk.toString();
|
|
2024
|
+
if (before.includes(`
|
|
2025
|
+
`) || !socket.data.buffered.includes(`
|
|
2026
|
+
`))
|
|
2027
|
+
return;
|
|
2028
|
+
respond(socket, JSON.parse(socket.data.buffered));
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
});
|
|
2032
|
+
writeFileSync2(script, `#!/bin/sh
|
|
2033
|
+
${SOCKET_VARIABLE}=${quoted(socketPath)} exec ${quoted(process16.execPath)} --no-env-file --config=/dev/null ${quoted(process16.argv[1])} "$@"
|
|
2034
|
+
`);
|
|
2035
|
+
chmodSync(script, 448);
|
|
2036
|
+
return {
|
|
2037
|
+
env: { GIT_ASKPASS: script, SSH_ASKPASS: script, SSH_ASKPASS_REQUIRE: "force" },
|
|
2038
|
+
close: () => {
|
|
2039
|
+
server.stop(true);
|
|
2040
|
+
rmSync(dir, { recursive: true, force: true });
|
|
2041
|
+
}
|
|
2042
|
+
};
|
|
2043
|
+
}
|
|
2044
|
+
async function askpassClient(argv) {
|
|
2045
|
+
const socketPath = process16.env[SOCKET_VARIABLE];
|
|
2046
|
+
if (socketPath === undefined)
|
|
2047
|
+
return;
|
|
2048
|
+
const request = { prompt: argv[0] ?? "", ...process16.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
2049
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
2050
|
+
let received = "";
|
|
2051
|
+
try {
|
|
2052
|
+
await Bun.connect({
|
|
2053
|
+
unix: socketPath,
|
|
2054
|
+
socket: {
|
|
2055
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
2056
|
+
`),
|
|
2057
|
+
data: (_, chunk) => {
|
|
2058
|
+
received += chunk.toString();
|
|
2059
|
+
},
|
|
2060
|
+
close: () => resolve(received),
|
|
2061
|
+
error: () => resolve("")
|
|
2062
|
+
}
|
|
2063
|
+
});
|
|
2064
|
+
} catch {
|
|
2065
|
+
return 1;
|
|
2066
|
+
}
|
|
2067
|
+
const reply = await promise;
|
|
2068
|
+
if (reply === "")
|
|
2069
|
+
return 1;
|
|
2070
|
+
const { answer } = JSON.parse(reply);
|
|
2071
|
+
if (request.notice === true)
|
|
2072
|
+
return 0;
|
|
2073
|
+
if (answer === undefined)
|
|
2074
|
+
return 1;
|
|
2075
|
+
process16.stdout.write(`${answer}
|
|
2076
|
+
`);
|
|
2077
|
+
return 0;
|
|
2078
|
+
}
|
|
1157
2079
|
|
|
1158
2080
|
// ../kit/src/completions.ts
|
|
1159
2081
|
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
@@ -1216,34 +2138,42 @@ compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
|
1216
2138
|
}
|
|
1217
2139
|
|
|
1218
2140
|
// ../kit/src/notify.ts
|
|
1219
|
-
|
|
2141
|
+
init_format();
|
|
2142
|
+
init_mode();
|
|
2143
|
+
import process17 from "process";
|
|
1220
2144
|
var NOTIFY_AFTER_MS = 1e4;
|
|
1221
2145
|
var CANCELLED = 130;
|
|
1222
2146
|
function base64(text) {
|
|
1223
2147
|
return Buffer.from(text).toString("base64");
|
|
1224
2148
|
}
|
|
1225
|
-
function notification(title, body, env =
|
|
1226
|
-
const id = `kit${
|
|
2149
|
+
function notification(title, body, env = process17.env) {
|
|
2150
|
+
const id = `kit${process17.pid}`;
|
|
1227
2151
|
const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
|
|
1228
2152
|
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1229
2153
|
}
|
|
1230
|
-
function notifyEnd(command, code, ms, { stream =
|
|
2154
|
+
function notifyEnd(command, code, ms, { stream = process17.stderr, env = process17.env } = {}) {
|
|
1231
2155
|
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1232
2156
|
return;
|
|
1233
2157
|
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1234
2158
|
}
|
|
1235
2159
|
|
|
2160
|
+
// ../kit/src/cli.ts
|
|
2161
|
+
init_style();
|
|
2162
|
+
init_text2();
|
|
2163
|
+
|
|
1236
2164
|
// ../kit/src/usage.ts
|
|
1237
|
-
import { appendFileSync, mkdirSync } from "fs";
|
|
1238
|
-
import { homedir as
|
|
1239
|
-
import { dirname as
|
|
1240
|
-
import
|
|
2165
|
+
import { appendFileSync, mkdirSync as mkdirSync2 } from "fs";
|
|
2166
|
+
import { homedir as homedir4 } from "os";
|
|
2167
|
+
import { dirname as dirname3, join as join7 } from "path";
|
|
2168
|
+
import process18 from "process";
|
|
1241
2169
|
|
|
1242
2170
|
// ../kit/src/logs.ts
|
|
2171
|
+
init_user_config();
|
|
1243
2172
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
1244
2173
|
var CLI_FOLDER = "kaynooo-cli";
|
|
1245
2174
|
|
|
1246
2175
|
// ../kit/src/usage.ts
|
|
2176
|
+
init_user_config();
|
|
1247
2177
|
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
1248
2178
|
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
1249
2179
|
var LONGEST_NAME = 40;
|
|
@@ -1251,14 +2181,13 @@ var usageError;
|
|
|
1251
2181
|
function noteUsageError(message) {
|
|
1252
2182
|
usageError = message;
|
|
1253
2183
|
}
|
|
1254
|
-
function stateHome(env =
|
|
1255
|
-
|
|
1256
|
-
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
2184
|
+
function stateHome(env = process18.env) {
|
|
2185
|
+
return xdgFolder(env.XDG_STATE_HOME, join7(homedir4(), ".local", "state"));
|
|
1257
2186
|
}
|
|
1258
|
-
function usagePath(env =
|
|
1259
|
-
return
|
|
2187
|
+
function usagePath(env = process18.env) {
|
|
2188
|
+
return join7(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1260
2189
|
}
|
|
1261
|
-
function usageRecorded(env =
|
|
2190
|
+
function usageRecorded(env = process18.env) {
|
|
1262
2191
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1263
2192
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1264
2193
|
}
|
|
@@ -1267,17 +2196,17 @@ function flagNames(argv) {
|
|
|
1267
2196
|
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
1268
2197
|
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
1269
2198
|
}
|
|
1270
|
-
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
2199
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
1271
2200
|
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
1272
2201
|
usageError = undefined;
|
|
1273
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
2202
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
1274
2203
|
}
|
|
1275
|
-
function recordUsage(entry, env =
|
|
2204
|
+
function recordUsage(entry, env = process18.env) {
|
|
1276
2205
|
if (!usageRecorded(env))
|
|
1277
2206
|
return;
|
|
1278
2207
|
try {
|
|
1279
2208
|
const path = usagePath(env);
|
|
1280
|
-
|
|
2209
|
+
mkdirSync2(dirname3(path), { recursive: true, mode: 448 });
|
|
1281
2210
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
1282
2211
|
`, { mode: 384 });
|
|
1283
2212
|
} catch {}
|
|
@@ -1294,8 +2223,8 @@ var TOP_OPTIONS = {
|
|
|
1294
2223
|
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1295
2224
|
};
|
|
1296
2225
|
function printError(prefix, message, hint, cause) {
|
|
1297
|
-
const colors = paint(
|
|
1298
|
-
const styled = takesControlCodes(
|
|
2226
|
+
const colors = paint(process19.stderr);
|
|
2227
|
+
const styled = takesControlCodes(process19.stderr);
|
|
1299
2228
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1300
2229
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1301
2230
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -1398,17 +2327,20 @@ function packageVersion(entry = Bun.main) {
|
|
|
1398
2327
|
try {
|
|
1399
2328
|
resolved = realpathSync2(entry);
|
|
1400
2329
|
} catch {}
|
|
1401
|
-
for (let dir =
|
|
2330
|
+
for (let dir = dirname4(resolved);; dir = dirname4(dir)) {
|
|
1402
2331
|
try {
|
|
1403
|
-
const { version } = JSON.parse(
|
|
2332
|
+
const { version } = JSON.parse(readFileSync6(join8(dir, "package.json"), "utf8"));
|
|
1404
2333
|
if (typeof version === "string")
|
|
1405
2334
|
return version;
|
|
1406
2335
|
} catch {}
|
|
1407
|
-
if (
|
|
2336
|
+
if (dirname4(dir) === dir)
|
|
1408
2337
|
return "0.0.0";
|
|
1409
2338
|
}
|
|
1410
2339
|
}
|
|
1411
2340
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
2341
|
+
const answered = await askpassClient(argv);
|
|
2342
|
+
if (answered !== undefined)
|
|
2343
|
+
return answered;
|
|
1412
2344
|
if (argv[0] === COMPLETE)
|
|
1413
2345
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1414
2346
|
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
@@ -1427,21 +2359,52 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
1427
2359
|
notifyEnd(name, code, performance.now() - started);
|
|
1428
2360
|
if (usage !== false) {
|
|
1429
2361
|
try {
|
|
1430
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
2362
|
+
recordUsage(usageEntry(name, undefined, argv, code, { ms: performance.now() - started }));
|
|
1431
2363
|
} catch {}
|
|
1432
2364
|
}
|
|
1433
2365
|
return code;
|
|
1434
2366
|
}
|
|
1435
|
-
|
|
1436
|
-
|
|
2367
|
+
|
|
2368
|
+
// ../kit/src/index.ts
|
|
2369
|
+
init_config();
|
|
2370
|
+
|
|
2371
|
+
// ../kit/src/excerpt.ts
|
|
2372
|
+
init_text2();
|
|
2373
|
+
|
|
2374
|
+
// ../kit/src/index.ts
|
|
2375
|
+
init_folders();
|
|
2376
|
+
init_format();
|
|
2377
|
+
|
|
2378
|
+
// ../kit/src/git.ts
|
|
2379
|
+
init_args();
|
|
2380
|
+
// ../kit/src/limit.ts
|
|
2381
|
+
init_args();
|
|
2382
|
+
|
|
2383
|
+
// ../kit/src/index.ts
|
|
2384
|
+
init_mode();
|
|
2385
|
+
|
|
2386
|
+
// ../kit/src/report.ts
|
|
2387
|
+
init_style();
|
|
2388
|
+
init_text2();
|
|
1437
2389
|
// ../kit/src/secrets.ts
|
|
1438
2390
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
2391
|
+
var NOT_PASSWORDS = new Set(["compass", "encompass", "bypass", "overpass", "underpass", "surpass", "trespass"]);
|
|
1439
2392
|
// ../kit/src/sessions.ts
|
|
1440
2393
|
var {Glob } = globalThis.Bun;
|
|
1441
2394
|
var SESSION_FILES = new Glob("*.json");
|
|
1442
2395
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
2396
|
+
|
|
2397
|
+
// ../kit/src/index.ts
|
|
2398
|
+
init_style();
|
|
2399
|
+
init_text2();
|
|
2400
|
+
init_theme();
|
|
2401
|
+
init_user_config();
|
|
2402
|
+
|
|
1443
2403
|
// ../kit/src/watch.ts
|
|
1444
|
-
|
|
2404
|
+
init_args();
|
|
2405
|
+
init_input();
|
|
2406
|
+
init_style();
|
|
2407
|
+
import process20 from "process";
|
|
1445
2408
|
import { format } from "util";
|
|
1446
2409
|
var CLEAR_SCREEN = "\x1B[H\x1B[2J";
|
|
1447
2410
|
var DEFAULT_SECONDS = 2;
|
|
@@ -1463,7 +2426,7 @@ function withoutWatch(args) {
|
|
|
1463
2426
|
}
|
|
1464
2427
|
return rest;
|
|
1465
2428
|
}
|
|
1466
|
-
async function watching(value, step, stream =
|
|
2429
|
+
async function watching(value, step, stream = process20.stdout, sleep = Bun.sleep, rounds = Number.POSITIVE_INFINITY) {
|
|
1467
2430
|
const interval = value === "" ? DEFAULT_SECONDS * 1000 : duration(value, "watch", DEFAULT_SECONDS * 1000);
|
|
1468
2431
|
if (!takesControlCodes(stream))
|
|
1469
2432
|
badUsage("--watch redraws the screen, so it needs a terminal");
|
|
@@ -1471,12 +2434,12 @@ async function watching(value, step, stream = process16.stdout, sleep = Bun.slee
|
|
|
1471
2434
|
for (let round = 0;round < rounds; round++) {
|
|
1472
2435
|
const held = [];
|
|
1473
2436
|
const { log, info } = console;
|
|
1474
|
-
const write =
|
|
2437
|
+
const write = process20.stdout.write.bind(process20.stdout);
|
|
1475
2438
|
const hold = (...parts) => void held.push(`${format(...parts)}
|
|
1476
2439
|
`);
|
|
1477
2440
|
console.log = hold;
|
|
1478
2441
|
console.info = hold;
|
|
1479
|
-
|
|
2442
|
+
process20.stdout.write = (text) => {
|
|
1480
2443
|
held.push(typeof text === "string" ? text : Buffer.from(text).toString());
|
|
1481
2444
|
return true;
|
|
1482
2445
|
};
|
|
@@ -1485,7 +2448,7 @@ async function watching(value, step, stream = process16.stdout, sleep = Bun.slee
|
|
|
1485
2448
|
} finally {
|
|
1486
2449
|
console.log = log;
|
|
1487
2450
|
console.info = info;
|
|
1488
|
-
|
|
2451
|
+
process20.stdout.write = write;
|
|
1489
2452
|
}
|
|
1490
2453
|
stream.write(`${CLEAR_SCREEN}${held.join("")}`);
|
|
1491
2454
|
await sleep(interval);
|
|
@@ -1493,21 +2456,22 @@ async function watching(value, step, stream = process16.stdout, sleep = Bun.slee
|
|
|
1493
2456
|
return code;
|
|
1494
2457
|
}
|
|
1495
2458
|
// ../kit/src/workspace-root.ts
|
|
1496
|
-
|
|
1497
|
-
import {
|
|
1498
|
-
import
|
|
2459
|
+
init_user_config();
|
|
2460
|
+
import { homedir as homedir5 } from "os";
|
|
2461
|
+
import { dirname as dirname5, join as join9, resolve as resolve4 } from "path";
|
|
2462
|
+
import process21 from "process";
|
|
1499
2463
|
function expandHome(path, home) {
|
|
1500
2464
|
if (path === "~")
|
|
1501
2465
|
return home;
|
|
1502
|
-
return path.startsWith("~/") ?
|
|
2466
|
+
return path.startsWith("~/") ? join9(home, path.slice(2)) : path;
|
|
1503
2467
|
}
|
|
1504
2468
|
function configured(env, home) {
|
|
1505
2469
|
const folder = readUserConfig("config", { home, xdg: env.XDG_CONFIG_HOME }).workspace;
|
|
1506
2470
|
return typeof folder === "string" && folder !== "" ? folder : undefined;
|
|
1507
2471
|
}
|
|
1508
|
-
function workspaceRoot({ given, env =
|
|
2472
|
+
function workspaceRoot({ given, env = process21.env, home = homedir5() } = {}) {
|
|
1509
2473
|
const fromEnv = env.KAYNOOO_WORKSPACE === "" ? undefined : env.KAYNOOO_WORKSPACE;
|
|
1510
|
-
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ??
|
|
2474
|
+
return resolve4(expandHome(given ?? fromEnv ?? configured(env, home) ?? join9(home, "Workspace"), home));
|
|
1511
2475
|
}
|
|
1512
2476
|
// src/git.ts
|
|
1513
2477
|
async function git2(args, env) {
|
|
@@ -1518,8 +2482,8 @@ async function git2(args, env) {
|
|
|
1518
2482
|
|
|
1519
2483
|
// src/repos.ts
|
|
1520
2484
|
import { readdir } from "fs/promises";
|
|
1521
|
-
import { join as
|
|
1522
|
-
import
|
|
2485
|
+
import { join as join10, relative, resolve as resolve5 } from "path";
|
|
2486
|
+
import process23 from "process";
|
|
1523
2487
|
|
|
1524
2488
|
// src/status.ts
|
|
1525
2489
|
var AHEAD_BEHIND = /\+(\d+) -(\d+)/;
|
|
@@ -1615,7 +2579,7 @@ async function reposUnder(root, depth = DEPTH) {
|
|
|
1615
2579
|
found.push(dir);
|
|
1616
2580
|
if (left === 0)
|
|
1617
2581
|
return;
|
|
1618
|
-
await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(
|
|
2582
|
+
await Promise.all(entries.filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && !SKIPPED.has(entry.name)).map(async (entry) => walk(join10(dir, entry.name), left - 1)));
|
|
1619
2583
|
}
|
|
1620
2584
|
await walk(resolve5(root), depth);
|
|
1621
2585
|
return found.sort();
|
|
@@ -1625,14 +2589,14 @@ async function toplevelOf(dir) {
|
|
|
1625
2589
|
return read.code === 0 ? read.stdout.trim() : undefined;
|
|
1626
2590
|
}
|
|
1627
2591
|
async function reposOf(roots) {
|
|
1628
|
-
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ??
|
|
2592
|
+
const starts = roots.length > 0 ? roots : [await toplevelOf(".") ?? process23.cwd()];
|
|
1629
2593
|
const found = await Promise.all(starts.map(async (root) => reposUnder(root)));
|
|
1630
2594
|
return [...new Set(found.flat())].sort();
|
|
1631
2595
|
}
|
|
1632
2596
|
async function repoState(dir) {
|
|
1633
2597
|
const [read, log] = await Promise.all([git2(["-C", dir, "status", "--porcelain=v2", "--branch"]), git2(["-C", dir, "log", "-1", "--format=%h%x00%s"])]);
|
|
1634
2598
|
const [sha, title = ""] = log.code === 0 && log.stdout.trim() !== "" ? log.stdout.trim().split("\x00") : [];
|
|
1635
|
-
return { path: relative(
|
|
2599
|
+
return { path: relative(process23.cwd(), dir) || ".", dir, status: read.code === 0 ? parseStatus(read.stdout) : null, head: sha === undefined ? null : { sha, title } };
|
|
1636
2600
|
}
|
|
1637
2601
|
function trackingOf(status) {
|
|
1638
2602
|
if (status.upstream === null)
|
|
@@ -1669,15 +2633,35 @@ async function dirsOf(positionals, all) {
|
|
|
1669
2633
|
|
|
1670
2634
|
// src/sync.ts
|
|
1671
2635
|
var GIT_FAILURE = /^(?:error: |fatal: )/;
|
|
2636
|
+
var LISTED = /^\s/;
|
|
2637
|
+
var LOCAL_CHANGES = /local changes .* would be overwritten/;
|
|
2638
|
+
var UNTRACKED = /untracked working tree files would be overwritten/;
|
|
1672
2639
|
function whyFailed(stderr, fallback) {
|
|
1673
2640
|
const lines = stderr.split(`
|
|
1674
2641
|
`).map((line) => line.trimEnd()).filter(Boolean);
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
2642
|
+
const at = lines.findIndex((line) => GIT_FAILURE.test(line));
|
|
2643
|
+
if (at === -1)
|
|
2644
|
+
return (lines.at(-1) ?? fallback).trim();
|
|
2645
|
+
const line = lines[at].trim();
|
|
2646
|
+
const listed = [];
|
|
2647
|
+
for (const next of lines.slice(at + 1)) {
|
|
2648
|
+
if (!LISTED.test(next))
|
|
2649
|
+
break;
|
|
2650
|
+
listed.push(next.trim());
|
|
2651
|
+
}
|
|
2652
|
+
if (listed.length === 0)
|
|
2653
|
+
return line;
|
|
2654
|
+
const paths = listed.join(", ");
|
|
2655
|
+
if (LOCAL_CHANGES.test(line))
|
|
2656
|
+
return `uncommitted changes in files the fast-forward changes (${paths}): commit them first (gc), or set them aside as a patch (gu)`;
|
|
2657
|
+
if (UNTRACKED.test(line))
|
|
2658
|
+
return `untracked files the fast-forward would overwrite (${paths}): move them aside first`;
|
|
2659
|
+
return `${line} ${paths}`;
|
|
2660
|
+
}
|
|
2661
|
+
async function sync(repo, { pull, env }) {
|
|
1678
2662
|
const { path, dir } = repo;
|
|
1679
2663
|
const refused = (reason, branch = null, upstream = null) => ({ path, branch, upstream, commits: null, outcome: "refused", reason });
|
|
1680
|
-
const fetched = await git2(["-C", dir, "fetch", "--prune"]);
|
|
2664
|
+
const fetched = await git2(["-C", dir, "fetch", "--prune"], env);
|
|
1681
2665
|
if (fetched.code !== 0)
|
|
1682
2666
|
return refused(whyFailed(fetched.stderr, "git fetch failed"), repo.status?.branch ?? null);
|
|
1683
2667
|
const { status } = await repoState(dir);
|
|
@@ -1706,8 +2690,8 @@ async function sync(repo, { pull }) {
|
|
|
1706
2690
|
var DEFAULT_FORGE = "git.kaynooo.fr";
|
|
1707
2691
|
var USAGE = `gcl <repo> [dir]: clones a repository into the workspace folder and prints where it landed
|
|
1708
2692
|
|
|
1709
|
-
<repo> is a URL, an scp-style address
|
|
1710
|
-
|
|
2693
|
+
<repo> is a URL, an scp-style address, a local path or \`owner/name\`, read as \`https://${DEFAULT_FORGE}/owner/name.git\` (the \`forge\` config key names another host). Without <dir> the clone goes to <workspace>/<name>, the workspace \`cli config\` reports.
|
|
2694
|
+
A folder that already holds the repository is fetched and fast-forwarded as gf does, not cloned again; one holding anything else is refused.`;
|
|
1711
2695
|
var EXITS = [[0, "it cloned the repository, or found it and brought it up to date"], [1, "git could not clone it, or the folder is taken"], [2, "a usage error"]];
|
|
1712
2696
|
var OPTIONS = {
|
|
1713
2697
|
json: jsonOption("{url, path, branch, head, outcome}, outcome being cloned or existing")
|
|
@@ -1720,7 +2704,7 @@ var TRAILING_SLASH = /\/+$/;
|
|
|
1720
2704
|
var LAST_SEGMENT = /[/:]/;
|
|
1721
2705
|
function urlOf(repo, forge) {
|
|
1722
2706
|
if (repo.startsWith("~/"))
|
|
1723
|
-
return
|
|
2707
|
+
return join11(homedir6(), repo.slice(2));
|
|
1724
2708
|
if (SCHEME.test(repo) || SCP.test(repo) || repo.startsWith("/") || repo.startsWith("."))
|
|
1725
2709
|
return repo;
|
|
1726
2710
|
if (OWNER_NAME.test(repo))
|
|
@@ -1743,7 +2727,7 @@ async function main(argv) {
|
|
|
1743
2727
|
const name = nameOf(url);
|
|
1744
2728
|
if (name === "")
|
|
1745
2729
|
fail(`no folder name can be taken from ${url}, give one: gcl ${repo} <dir>`, 2);
|
|
1746
|
-
const path = given === undefined ?
|
|
2730
|
+
const path = given === undefined ? join11(workspaceRoot(), name) : resolve6(given);
|
|
1747
2731
|
let outcome = "cloned";
|
|
1748
2732
|
if (existsSync4(path) && (!statSync2(path).isDirectory() || readdirSync(path).length > 0)) {
|
|
1749
2733
|
if (!statSync2(path).isDirectory() || await toplevelOf(path) !== realpathSync3(path))
|
|
@@ -1772,7 +2756,7 @@ ${cloned.stderr.trim()}`, 1);
|
|
|
1772
2756
|
return 0;
|
|
1773
2757
|
}
|
|
1774
2758
|
if (import.meta.main)
|
|
1775
|
-
|
|
2759
|
+
process24.exitCode = await runMain({ name: "gcl", run: main });
|
|
1776
2760
|
export {
|
|
1777
2761
|
nameOf,
|
|
1778
2762
|
urlOf
|