@kaynooo/cli-dl 0.0.0-stage → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +39 -2
- package/dist/cli.js +2220 -0
- package/package.json +39 -4
package/dist/cli.js
ADDED
|
@@ -0,0 +1,2220 @@
|
|
|
1
|
+
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
|
+
// @bun
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __returnValue = (v) => v;
|
|
5
|
+
function __exportSetter(name, newValue) {
|
|
6
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
7
|
+
}
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
set: __exportSetter.bind(all, name)
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
var __esm = (fn, res, err) => () => {
|
|
18
|
+
if (fn)
|
|
19
|
+
try {
|
|
20
|
+
res = fn(fn = 0);
|
|
21
|
+
} catch (e) {
|
|
22
|
+
err = [e];
|
|
23
|
+
}
|
|
24
|
+
if (err)
|
|
25
|
+
throw err[0];
|
|
26
|
+
return res;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// ../kit/src/advisory.ts
|
|
30
|
+
var init_advisory = () => {};
|
|
31
|
+
|
|
32
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
33
|
+
function ko(t, e, r = "...") {
|
|
34
|
+
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
35
|
+
if (t.length <= e)
|
|
36
|
+
return t;
|
|
37
|
+
let l = Math.max(0, e), c = t.substring(0, Math.max(0, s ? l - n.length : l));
|
|
38
|
+
if (o && !Y.test(t[c.length] ?? " "))
|
|
39
|
+
c = c.replace(Nt, "") || c;
|
|
40
|
+
if (o)
|
|
41
|
+
c = c.trimEnd();
|
|
42
|
+
return s ? (c + n).slice(0, l) : c + n;
|
|
43
|
+
}
|
|
44
|
+
var N, Nt, Y, be, z;
|
|
45
|
+
var init_chunk_rxztfxgv = __esm(() => {
|
|
46
|
+
N = new Map;
|
|
47
|
+
Nt = /\s+\S*$/;
|
|
48
|
+
Y = /\s/;
|
|
49
|
+
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));
|
|
50
|
+
z = new Map;
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
|
|
54
|
+
var init_text = __esm(() => {
|
|
55
|
+
init_chunk_rxztfxgv();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// ../kit/src/mode.ts
|
|
59
|
+
import process2 from "process";
|
|
60
|
+
function isSet(value) {
|
|
61
|
+
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
62
|
+
}
|
|
63
|
+
function outputMode(stream = process2.stdout, env = process2.env) {
|
|
64
|
+
const chosen = env.KIT_MODE;
|
|
65
|
+
if (chosen !== undefined && MODES.has(chosen))
|
|
66
|
+
return chosen;
|
|
67
|
+
if (AGENT_VARIABLES.some((name) => isSet(env[name])))
|
|
68
|
+
return "agent";
|
|
69
|
+
if (stream.isTTY === true)
|
|
70
|
+
return "terminal";
|
|
71
|
+
return isSet(env.CI) ? "ci" : "pipe";
|
|
72
|
+
}
|
|
73
|
+
var MODES, AGENT_VARIABLES;
|
|
74
|
+
var init_mode = __esm(() => {
|
|
75
|
+
MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
76
|
+
AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
80
|
+
function b(r) {
|
|
81
|
+
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
82
|
+
if (!G2.test(e))
|
|
83
|
+
return [0, 0, 0];
|
|
84
|
+
if (e.length === 3 || e.length === 4)
|
|
85
|
+
return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
|
|
86
|
+
if (e.length !== 6 && e.length !== 8)
|
|
87
|
+
throw Error(`Invalid hex color length: ${e.length}`);
|
|
88
|
+
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
89
|
+
}
|
|
90
|
+
function C(r, e = globalThis.process?.env ?? {}) {
|
|
91
|
+
if (e.FORCE_COLOR !== undefined)
|
|
92
|
+
return h.has(e.FORCE_COLOR);
|
|
93
|
+
if (e.NO_COLOR !== undefined || e.NODE_DISABLE_COLORS !== undefined || e.TERM === "dumb")
|
|
94
|
+
return false;
|
|
95
|
+
return r?.isTTY === true;
|
|
96
|
+
}
|
|
97
|
+
function f(r, e = []) {
|
|
98
|
+
let l = "", n = "";
|
|
99
|
+
for (let t = 0, i = e.length;t < i; t++)
|
|
100
|
+
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
101
|
+
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
102
|
+
return new Proxy(c, { get(t, i) {
|
|
103
|
+
let a = B2[i];
|
|
104
|
+
if (Array.isArray(a)) {
|
|
105
|
+
let s = g.get(i);
|
|
106
|
+
if (s === undefined)
|
|
107
|
+
s = f(r, [...e, a]), g.set(i, s);
|
|
108
|
+
return s;
|
|
109
|
+
}
|
|
110
|
+
if (typeof a === "function")
|
|
111
|
+
return (...s) => {
|
|
112
|
+
let y = `${i}:${s.join(",")}`, u = g.get(y);
|
|
113
|
+
if (u === undefined) {
|
|
114
|
+
if (g.size >= 64)
|
|
115
|
+
g.clear();
|
|
116
|
+
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
117
|
+
}
|
|
118
|
+
return u;
|
|
119
|
+
};
|
|
120
|
+
throw Error(`Unknown style: ${String(i)}`);
|
|
121
|
+
} });
|
|
122
|
+
}
|
|
123
|
+
function Fe(r = {}) {
|
|
124
|
+
return f(r);
|
|
125
|
+
}
|
|
126
|
+
var G2, B2, h, o;
|
|
127
|
+
var init_chunk_x450vn3m = __esm(() => {
|
|
128
|
+
G2 = /^[a-f0-9]+$/i;
|
|
129
|
+
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") => {
|
|
130
|
+
let [l, n, c] = b(r);
|
|
131
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
132
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
133
|
+
h = new Set(["", "1", "2", "3", "true"]);
|
|
134
|
+
o = Fe();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
|
|
138
|
+
var init_colors = __esm(() => {
|
|
139
|
+
init_chunk_x450vn3m();
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// ../kit/src/config.ts
|
|
143
|
+
import { existsSync } from "fs";
|
|
144
|
+
import { dirname, join, resolve } from "path";
|
|
145
|
+
import process3 from "process";
|
|
146
|
+
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
147
|
+
const wanted = typeof names === "string" ? [names] : names;
|
|
148
|
+
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
149
|
+
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
150
|
+
if (found !== undefined)
|
|
151
|
+
return found;
|
|
152
|
+
if (stop(dir) || dirname(dir) === dir)
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
var init_config = __esm(() => {
|
|
157
|
+
init_args();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// ../kit/src/user-config.ts
|
|
161
|
+
import { homedir } from "os";
|
|
162
|
+
import { join as join2 } from "path";
|
|
163
|
+
import process4 from "process";
|
|
164
|
+
function configBase(where = {}) {
|
|
165
|
+
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
166
|
+
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
167
|
+
}
|
|
168
|
+
function userConfigPath(bin, where = {}) {
|
|
169
|
+
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
170
|
+
}
|
|
171
|
+
var init_user_config = () => {};
|
|
172
|
+
|
|
173
|
+
// ../kit/src/theme.ts
|
|
174
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
175
|
+
import { homedir as homedir2 } from "os";
|
|
176
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
177
|
+
import process5 from "process";
|
|
178
|
+
function toLinear(channel) {
|
|
179
|
+
const value = channel / 255;
|
|
180
|
+
return value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
181
|
+
}
|
|
182
|
+
function toOklab(hex) {
|
|
183
|
+
const [r, g, b] = [1, 3, 5].map((at) => toLinear(Number.parseInt(hex.slice(at, at + 2), 16)));
|
|
184
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
185
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
186
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
187
|
+
return [0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s, 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s, 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s];
|
|
188
|
+
}
|
|
189
|
+
function fromOklab([lightness, a, b]) {
|
|
190
|
+
const l = (lightness + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
191
|
+
const m = (lightness - 0.1055613458 * a - 0.0638541728 * b) ** 3;
|
|
192
|
+
const s = (lightness - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
193
|
+
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];
|
|
194
|
+
return `#${channels.map((channel) => fromLinear(channel).toString(16).padStart(2, "0")).join("")}`;
|
|
195
|
+
}
|
|
196
|
+
function gradientAt(theme, ratio) {
|
|
197
|
+
if (theme.gradient === undefined)
|
|
198
|
+
return;
|
|
199
|
+
const key = theme.gradient.join();
|
|
200
|
+
let ends = ENDS.get(key);
|
|
201
|
+
if (ends === undefined) {
|
|
202
|
+
ends = [toOklab(theme.gradient[0]), toOklab(theme.gradient[1])];
|
|
203
|
+
ENDS.set(key, ends);
|
|
204
|
+
}
|
|
205
|
+
const at = Math.min(1, Math.max(0, ratio));
|
|
206
|
+
const [from, to] = ends;
|
|
207
|
+
return fromOklab(from.map((start, index) => start + (to[index] - start) * at));
|
|
208
|
+
}
|
|
209
|
+
function isColorSpec(spec) {
|
|
210
|
+
if (typeof spec === "number")
|
|
211
|
+
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
212
|
+
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
213
|
+
}
|
|
214
|
+
function cubeLevel(channel) {
|
|
215
|
+
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
216
|
+
}
|
|
217
|
+
function nearest256(hex) {
|
|
218
|
+
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
219
|
+
const levels = rgb.map(cubeLevel);
|
|
220
|
+
const cube = levels.map((level) => CUBE[level]);
|
|
221
|
+
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
222
|
+
const greyValue = 8 + grey * 10;
|
|
223
|
+
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
224
|
+
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
225
|
+
}
|
|
226
|
+
function hasTrueColor(env) {
|
|
227
|
+
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
228
|
+
}
|
|
229
|
+
function tinted(colors, spec, env = process5.env) {
|
|
230
|
+
if (typeof spec === "number")
|
|
231
|
+
return colors.ansi256(spec);
|
|
232
|
+
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
233
|
+
if (HEX.test(token))
|
|
234
|
+
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
235
|
+
return chain[token] ?? chain;
|
|
236
|
+
}, colors);
|
|
237
|
+
}
|
|
238
|
+
function shaded(theme, colors, glyph, cells, width, env = process5.env) {
|
|
239
|
+
return Array.from({ length: cells }, (_, index) => tinted(colors, gradientAt(theme, width <= 1 ? 0 : index / (width - 1)) ?? theme.colors.accent, env)(glyph)).join("");
|
|
240
|
+
}
|
|
241
|
+
function isRecord(value) {
|
|
242
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
243
|
+
}
|
|
244
|
+
function readThemeFile(path, warn) {
|
|
245
|
+
try {
|
|
246
|
+
const stat = statSync(path, { throwIfNoEntry: false });
|
|
247
|
+
if (stat === undefined)
|
|
248
|
+
return;
|
|
249
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
250
|
+
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
254
|
+
if (isRecord(parsed))
|
|
255
|
+
return parsed;
|
|
256
|
+
warn(`${path} is not a JSON object, theme ignored`);
|
|
257
|
+
} catch (error) {
|
|
258
|
+
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
259
|
+
}
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
function applyPreset(theme, name, warn, where) {
|
|
263
|
+
if (name === undefined)
|
|
264
|
+
return;
|
|
265
|
+
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
266
|
+
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const preset = PRESETS[name];
|
|
270
|
+
Object.assign(theme.colors, preset.colors);
|
|
271
|
+
Object.assign(theme.glyphs, preset.glyphs);
|
|
272
|
+
if (preset.accents !== undefined)
|
|
273
|
+
theme.accents = [...preset.accents];
|
|
274
|
+
if (Object.hasOwn(preset, "gradient"))
|
|
275
|
+
theme.gradient = preset.gradient;
|
|
276
|
+
return name;
|
|
277
|
+
}
|
|
278
|
+
function applyFile(theme, file, where, warn) {
|
|
279
|
+
if (isRecord(file.colors)) {
|
|
280
|
+
for (const [key, value] of Object.entries(file.colors)) {
|
|
281
|
+
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
282
|
+
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
283
|
+
else if (!isColorSpec(value))
|
|
284
|
+
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
285
|
+
else
|
|
286
|
+
theme.colors[key] = value;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (isRecord(file.glyphs)) {
|
|
290
|
+
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
291
|
+
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
292
|
+
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
293
|
+
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
294
|
+
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
295
|
+
else
|
|
296
|
+
theme.glyphs[key] = value;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
300
|
+
theme.accents = [...file.accents];
|
|
301
|
+
else if (file.accents !== undefined)
|
|
302
|
+
warn(`${where}: accents must be a non-empty list of colours`);
|
|
303
|
+
if (file.gradient === null)
|
|
304
|
+
theme.gradient = undefined;
|
|
305
|
+
else if (Array.isArray(file.gradient) && file.gradient.length === 2 && file.gradient.every((end) => typeof end === "string" && HEX.test(end)))
|
|
306
|
+
theme.gradient = [file.gradient[0], file.gradient[1]];
|
|
307
|
+
else if (file.gradient !== undefined)
|
|
308
|
+
warn(`${where}: gradient must be two \`#rrggbb\` colours, or null for none`);
|
|
309
|
+
if (isRecord(file.bins)) {
|
|
310
|
+
for (const [bin, value] of Object.entries(file.bins)) {
|
|
311
|
+
if (isColorSpec(value))
|
|
312
|
+
theme.bins[bin] = value;
|
|
313
|
+
else
|
|
314
|
+
warn(`${where}: bin ${bin} has no valid colour`);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
function endsWalk(home) {
|
|
319
|
+
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
320
|
+
}
|
|
321
|
+
function warnOnce(message) {
|
|
322
|
+
if (warned.has(message))
|
|
323
|
+
return;
|
|
324
|
+
warned.add(message);
|
|
325
|
+
console.error(`warning: theme ${message}`);
|
|
326
|
+
}
|
|
327
|
+
function isPath(chosen) {
|
|
328
|
+
return chosen.includes("/") || chosen.endsWith(".json");
|
|
329
|
+
}
|
|
330
|
+
function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
331
|
+
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null), gradient: DEFAULT.gradient };
|
|
332
|
+
const sources = [];
|
|
333
|
+
const chosen = env.KIT_THEME ?? "";
|
|
334
|
+
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
335
|
+
if (isPath(chosen))
|
|
336
|
+
wanted.push(resolve2(from, chosen));
|
|
337
|
+
const files = [];
|
|
338
|
+
for (const path of wanted) {
|
|
339
|
+
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
340
|
+
if (path !== undefined && file !== undefined)
|
|
341
|
+
files.push({ path, file });
|
|
342
|
+
}
|
|
343
|
+
let preset = "default";
|
|
344
|
+
if (chosen !== "" && !isPath(chosen)) {
|
|
345
|
+
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
346
|
+
} else {
|
|
347
|
+
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
348
|
+
if (named !== undefined)
|
|
349
|
+
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
350
|
+
}
|
|
351
|
+
for (const { path, file } of files) {
|
|
352
|
+
applyFile(theme, file, path, warn);
|
|
353
|
+
sources.push(path);
|
|
354
|
+
}
|
|
355
|
+
return { theme, sources, preset };
|
|
356
|
+
}
|
|
357
|
+
function activeTheme() {
|
|
358
|
+
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
359
|
+
if (current === undefined || key !== currentKey) {
|
|
360
|
+
current = loadTheme();
|
|
361
|
+
currentKey = key;
|
|
362
|
+
}
|
|
363
|
+
return current;
|
|
364
|
+
}
|
|
365
|
+
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 = "";
|
|
366
|
+
var init_theme = __esm(() => {
|
|
367
|
+
init_config();
|
|
368
|
+
init_user_config();
|
|
369
|
+
ENDS = new Map;
|
|
370
|
+
DEFAULT = {
|
|
371
|
+
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" },
|
|
372
|
+
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" },
|
|
373
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
374
|
+
bins: {},
|
|
375
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
376
|
+
};
|
|
377
|
+
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" };
|
|
378
|
+
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" };
|
|
379
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
380
|
+
PRESETS = {
|
|
381
|
+
default: {},
|
|
382
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
383
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
384
|
+
ascii: { glyphs: ASCII }
|
|
385
|
+
};
|
|
386
|
+
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"]);
|
|
387
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
388
|
+
CONTROL = /\p{Cc}/u;
|
|
389
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
390
|
+
SPACES = /\s+/;
|
|
391
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
392
|
+
warned = new Set;
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
// ../kit/src/style.ts
|
|
396
|
+
import process6 from "process";
|
|
397
|
+
function takesControlCodes(stream, env = process6.env) {
|
|
398
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
399
|
+
}
|
|
400
|
+
function paint(stream, env = process6.env) {
|
|
401
|
+
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
402
|
+
}
|
|
403
|
+
function marked(mark, text, stream, detail, env = process6.env) {
|
|
404
|
+
const colors = paint(stream, env);
|
|
405
|
+
let head = MARK_WORDS[mark];
|
|
406
|
+
if (takesControlCodes(stream, env)) {
|
|
407
|
+
const { theme } = activeTheme();
|
|
408
|
+
head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
|
|
409
|
+
}
|
|
410
|
+
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
411
|
+
}
|
|
412
|
+
var MARK_WORDS, STATUS_WORDS, STATUS_OF;
|
|
413
|
+
var init_style = __esm(() => {
|
|
414
|
+
init_colors();
|
|
415
|
+
init_mode();
|
|
416
|
+
init_theme();
|
|
417
|
+
MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
418
|
+
STATUS_WORDS = {
|
|
419
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
420
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
421
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
422
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
423
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
424
|
+
};
|
|
425
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
// ../kit/src/format.ts
|
|
429
|
+
import process7 from "process";
|
|
430
|
+
function formatSeconds(total) {
|
|
431
|
+
let rest = Math.max(0, Math.round(total));
|
|
432
|
+
const amounts = UNITS.map(([unit, size]) => {
|
|
433
|
+
const amount = Math.floor(rest / size);
|
|
434
|
+
rest -= amount * size;
|
|
435
|
+
return `${amount}${unit}`;
|
|
436
|
+
});
|
|
437
|
+
const first = amounts.findIndex((amount) => !amount.startsWith("0"));
|
|
438
|
+
if (first === -1)
|
|
439
|
+
return "0s";
|
|
440
|
+
const next = amounts[first + 1];
|
|
441
|
+
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
442
|
+
}
|
|
443
|
+
function formatDuration(ms) {
|
|
444
|
+
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
445
|
+
}
|
|
446
|
+
function formatElapsed(ms) {
|
|
447
|
+
return formatSeconds(Math.floor(Math.max(0, ms) / 1000));
|
|
448
|
+
}
|
|
449
|
+
function upTo(text, separator) {
|
|
450
|
+
const end = text.indexOf(separator);
|
|
451
|
+
return end === -1 ? text : text.slice(0, end);
|
|
452
|
+
}
|
|
453
|
+
function formatAge(date, now = Date.now()) {
|
|
454
|
+
const at = typeof date === "number" ? date : Date.parse(date);
|
|
455
|
+
if (Number.isNaN(at))
|
|
456
|
+
return "-";
|
|
457
|
+
const seconds = (now - at) / 1000;
|
|
458
|
+
return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
|
|
459
|
+
}
|
|
460
|
+
function truncate(text, width) {
|
|
461
|
+
return ko(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
462
|
+
}
|
|
463
|
+
function textWidth(text) {
|
|
464
|
+
return Bun.stringWidth(text);
|
|
465
|
+
}
|
|
466
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
|
|
467
|
+
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
468
|
+
if (outputMode(stream, env) === "agent")
|
|
469
|
+
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
470
|
+
`);
|
|
471
|
+
const widths = [];
|
|
472
|
+
for (const row of cells) {
|
|
473
|
+
for (const [index, cell] of row.entries())
|
|
474
|
+
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
475
|
+
}
|
|
476
|
+
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
477
|
+
const colors = paint(stream);
|
|
478
|
+
const lines = shown.map((row) => row.map((cell, index) => {
|
|
479
|
+
const width = widths[index] ?? 0;
|
|
480
|
+
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
481
|
+
if (align[index] === "right")
|
|
482
|
+
return `${gap}${cell}`;
|
|
483
|
+
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
484
|
+
}).join(" ").trimEnd());
|
|
485
|
+
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
486
|
+
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
487
|
+
`);
|
|
488
|
+
}
|
|
489
|
+
function narrow(rows, widths, limit) {
|
|
490
|
+
const used = () => widths.reduce((sum, width) => sum + width, 0) + 2 * Math.max(0, widths.length - 1);
|
|
491
|
+
const cuttable = (index) => rows.every((row) => !(row[index] ?? "").includes(ESCAPE));
|
|
492
|
+
const floor = 8;
|
|
493
|
+
while (used() > limit) {
|
|
494
|
+
let widest = -1;
|
|
495
|
+
for (const [index, width] of widths.entries()) {
|
|
496
|
+
if (cuttable(index) && width > floor && width > (widths[widest] ?? 0))
|
|
497
|
+
widest = index;
|
|
498
|
+
}
|
|
499
|
+
if (widest === -1)
|
|
500
|
+
break;
|
|
501
|
+
widths[widest] = Math.max(floor, (widths[widest] ?? 0) - (used() - limit));
|
|
502
|
+
}
|
|
503
|
+
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
504
|
+
}
|
|
505
|
+
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
506
|
+
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
507
|
+
}
|
|
508
|
+
function printJson(value) {
|
|
509
|
+
console.log(jsonText(value));
|
|
510
|
+
}
|
|
511
|
+
var UNITS, LINE_BREAKS, ESCAPE;
|
|
512
|
+
var init_format = __esm(() => {
|
|
513
|
+
init_text();
|
|
514
|
+
init_mode();
|
|
515
|
+
init_style();
|
|
516
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
517
|
+
LINE_BREAKS = /\s*\n\s*/g;
|
|
518
|
+
ESCAPE = String.fromCharCode(27);
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
// ../kit/src/help.ts
|
|
522
|
+
import process8 from "process";
|
|
523
|
+
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
524
|
+
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
525
|
+
}
|
|
526
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
527
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
528
|
+
`);
|
|
529
|
+
}
|
|
530
|
+
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
531
|
+
if (exits.length === 0)
|
|
532
|
+
return [];
|
|
533
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
534
|
+
}
|
|
535
|
+
function wantsHelpJson(env = process8.env) {
|
|
536
|
+
return env.KIT_HELP === "json";
|
|
537
|
+
}
|
|
538
|
+
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
539
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
540
|
+
`);
|
|
541
|
+
const first = lines[0];
|
|
542
|
+
const colon = first.indexOf(": ");
|
|
543
|
+
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
544
|
+
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
545
|
+
return {
|
|
546
|
+
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
547
|
+
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
548
|
+
...replaces === undefined ? {} : { replaces },
|
|
549
|
+
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] }),
|
|
550
|
+
...exits === undefined ? {} : { exits: exits.map(([code, meaning]) => ({ code, meaning })) },
|
|
551
|
+
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
555
|
+
if (examples.length === 0 || outputMode() === "agent")
|
|
556
|
+
return [];
|
|
557
|
+
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
558
|
+
}
|
|
559
|
+
function optionRows(options, colors = paint(process8.stdout)) {
|
|
560
|
+
const rows = Object.entries(options).map(([name, option]) => {
|
|
561
|
+
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
562
|
+
const choices = option.choices?.join("|");
|
|
563
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
564
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
565
|
+
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
566
|
+
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
567
|
+
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
568
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
569
|
+
});
|
|
570
|
+
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
571
|
+
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
572
|
+
}
|
|
573
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, MAX_INLINE_CHOICES = 24;
|
|
574
|
+
var init_help = __esm(() => {
|
|
575
|
+
init_mode();
|
|
576
|
+
init_style();
|
|
577
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
578
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
579
|
+
FULL_STOP = /\.$/;
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
// ../kit/src/text.ts
|
|
583
|
+
function distance(a, b) {
|
|
584
|
+
const left = [...a];
|
|
585
|
+
const right = [...b];
|
|
586
|
+
let before = [];
|
|
587
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
588
|
+
for (const [i, x] of left.entries()) {
|
|
589
|
+
const current = [i + 1];
|
|
590
|
+
for (const [j, y] of right.entries()) {
|
|
591
|
+
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
592
|
+
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
593
|
+
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
594
|
+
current.push(cost);
|
|
595
|
+
}
|
|
596
|
+
before = previous;
|
|
597
|
+
previous = current;
|
|
598
|
+
}
|
|
599
|
+
return previous[right.length] ?? 0;
|
|
600
|
+
}
|
|
601
|
+
function closest(name, names) {
|
|
602
|
+
const started = names.find((known) => known.startsWith(name));
|
|
603
|
+
if (started !== undefined)
|
|
604
|
+
return started;
|
|
605
|
+
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
606
|
+
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
607
|
+
}
|
|
608
|
+
var init_text2 = () => {};
|
|
609
|
+
|
|
610
|
+
// ../kit/src/input.ts
|
|
611
|
+
var init_input = __esm(() => {
|
|
612
|
+
init_args();
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
// ../kit/src/args.ts
|
|
616
|
+
import process9 from "process";
|
|
617
|
+
import { parseArgs } from "util";
|
|
618
|
+
function jsonOption(holds) {
|
|
619
|
+
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
620
|
+
}
|
|
621
|
+
function fail(message, code = 2, hint) {
|
|
622
|
+
throw new Exit(message, code, hint);
|
|
623
|
+
}
|
|
624
|
+
function badUsage(message) {
|
|
625
|
+
throw new UsageError(message);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
class Completing {
|
|
629
|
+
options;
|
|
630
|
+
positionals;
|
|
631
|
+
candidates;
|
|
632
|
+
constructor(options, positionals = [], candidates = {}) {
|
|
633
|
+
this.options = options;
|
|
634
|
+
this.positionals = positionals;
|
|
635
|
+
this.candidates = candidates;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
function applyOutput(color, plain, env = process9.env) {
|
|
639
|
+
const when = plain === true ? "never" : color ?? "auto";
|
|
640
|
+
if (when === "auto")
|
|
641
|
+
return;
|
|
642
|
+
if (when !== "always" && when !== "never")
|
|
643
|
+
badUsage(`--color takes auto, always or never, not ${when}`);
|
|
644
|
+
if (when === "always") {
|
|
645
|
+
env.FORCE_COLOR = "1";
|
|
646
|
+
delete env.NO_COLOR;
|
|
647
|
+
} else {
|
|
648
|
+
env.NO_COLOR = "1";
|
|
649
|
+
delete env.FORCE_COLOR;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
function parse(args, usage, options, settings = {}) {
|
|
653
|
+
const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
|
|
654
|
+
const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
|
|
655
|
+
const listing = listed(all, settings.allowNegative === true);
|
|
656
|
+
if (completion.active)
|
|
657
|
+
throw new Completing(listing, settings.positionals, settings.candidates);
|
|
658
|
+
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
659
|
+
let parsed;
|
|
660
|
+
try {
|
|
661
|
+
parsed = parseArgs({ args: joinDashValues(withBare(withAliases(own, all), all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
662
|
+
} catch (error) {
|
|
663
|
+
const message = parseError(error);
|
|
664
|
+
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
665
|
+
}
|
|
666
|
+
const values = parsed.values;
|
|
667
|
+
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
668
|
+
if (values.help === true) {
|
|
669
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings, listing)) : helpText(usage, listing, undefined, settings));
|
|
670
|
+
throw new HelpShown;
|
|
671
|
+
}
|
|
672
|
+
checkChoices(parsed.values, all);
|
|
673
|
+
checkConflicts(parsed.values, all);
|
|
674
|
+
if (settings.positionals !== undefined)
|
|
675
|
+
checkPositionals(parsed.positionals, settings.positionals);
|
|
676
|
+
return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
|
|
677
|
+
}
|
|
678
|
+
function splitRest(args, passes) {
|
|
679
|
+
const separator = passes ? args.indexOf("--") : -1;
|
|
680
|
+
return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
|
|
681
|
+
}
|
|
682
|
+
function splitTrailing(args, options, count) {
|
|
683
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
684
|
+
let seen = 0;
|
|
685
|
+
if (count === 0)
|
|
686
|
+
return { own: args, rest: undefined };
|
|
687
|
+
for (let at = 0;at < args.length; at++) {
|
|
688
|
+
const word = args[at];
|
|
689
|
+
if (word === "--")
|
|
690
|
+
break;
|
|
691
|
+
if (word.startsWith("-")) {
|
|
692
|
+
if (takesValue(word))
|
|
693
|
+
at++;
|
|
694
|
+
continue;
|
|
695
|
+
}
|
|
696
|
+
seen++;
|
|
697
|
+
if (seen === count)
|
|
698
|
+
return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
|
|
699
|
+
}
|
|
700
|
+
return { own: args, rest: undefined };
|
|
701
|
+
}
|
|
702
|
+
function listed(options, allowNegative) {
|
|
703
|
+
if (!allowNegative)
|
|
704
|
+
return options;
|
|
705
|
+
return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
|
|
706
|
+
if (option.type !== "boolean" || option.negative === undefined)
|
|
707
|
+
return [[name, option]];
|
|
708
|
+
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
709
|
+
}));
|
|
710
|
+
}
|
|
711
|
+
function withAliases(args, options) {
|
|
712
|
+
const named = new Map(Object.entries(options).flatMap(([name, { aliases = [] }]) => aliases.map((alias) => [`--${alias}`, `--${name}`])));
|
|
713
|
+
if (named.size === 0)
|
|
714
|
+
return args;
|
|
715
|
+
const separator = args.indexOf("--");
|
|
716
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
717
|
+
return [...own.map((arg) => {
|
|
718
|
+
const at = arg.indexOf("=");
|
|
719
|
+
const current = named.get(at === -1 ? arg : arg.slice(0, at));
|
|
720
|
+
return current === undefined ? arg : `${current}${at === -1 ? "" : arg.slice(at)}`;
|
|
721
|
+
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
722
|
+
}
|
|
723
|
+
function withBare(args, options) {
|
|
724
|
+
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
725
|
+
if (bare.size === 0)
|
|
726
|
+
return args;
|
|
727
|
+
const separator = args.indexOf("--");
|
|
728
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
729
|
+
return [...own.flatMap((arg, index) => {
|
|
730
|
+
const optional = bare.get(arg);
|
|
731
|
+
const next = own[index + 1];
|
|
732
|
+
const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
|
|
733
|
+
return optional === undefined || value ? [arg] : [arg, optional.bare];
|
|
734
|
+
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
735
|
+
}
|
|
736
|
+
function checkConflicts(values, options) {
|
|
737
|
+
const given = (name) => values[name] !== undefined && values[name] !== false;
|
|
738
|
+
for (const [name, { conflicts = [] }] of Object.entries(options)) {
|
|
739
|
+
const other = given(name) ? conflicts.find(given) : undefined;
|
|
740
|
+
if (other !== undefined)
|
|
741
|
+
badUsage(`--${name} cannot be used with --${other}`);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
function checkChoices(values, options) {
|
|
745
|
+
for (const [name, option] of Object.entries(options)) {
|
|
746
|
+
if (option.choices === undefined)
|
|
747
|
+
continue;
|
|
748
|
+
const given = values[name];
|
|
749
|
+
for (const value of Array.isArray(given) ? given : [given]) {
|
|
750
|
+
if (typeof value === "string")
|
|
751
|
+
oneOf(value, name, option.choices);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
function oneOf(value, name, choices) {
|
|
756
|
+
if (!choices.includes(value))
|
|
757
|
+
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
|
|
758
|
+
return value;
|
|
759
|
+
}
|
|
760
|
+
function checkPositionals(given, names) {
|
|
761
|
+
const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
|
|
762
|
+
const required = names.filter((name) => !name.startsWith("[")).length;
|
|
763
|
+
if (given.length < required)
|
|
764
|
+
badUsage(`missing ${names[given.length]}`);
|
|
765
|
+
if (!variadic && given.length > names.length)
|
|
766
|
+
badUsage(`unexpected argument ${given[names.length]}`);
|
|
767
|
+
}
|
|
768
|
+
function joinDashValues(args, options) {
|
|
769
|
+
const longOf = new Map(Object.entries(options).flatMap(([name, option]) => option.short === undefined ? [[`--${name}`, name]] : [[`--${name}`, name], [`-${option.short}`, name]]));
|
|
770
|
+
const isOption = (arg) => arg === "--" || longOf.has(arg.includes("=") ? arg.slice(0, arg.indexOf("=")) : arg);
|
|
771
|
+
const joined = [];
|
|
772
|
+
for (let i = 0;i < args.length; i++) {
|
|
773
|
+
const arg = args[i] ?? "";
|
|
774
|
+
if (arg === "--")
|
|
775
|
+
return [...joined, ...args.slice(i)];
|
|
776
|
+
const name = longOf.get(arg);
|
|
777
|
+
const next = args[i + 1];
|
|
778
|
+
if (name !== undefined && options[name]?.type === "string" && next !== undefined && next.startsWith("-") && next !== "-" && !isOption(next)) {
|
|
779
|
+
joined.push(`--${name}=${next}`);
|
|
780
|
+
i++;
|
|
781
|
+
} else {
|
|
782
|
+
joined.push(arg);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
return joined;
|
|
786
|
+
}
|
|
787
|
+
function parseError(error) {
|
|
788
|
+
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
789
|
+
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
790
|
+
}
|
|
791
|
+
function nearestOption(message, options, allowNegative) {
|
|
792
|
+
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
793
|
+
if (typed === undefined)
|
|
794
|
+
return;
|
|
795
|
+
const word = typed.replace(DASHES, "");
|
|
796
|
+
if (word.length < 2 && !typed.startsWith("--"))
|
|
797
|
+
return;
|
|
798
|
+
const known = Object.entries(options).flatMap(([name, option]) => [
|
|
799
|
+
...option.short === undefined ? [] : [`-${option.short}`],
|
|
800
|
+
`--${name}`,
|
|
801
|
+
...allowNegative && option.type === "boolean" ? [`--no-${name}`] : []
|
|
802
|
+
]);
|
|
803
|
+
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
804
|
+
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
805
|
+
}
|
|
806
|
+
var DASHES, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
807
|
+
var init_args = __esm(() => {
|
|
808
|
+
init_format();
|
|
809
|
+
init_help();
|
|
810
|
+
init_text2();
|
|
811
|
+
init_help();
|
|
812
|
+
init_input();
|
|
813
|
+
DASHES = /^-+/;
|
|
814
|
+
Exit = class Exit extends Error {
|
|
815
|
+
code;
|
|
816
|
+
hint;
|
|
817
|
+
constructor(message, code, hint) {
|
|
818
|
+
super(message);
|
|
819
|
+
this.code = code;
|
|
820
|
+
this.hint = hint;
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
UsageError = class UsageError extends Exit {
|
|
824
|
+
constructor(message, hint) {
|
|
825
|
+
super(message, 2, hint);
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
HelpShown = class HelpShown extends Exit {
|
|
829
|
+
constructor() {
|
|
830
|
+
super("help shown", 0);
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
completion = { active: false };
|
|
834
|
+
OUTPUT_OPTIONS = {
|
|
835
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
836
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
837
|
+
};
|
|
838
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
839
|
+
});
|
|
840
|
+
|
|
841
|
+
// ../kit/src/argv.ts
|
|
842
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
843
|
+
import { resolve as resolve3 } from "path";
|
|
844
|
+
import process10 from "process";
|
|
845
|
+
function commandLine() {
|
|
846
|
+
try {
|
|
847
|
+
return readFileSync2("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
848
|
+
} catch {
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
function realPath(word) {
|
|
853
|
+
try {
|
|
854
|
+
return realpathSync(resolve3(word));
|
|
855
|
+
} catch {
|
|
856
|
+
return;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), script = process10.argv[1]) {
|
|
860
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
861
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve3(word) === script || realPath(word) === target));
|
|
862
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
863
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
864
|
+
}
|
|
865
|
+
var init_argv = () => {};
|
|
866
|
+
|
|
867
|
+
// ../kit/src/chart.ts
|
|
868
|
+
var init_chart = __esm(() => {
|
|
869
|
+
init_format();
|
|
870
|
+
init_mode();
|
|
871
|
+
init_style();
|
|
872
|
+
init_theme();
|
|
873
|
+
});
|
|
874
|
+
|
|
875
|
+
// ../kit/src/process.ts
|
|
876
|
+
import process11 from "process";
|
|
877
|
+
function holdSignals(cleanup) {
|
|
878
|
+
let received;
|
|
879
|
+
let child;
|
|
880
|
+
const held = {
|
|
881
|
+
get signal() {
|
|
882
|
+
return received;
|
|
883
|
+
},
|
|
884
|
+
forward: (to) => {
|
|
885
|
+
child = to;
|
|
886
|
+
},
|
|
887
|
+
release: () => {
|
|
888
|
+
for (const signal of SIGNALS)
|
|
889
|
+
process11.off(signal, onSignal);
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
function onSignal(signal) {
|
|
893
|
+
received = signal;
|
|
894
|
+
if (child !== undefined) {
|
|
895
|
+
child.kill(signal);
|
|
896
|
+
return;
|
|
897
|
+
}
|
|
898
|
+
if (cleanup === undefined)
|
|
899
|
+
return;
|
|
900
|
+
held.release();
|
|
901
|
+
cleanup(signal);
|
|
902
|
+
process11.kill(process11.pid, signal);
|
|
903
|
+
}
|
|
904
|
+
for (const signal of SIGNALS)
|
|
905
|
+
process11.on(signal, onSignal);
|
|
906
|
+
return held;
|
|
907
|
+
}
|
|
908
|
+
var SIGNALS;
|
|
909
|
+
var init_process = __esm(() => {
|
|
910
|
+
SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
911
|
+
});
|
|
912
|
+
|
|
913
|
+
// ../kit/src/progress.ts
|
|
914
|
+
import process12 from "process";
|
|
915
|
+
function liveRegion(render, stream = process12.stderr, env = process12.env) {
|
|
916
|
+
if (!takesControlCodes(stream, env))
|
|
917
|
+
return { redraw: () => {
|
|
918
|
+
return;
|
|
919
|
+
}, print: (text) => void stream.write(`${text}
|
|
920
|
+
`), stop: () => {
|
|
921
|
+
return;
|
|
922
|
+
} };
|
|
923
|
+
const write = stream.write.bind(stream);
|
|
924
|
+
let frame = 0;
|
|
925
|
+
let drawn = false;
|
|
926
|
+
const columns = () => {
|
|
927
|
+
const now = stream.getWindowSize?.()[0] ?? stream.columns;
|
|
928
|
+
return now === undefined || now === 0 ? 80 : now;
|
|
929
|
+
};
|
|
930
|
+
const clear = () => {
|
|
931
|
+
if (drawn)
|
|
932
|
+
write(CLEAR_BELOW);
|
|
933
|
+
drawn = false;
|
|
934
|
+
};
|
|
935
|
+
const draw = () => {
|
|
936
|
+
const width = columns() - 1;
|
|
937
|
+
const height = stream.rows === undefined || stream.rows === 0 ? 24 : stream.rows;
|
|
938
|
+
const lines = render(FRAMES[frame++ % FRAMES.length]).slice(0, Math.max(1, height - 1)).map((line) => cutToWidth(line, width));
|
|
939
|
+
if (lines.length === 0) {
|
|
940
|
+
clear();
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
write(`${CLEAR_BELOW}${lines.join(`
|
|
944
|
+
`)}${lines.length > 1 ? `\x1B[${lines.length - 1}A` : ""}\r`);
|
|
945
|
+
drawn = true;
|
|
946
|
+
};
|
|
947
|
+
const timer = setInterval(draw, FRAME_MS);
|
|
948
|
+
stream.on?.("resize", draw);
|
|
949
|
+
const restore = interceptOutput(clear);
|
|
950
|
+
const release = swallowInput();
|
|
951
|
+
const onExit = () => {
|
|
952
|
+
clear();
|
|
953
|
+
release();
|
|
954
|
+
};
|
|
955
|
+
const signals = holdSignals(stop);
|
|
956
|
+
function stop() {
|
|
957
|
+
clearInterval(timer);
|
|
958
|
+
stream.off?.("resize", draw);
|
|
959
|
+
clear();
|
|
960
|
+
restore();
|
|
961
|
+
release();
|
|
962
|
+
process12.off("exit", onExit);
|
|
963
|
+
signals.release();
|
|
964
|
+
}
|
|
965
|
+
timer.unref();
|
|
966
|
+
process12.on("exit", onExit);
|
|
967
|
+
return {
|
|
968
|
+
redraw: draw,
|
|
969
|
+
print: (text) => {
|
|
970
|
+
clear();
|
|
971
|
+
write(`${text}
|
|
972
|
+
`);
|
|
973
|
+
draw();
|
|
974
|
+
},
|
|
975
|
+
stop
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
function progressLine(stream = process12.stderr, env = process12.env) {
|
|
979
|
+
const colors = paint(stream, env);
|
|
980
|
+
const write = stream.write.bind(stream);
|
|
981
|
+
const begun = performance.now();
|
|
982
|
+
let started = begun;
|
|
983
|
+
let current;
|
|
984
|
+
const region = liveRegion((spinner) => current === undefined ? [] : [tintedParts(progressParts(current, spinner, performance.now() - started), colors)], stream, env);
|
|
985
|
+
const end = (line) => {
|
|
986
|
+
region.stop();
|
|
987
|
+
write(`${line}
|
|
988
|
+
`);
|
|
989
|
+
};
|
|
990
|
+
return {
|
|
991
|
+
update: (progress) => {
|
|
992
|
+
const step = current?.step;
|
|
993
|
+
current = progress;
|
|
994
|
+
if (progress.step !== step) {
|
|
995
|
+
started = performance.now();
|
|
996
|
+
region.redraw();
|
|
997
|
+
}
|
|
998
|
+
},
|
|
999
|
+
stop: region.stop,
|
|
1000
|
+
done: (text) => end(marked("ok", text, stream, formatDuration(performance.now() - begun), env)),
|
|
1001
|
+
failed: (text) => end(marked("problem", text, stream, undefined, env))
|
|
1002
|
+
};
|
|
1003
|
+
}
|
|
1004
|
+
function progressParts({ step, done, total, unit }, spinner, ms) {
|
|
1005
|
+
const { theme } = activeTheme();
|
|
1006
|
+
const parts = [{ text: spinner, tint: (colors) => tinted(colors, theme.colors.accent) }, { text: ` ${step}`, tint: () => plain }];
|
|
1007
|
+
if (total !== undefined && total > 0) {
|
|
1008
|
+
const counted = Math.min(done ?? 0, total);
|
|
1009
|
+
const filled = Math.round(counted / total * BAR_WIDTH);
|
|
1010
|
+
parts.push({ text: " ", tint: () => plain }, { text: theme.glyphs.bar.repeat(filled), tint: (colors) => () => shaded(theme, colors, theme.glyphs.bar, filled, BAR_WIDTH) }, { text: theme.glyphs.bar.repeat(BAR_WIDTH - filled), tint: (colors) => colors.dim }, { text: ` ${counted}/${total}${unit === undefined ? "" : ` ${unit}`}`, tint: (colors) => colors.dim });
|
|
1011
|
+
}
|
|
1012
|
+
parts.push({ text: ` ${formatElapsed(ms)}`, tint: (colors) => colors.dim });
|
|
1013
|
+
return parts;
|
|
1014
|
+
}
|
|
1015
|
+
function plain(text) {
|
|
1016
|
+
return text;
|
|
1017
|
+
}
|
|
1018
|
+
function tintedParts(parts, colors) {
|
|
1019
|
+
return parts.map(({ text, tint }) => tint(colors)(text)).join("");
|
|
1020
|
+
}
|
|
1021
|
+
function cutToWidth(line, width) {
|
|
1022
|
+
if (Bun.stringWidth(line) <= width)
|
|
1023
|
+
return line;
|
|
1024
|
+
let room = width;
|
|
1025
|
+
let kept = "";
|
|
1026
|
+
let index = 0;
|
|
1027
|
+
let linked = false;
|
|
1028
|
+
while (index < line.length) {
|
|
1029
|
+
ESCAPE_CODE.lastIndex = index;
|
|
1030
|
+
const escape = ESCAPE_CODE.exec(line);
|
|
1031
|
+
if (escape !== null) {
|
|
1032
|
+
kept += escape[0];
|
|
1033
|
+
linked ||= escape[0].startsWith(`${ESC}]`);
|
|
1034
|
+
index = ESCAPE_CODE.lastIndex;
|
|
1035
|
+
continue;
|
|
1036
|
+
}
|
|
1037
|
+
const char = String.fromCodePoint(line.codePointAt(index));
|
|
1038
|
+
const columns = Bun.stringWidth(char);
|
|
1039
|
+
if (columns > room)
|
|
1040
|
+
break;
|
|
1041
|
+
kept += char;
|
|
1042
|
+
room -= columns;
|
|
1043
|
+
index += char.length;
|
|
1044
|
+
}
|
|
1045
|
+
return `${kept}${RESET_STYLE}${linked ? CLOSE_LINK : ""}`;
|
|
1046
|
+
}
|
|
1047
|
+
function swallowInput() {
|
|
1048
|
+
const input = process12.stdin;
|
|
1049
|
+
if (!input.isTTY)
|
|
1050
|
+
return () => {
|
|
1051
|
+
return;
|
|
1052
|
+
};
|
|
1053
|
+
const onData = (data) => {
|
|
1054
|
+
if (data.includes(CTRL_C))
|
|
1055
|
+
process12.kill(process12.pid, "SIGINT");
|
|
1056
|
+
};
|
|
1057
|
+
input.setRawMode(true);
|
|
1058
|
+
input.on("data", onData);
|
|
1059
|
+
input.resume();
|
|
1060
|
+
let released = false;
|
|
1061
|
+
return () => {
|
|
1062
|
+
if (released)
|
|
1063
|
+
return;
|
|
1064
|
+
released = true;
|
|
1065
|
+
input.off("data", onData);
|
|
1066
|
+
input.pause();
|
|
1067
|
+
input.setRawMode(false);
|
|
1068
|
+
};
|
|
1069
|
+
}
|
|
1070
|
+
function interceptOutput(clear) {
|
|
1071
|
+
const targets = [...CONSOLE_METHODS.map((name) => [console, name]), [process12.stdout, "write"], [process12.stderr, "write"]];
|
|
1072
|
+
const wrapped = targets.map(([target, name]) => {
|
|
1073
|
+
const original = Reflect.get(target, name);
|
|
1074
|
+
const wrapper = (...args) => {
|
|
1075
|
+
clear();
|
|
1076
|
+
return original.apply(target, args);
|
|
1077
|
+
};
|
|
1078
|
+
Reflect.set(target, name, wrapper);
|
|
1079
|
+
return { target, name, original, wrapper };
|
|
1080
|
+
});
|
|
1081
|
+
return () => {
|
|
1082
|
+
for (const { target, name, original, wrapper } of wrapped) {
|
|
1083
|
+
if (Reflect.get(target, name) === wrapper)
|
|
1084
|
+
Reflect.set(target, name, original);
|
|
1085
|
+
}
|
|
1086
|
+
};
|
|
1087
|
+
}
|
|
1088
|
+
var FRAMES, FRAME_MS = 200, BAR_WIDTH = 20, CLEAR_BELOW = "\r\x1B[J", ESC, ESCAPE_CODE, RESET_STYLE, CTRL_C = 3, CLOSE_LINK, CONSOLE_METHODS;
|
|
1089
|
+
var init_progress = __esm(() => {
|
|
1090
|
+
init_format();
|
|
1091
|
+
init_process();
|
|
1092
|
+
init_style();
|
|
1093
|
+
init_theme();
|
|
1094
|
+
FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
1095
|
+
ESC = String.fromCharCode(27);
|
|
1096
|
+
ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
1097
|
+
RESET_STYLE = `${ESC}[0m`;
|
|
1098
|
+
CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
1099
|
+
CONSOLE_METHODS = ["log", "info", "warn", "error", "debug", "dir", "dirxml", "table", "trace", "group", "groupCollapsed", "count", "timeEnd", "timeLog", "assert"];
|
|
1100
|
+
});
|
|
1101
|
+
|
|
1102
|
+
// ../kit/src/tool.ts
|
|
1103
|
+
var init_tool = __esm(() => {
|
|
1104
|
+
init_format();
|
|
1105
|
+
init_process();
|
|
1106
|
+
});
|
|
1107
|
+
|
|
1108
|
+
// ../kit/src/ci.ts
|
|
1109
|
+
var init_ci = __esm(() => {
|
|
1110
|
+
init_args();
|
|
1111
|
+
init_format();
|
|
1112
|
+
init_progress();
|
|
1113
|
+
init_style();
|
|
1114
|
+
init_tool();
|
|
1115
|
+
});
|
|
1116
|
+
|
|
1117
|
+
// ../kit/src/completions.ts
|
|
1118
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
1119
|
+
if (shell === "fish")
|
|
1120
|
+
return `${header}
|
|
1121
|
+
${FISH_FUNCTION}
|
|
1122
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
1123
|
+
`).join("")}`;
|
|
1124
|
+
if (shell === "bash")
|
|
1125
|
+
return `${header}
|
|
1126
|
+
${BASH_FUNCTION}
|
|
1127
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1128
|
+
`;
|
|
1129
|
+
return `${header}
|
|
1130
|
+
${ZSH_FUNCTION}
|
|
1131
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1132
|
+
`;
|
|
1133
|
+
}
|
|
1134
|
+
var COMPLETION_SHELLS, FISH_FUNCTION = `functions -q __kaynooo_cli_complete; or function __kaynooo_cli_complete --argument-names bin --description 'what a @kaynooo/cli-kit bin offers for the word being typed'
|
|
1135
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
1136
|
+
set -l current (commandline -ct)
|
|
1137
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
1138
|
+
if test "$line" = __files__
|
|
1139
|
+
__fish_complete_path $current
|
|
1140
|
+
else
|
|
1141
|
+
echo $line
|
|
1142
|
+
end
|
|
1143
|
+
end
|
|
1144
|
+
end`, BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1145
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
1146
|
+
local -a lines
|
|
1147
|
+
COMPREPLY=()
|
|
1148
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
1149
|
+
for line in "\${lines[@]}"; do
|
|
1150
|
+
if [[ $line == __files__ ]]; then
|
|
1151
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
1152
|
+
else
|
|
1153
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
1154
|
+
fi
|
|
1155
|
+
done
|
|
1156
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
1157
|
+
}`, ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1158
|
+
local line
|
|
1159
|
+
local -a described plain
|
|
1160
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
1161
|
+
if [[ $line == __files__ ]]; then
|
|
1162
|
+
_files
|
|
1163
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
1164
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
1165
|
+
else
|
|
1166
|
+
plain+=("$line")
|
|
1167
|
+
fi
|
|
1168
|
+
done
|
|
1169
|
+
(( \${#described} )) && _describe -V value described
|
|
1170
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
1171
|
+
return 0
|
|
1172
|
+
}`;
|
|
1173
|
+
var init_completions = __esm(() => {
|
|
1174
|
+
COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
1175
|
+
});
|
|
1176
|
+
|
|
1177
|
+
// ../kit/src/notify.ts
|
|
1178
|
+
import process13 from "process";
|
|
1179
|
+
function base64(text) {
|
|
1180
|
+
return Buffer.from(text).toString("base64");
|
|
1181
|
+
}
|
|
1182
|
+
function notification(title, body, env = process13.env) {
|
|
1183
|
+
const id = `kit${process13.pid}`;
|
|
1184
|
+
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\\`];
|
|
1185
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1186
|
+
}
|
|
1187
|
+
function notifyEnd(command, code, ms, { stream = process13.stderr, env = process13.env } = {}) {
|
|
1188
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1189
|
+
return;
|
|
1190
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1191
|
+
}
|
|
1192
|
+
var NOTIFY_AFTER_MS = 1e4, CANCELLED = 130;
|
|
1193
|
+
var init_notify = __esm(() => {
|
|
1194
|
+
init_format();
|
|
1195
|
+
init_mode();
|
|
1196
|
+
});
|
|
1197
|
+
|
|
1198
|
+
// ../kit/src/logs.ts
|
|
1199
|
+
var DAY_MS, CLI_FOLDER = "kaynooo-cli";
|
|
1200
|
+
var init_logs = __esm(() => {
|
|
1201
|
+
DAY_MS = 24 * 60 * 60 * 1000;
|
|
1202
|
+
});
|
|
1203
|
+
|
|
1204
|
+
// ../kit/src/usage.ts
|
|
1205
|
+
import { appendFileSync, mkdirSync } from "fs";
|
|
1206
|
+
import { homedir as homedir3 } from "os";
|
|
1207
|
+
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
1208
|
+
import process14 from "process";
|
|
1209
|
+
function noteUsageError(message) {
|
|
1210
|
+
usageError = message;
|
|
1211
|
+
}
|
|
1212
|
+
function stateHome(env = process14.env) {
|
|
1213
|
+
const dir = env.XDG_STATE_HOME;
|
|
1214
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
1215
|
+
}
|
|
1216
|
+
function usagePath(env = process14.env) {
|
|
1217
|
+
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1218
|
+
}
|
|
1219
|
+
function usageRecorded(env = process14.env) {
|
|
1220
|
+
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1221
|
+
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1222
|
+
}
|
|
1223
|
+
function flagNames(argv) {
|
|
1224
|
+
const end = argv.indexOf("--");
|
|
1225
|
+
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
1226
|
+
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
1227
|
+
}
|
|
1228
|
+
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
1229
|
+
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
1230
|
+
usageError = undefined;
|
|
1231
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
1232
|
+
}
|
|
1233
|
+
function recordUsage(entry, env = process14.env) {
|
|
1234
|
+
if (!usageRecorded(env))
|
|
1235
|
+
return;
|
|
1236
|
+
try {
|
|
1237
|
+
const path = usagePath(env);
|
|
1238
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
1239
|
+
appendFileSync(path, `${JSON.stringify(entry)}
|
|
1240
|
+
`, { mode: 384 });
|
|
1241
|
+
} catch {}
|
|
1242
|
+
}
|
|
1243
|
+
var UNKNOWN_OPTION2, FLAG_NAME, LONGEST_NAME = 40, usageError;
|
|
1244
|
+
var init_usage = __esm(() => {
|
|
1245
|
+
init_logs();
|
|
1246
|
+
UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
1247
|
+
FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
1248
|
+
});
|
|
1249
|
+
|
|
1250
|
+
// ../kit/src/cli.ts
|
|
1251
|
+
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
1252
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
1253
|
+
import process15 from "process";
|
|
1254
|
+
async function commandRows(all, colors) {
|
|
1255
|
+
const commands = shown(all);
|
|
1256
|
+
const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
|
|
1257
|
+
const groups = new Map([["Commands:", []]]);
|
|
1258
|
+
const summaries = await Promise.all(Object.values(commands).map(async ({ summary }) => resolveSummary(summary)));
|
|
1259
|
+
for (const [index, [name, { group }]] of Object.entries(commands).entries()) {
|
|
1260
|
+
const heading = group === undefined ? "Commands:" : `${group}:`;
|
|
1261
|
+
const rows = groups.get(heading) ?? [];
|
|
1262
|
+
rows.push(` ${colors.cyan(name.padEnd(width))} ${colors.dim(summaries[index])}`);
|
|
1263
|
+
groups.set(heading, rows);
|
|
1264
|
+
}
|
|
1265
|
+
return [...groups].filter(([, rows]) => rows.length > 0).flatMap(([heading, rows], index) => [...index === 0 ? [] : [""], colors.bold(heading), ...rows]);
|
|
1266
|
+
}
|
|
1267
|
+
function shown(commands) {
|
|
1268
|
+
return Object.fromEntries(Object.entries(commands).filter(([, { hidden }]) => hidden !== true));
|
|
1269
|
+
}
|
|
1270
|
+
function takeOutputFlags(argv) {
|
|
1271
|
+
let index = 0;
|
|
1272
|
+
for (;index < argv.length; index++) {
|
|
1273
|
+
const word = argv[index];
|
|
1274
|
+
if (word === "--plain")
|
|
1275
|
+
applyOutput(undefined, true);
|
|
1276
|
+
else if (word.startsWith("--color="))
|
|
1277
|
+
applyOutput(word.slice("--color=".length), undefined);
|
|
1278
|
+
else if (word === "--color" && argv[index + 1] !== undefined)
|
|
1279
|
+
applyOutput(argv[++index], undefined);
|
|
1280
|
+
else
|
|
1281
|
+
break;
|
|
1282
|
+
}
|
|
1283
|
+
return argv.slice(index);
|
|
1284
|
+
}
|
|
1285
|
+
async function resolveSummary(summary) {
|
|
1286
|
+
return typeof summary === "string" ? summary : summary();
|
|
1287
|
+
}
|
|
1288
|
+
function scopeOf(commands, extra, aliases) {
|
|
1289
|
+
return { commands: typeof commands === "function" ? {} : commands, lazy: [...typeof commands === "function" ? [commands] : [], ...extra === undefined ? [] : [extra]], aliases };
|
|
1290
|
+
}
|
|
1291
|
+
async function expand(scope, words) {
|
|
1292
|
+
if (scope.lazy.length === 0)
|
|
1293
|
+
return scope;
|
|
1294
|
+
const commands = { ...scope.commands };
|
|
1295
|
+
for (const added of await Promise.all(scope.lazy.map(async (lazy) => lazy(words)))) {
|
|
1296
|
+
for (const [name, command] of Object.entries(added))
|
|
1297
|
+
commands[name] ??= command;
|
|
1298
|
+
}
|
|
1299
|
+
return { ...scope, commands, lazy: [] };
|
|
1300
|
+
}
|
|
1301
|
+
async function help2({ path, header, summary: lazySummary, commands, defaultCommand, examples, replaces }, stream) {
|
|
1302
|
+
const colors = paint(stream);
|
|
1303
|
+
const prefix = path.join(" ");
|
|
1304
|
+
const summary = await resolveSummary(lazySummary);
|
|
1305
|
+
if (wantsHelpJson())
|
|
1306
|
+
return JSON.stringify(description(`${prefix} <command> [options]: ${summary}`, { examples, replaces }));
|
|
1307
|
+
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
1308
|
+
const options = fallback !== undefined && "run" in fallback ? await optionsOf(fallback.run) : undefined;
|
|
1309
|
+
const own = Object.entries(options ?? {}).filter(([name]) => !(name in TOP_OPTIONS));
|
|
1310
|
+
return [
|
|
1311
|
+
header(colors, summary),
|
|
1312
|
+
"",
|
|
1313
|
+
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
1314
|
+
"",
|
|
1315
|
+
...await commandRows(commands, colors),
|
|
1316
|
+
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
1317
|
+
"",
|
|
1318
|
+
colors.bold("Options:"),
|
|
1319
|
+
...optionRows(path.length === 1 ? TOP_OPTIONS : LEVEL_OPTIONS, colors),
|
|
1320
|
+
...exampleRows(examples ?? [], colors),
|
|
1321
|
+
"",
|
|
1322
|
+
`${colors.dim("Run")} ${prefix} ${colors.cyan("<command>")} --help ${colors.dim("for its options.")}`
|
|
1323
|
+
].join(`
|
|
1324
|
+
`);
|
|
1325
|
+
}
|
|
1326
|
+
function printError(prefix, message, hint, cause) {
|
|
1327
|
+
const colors = paint(process15.stderr);
|
|
1328
|
+
const styled = takesControlCodes(process15.stderr);
|
|
1329
|
+
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1330
|
+
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1331
|
+
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
1332
|
+
console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
|
|
1333
|
+
}
|
|
1334
|
+
function printJsonError(message, hint, cause) {
|
|
1335
|
+
console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
|
|
1336
|
+
}
|
|
1337
|
+
function wantsJson(argv) {
|
|
1338
|
+
const end = argv.indexOf("--");
|
|
1339
|
+
return (end === -1 ? argv : argv.slice(0, end)).includes("--json");
|
|
1340
|
+
}
|
|
1341
|
+
function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
1342
|
+
if (error instanceof HelpShown)
|
|
1343
|
+
return 0;
|
|
1344
|
+
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
1345
|
+
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
1346
|
+
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
1347
|
+
if (error instanceof Exit && error.code === 2)
|
|
1348
|
+
noteUsageError(error.message);
|
|
1349
|
+
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
1350
|
+
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
1351
|
+
return error instanceof Exit ? error.code : 1;
|
|
1352
|
+
}
|
|
1353
|
+
async function dispatch(level, typed, { version, redact }) {
|
|
1354
|
+
const prefix = level.path.join(" ");
|
|
1355
|
+
let argv;
|
|
1356
|
+
try {
|
|
1357
|
+
argv = takeOutputFlags(typed);
|
|
1358
|
+
} catch (error) {
|
|
1359
|
+
return reportThrown(prefix, error);
|
|
1360
|
+
}
|
|
1361
|
+
const [name, ...args] = argv;
|
|
1362
|
+
const fallback = level.defaultCommand === undefined ? undefined : level.commands[level.defaultCommand];
|
|
1363
|
+
if (name === undefined && level.runBare && fallback !== undefined && "run" in fallback) {
|
|
1364
|
+
try {
|
|
1365
|
+
return await fallback.run([]);
|
|
1366
|
+
} catch (error) {
|
|
1367
|
+
return reportThrown(`${prefix} ${level.defaultCommand}`, error, redact, false);
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
if (name === undefined && level.path.length > 1) {
|
|
1371
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stderr));
|
|
1372
|
+
return 2;
|
|
1373
|
+
}
|
|
1374
|
+
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1375
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process15.stdout));
|
|
1376
|
+
return 0;
|
|
1377
|
+
}
|
|
1378
|
+
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
1379
|
+
console.log(version);
|
|
1380
|
+
return 0;
|
|
1381
|
+
}
|
|
1382
|
+
let command = level.commands[level.aliases?.[name] ?? name];
|
|
1383
|
+
let rest = args;
|
|
1384
|
+
let ran = name;
|
|
1385
|
+
if (command === undefined && level.lazy.length > 0) {
|
|
1386
|
+
level = await expand(level, [...level.path.slice(1), ...argv]);
|
|
1387
|
+
command = level.commands[level.aliases?.[name] ?? name];
|
|
1388
|
+
}
|
|
1389
|
+
if (command === undefined && level.defaultCommand !== undefined) {
|
|
1390
|
+
command = level.commands[level.defaultCommand];
|
|
1391
|
+
rest = argv;
|
|
1392
|
+
ran = level.defaultCommand;
|
|
1393
|
+
}
|
|
1394
|
+
if (command === undefined) {
|
|
1395
|
+
const meant = closest(name, Object.keys(shown(level.commands)));
|
|
1396
|
+
printError(prefix, `no command ${name}`, meant === undefined ? `run ${prefix} --help for its commands` : `did you mean ${meant}?`);
|
|
1397
|
+
return 2;
|
|
1398
|
+
}
|
|
1399
|
+
if ("commands" in command) {
|
|
1400
|
+
const { summary } = command;
|
|
1401
|
+
return dispatch({ path: [...level.path, name], header: (colors, text) => `${colors.bold(`${prefix} ${name}`)} ${text}`, summary, ...scopeOf(command.commands, command.extraCommands, command.aliases), defaultCommand: undefined, runBare: false, examples: command.examples, replaces: undefined }, rest, { version, redact });
|
|
1402
|
+
}
|
|
1403
|
+
try {
|
|
1404
|
+
return await command.run(rest);
|
|
1405
|
+
} catch (error) {
|
|
1406
|
+
return reportThrown(`${prefix} ${ran}`, error, redact, wantsJson(rest));
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
async function completingOf(run) {
|
|
1410
|
+
completion.active = true;
|
|
1411
|
+
try {
|
|
1412
|
+
await run([]);
|
|
1413
|
+
} catch (error) {
|
|
1414
|
+
if (error instanceof Completing)
|
|
1415
|
+
return error;
|
|
1416
|
+
} finally {
|
|
1417
|
+
completion.active = false;
|
|
1418
|
+
}
|
|
1419
|
+
return new Completing({});
|
|
1420
|
+
}
|
|
1421
|
+
async function optionsOf(run) {
|
|
1422
|
+
return (await completingOf(run)).options;
|
|
1423
|
+
}
|
|
1424
|
+
function candidateLine(candidate) {
|
|
1425
|
+
return typeof candidate === "string" ? candidate : candidate.join("\t");
|
|
1426
|
+
}
|
|
1427
|
+
function positionalBeingTyped(before, { options, positionals }) {
|
|
1428
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1429
|
+
const typed = [];
|
|
1430
|
+
let at = 0;
|
|
1431
|
+
while (at < before.length) {
|
|
1432
|
+
const word = before[at];
|
|
1433
|
+
if (word === "--") {
|
|
1434
|
+
typed.push(...before.slice(at + 1));
|
|
1435
|
+
break;
|
|
1436
|
+
}
|
|
1437
|
+
if (!word.startsWith("-"))
|
|
1438
|
+
typed.push(word);
|
|
1439
|
+
else if (takesValue(word))
|
|
1440
|
+
at++;
|
|
1441
|
+
at++;
|
|
1442
|
+
}
|
|
1443
|
+
const last = positionals.at(-1);
|
|
1444
|
+
if (typed.length < positionals.length)
|
|
1445
|
+
return { name: positionals[typed.length], typed };
|
|
1446
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1447
|
+
}
|
|
1448
|
+
async function leafCandidates(run, words) {
|
|
1449
|
+
const completing = await completingOf(run);
|
|
1450
|
+
if ((words.at(-1) ?? "").startsWith("-"))
|
|
1451
|
+
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1452
|
+
const flag = words.at(-2);
|
|
1453
|
+
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1454
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1455
|
+
if (option?.type === "string") {
|
|
1456
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1457
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1458
|
+
}
|
|
1459
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1460
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1461
|
+
}
|
|
1462
|
+
async function candidates(scope, defaultCommand, words, before = []) {
|
|
1463
|
+
const [word = "", ...rest] = words;
|
|
1464
|
+
const listing = rest.length === 0 && !word.startsWith("-");
|
|
1465
|
+
let { commands, aliases } = scope;
|
|
1466
|
+
let command = commands[aliases?.[word] ?? word];
|
|
1467
|
+
if (listing || command === undefined) {
|
|
1468
|
+
({ commands, aliases } = await expand(scope, [...before, ...words]));
|
|
1469
|
+
command = commands[aliases?.[word] ?? word];
|
|
1470
|
+
}
|
|
1471
|
+
if (listing) {
|
|
1472
|
+
const own = await Promise.all(Object.entries(shown(commands)).map(async ([name, { summary }]) => `${name} ${await resolveSummary(summary)}`));
|
|
1473
|
+
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
1474
|
+
const values = fallback !== undefined && "run" in fallback ? await leafCandidates(fallback.run, [word]) : [];
|
|
1475
|
+
const valueOf = (line) => line.slice(0, line.includes("\t") ? line.indexOf("\t") : undefined);
|
|
1476
|
+
return [...own, ...values.filter((line) => line !== FILES && !(valueOf(line) in commands))];
|
|
1477
|
+
}
|
|
1478
|
+
if (command === undefined) {
|
|
1479
|
+
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
1480
|
+
return fallback !== undefined && "run" in fallback ? leafCandidates(fallback.run, words) : [];
|
|
1481
|
+
}
|
|
1482
|
+
return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
|
|
1483
|
+
}
|
|
1484
|
+
function flagValue([flag = "", ...rest]) {
|
|
1485
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1486
|
+
}
|
|
1487
|
+
function printCompletionScript(name, args) {
|
|
1488
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1489
|
+
if (shell === undefined || args.length !== 1) {
|
|
1490
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1491
|
+
return 2;
|
|
1492
|
+
}
|
|
1493
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1494
|
+
return 0;
|
|
1495
|
+
}
|
|
1496
|
+
async function printCandidates(found) {
|
|
1497
|
+
for (const line of await found)
|
|
1498
|
+
console.log(line);
|
|
1499
|
+
return 0;
|
|
1500
|
+
}
|
|
1501
|
+
function packageVersion(entry = Bun.main) {
|
|
1502
|
+
let resolved = entry;
|
|
1503
|
+
try {
|
|
1504
|
+
resolved = realpathSync2(entry);
|
|
1505
|
+
} catch {}
|
|
1506
|
+
for (let dir = dirname3(resolved);; dir = dirname3(dir)) {
|
|
1507
|
+
try {
|
|
1508
|
+
const { version } = JSON.parse(readFileSync3(join5(dir, "package.json"), "utf8"));
|
|
1509
|
+
if (typeof version === "string")
|
|
1510
|
+
return version;
|
|
1511
|
+
} catch {}
|
|
1512
|
+
if (dirname3(dir) === dir)
|
|
1513
|
+
return "0.0.0";
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
1517
|
+
const version = cli.version ?? packageVersion();
|
|
1518
|
+
if (argv[0] === COMPLETE)
|
|
1519
|
+
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1520
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1521
|
+
return printCompletionScript(cli.name, flagValue(argv));
|
|
1522
|
+
const started = performance.now();
|
|
1523
|
+
const code = await dispatch({ path: [cli.name], header: (colors, about) => `${colors.bold(cli.name)} ${colors.dim(version)} ${about}`, summary: cli.about, ...scopeOf(cli.commands, cli.extraCommands, cli.aliases), defaultCommand: cli.defaultCommand, runBare: cli.runBare === true, examples: cli.examples, replaces: cli.replaces }, argv, { version, redact: cli.redact });
|
|
1524
|
+
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
|
1525
|
+
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1526
|
+
if (cli.usage !== false) {
|
|
1527
|
+
try {
|
|
1528
|
+
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
1529
|
+
} catch {}
|
|
1530
|
+
}
|
|
1531
|
+
return code;
|
|
1532
|
+
}
|
|
1533
|
+
function commandPath(scope, argv) {
|
|
1534
|
+
const path = [];
|
|
1535
|
+
let level = scope;
|
|
1536
|
+
for (const word of argv.filter((each) => !each.startsWith("-"))) {
|
|
1537
|
+
const name = level.aliases !== undefined && Object.hasOwn(level.aliases, word) ? level.aliases[word] ?? word : word;
|
|
1538
|
+
const command = Object.hasOwn(level.commands, name) ? level.commands[name] : undefined;
|
|
1539
|
+
if (command === undefined)
|
|
1540
|
+
break;
|
|
1541
|
+
path.push(word);
|
|
1542
|
+
if (!("commands" in command))
|
|
1543
|
+
break;
|
|
1544
|
+
level = scopeOf(command.commands, command.extraCommands, command.aliases);
|
|
1545
|
+
}
|
|
1546
|
+
return path.length === 0 ? undefined : path.join(" ");
|
|
1547
|
+
}
|
|
1548
|
+
var LEVEL_OPTIONS, TOP_OPTIONS, COMPLETE = "__complete", FILES = "__files__", COMPLETIONS = "--completions";
|
|
1549
|
+
var init_cli = __esm(() => {
|
|
1550
|
+
init_args();
|
|
1551
|
+
init_argv();
|
|
1552
|
+
init_completions();
|
|
1553
|
+
init_notify();
|
|
1554
|
+
init_style();
|
|
1555
|
+
init_text2();
|
|
1556
|
+
init_usage();
|
|
1557
|
+
LEVEL_OPTIONS = {
|
|
1558
|
+
...OUTPUT_OPTIONS,
|
|
1559
|
+
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1560
|
+
};
|
|
1561
|
+
TOP_OPTIONS = {
|
|
1562
|
+
...LEVEL_OPTIONS,
|
|
1563
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1564
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1565
|
+
};
|
|
1566
|
+
});
|
|
1567
|
+
// ../kit/src/excerpt.ts
|
|
1568
|
+
var init_excerpt = __esm(() => {
|
|
1569
|
+
init_text2();
|
|
1570
|
+
});
|
|
1571
|
+
|
|
1572
|
+
// ../kit/src/folders.ts
|
|
1573
|
+
var SKIPPED_FOLDERS;
|
|
1574
|
+
var init_folders = __esm(() => {
|
|
1575
|
+
init_user_config();
|
|
1576
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1577
|
+
});
|
|
1578
|
+
|
|
1579
|
+
// ../kit/src/git.ts
|
|
1580
|
+
var init_git = __esm(() => {
|
|
1581
|
+
init_args();
|
|
1582
|
+
init_tool();
|
|
1583
|
+
});
|
|
1584
|
+
|
|
1585
|
+
// ../kit/src/limit.ts
|
|
1586
|
+
var init_limit = __esm(() => {
|
|
1587
|
+
init_args();
|
|
1588
|
+
});
|
|
1589
|
+
// ../kit/src/report.ts
|
|
1590
|
+
var init_report = __esm(() => {
|
|
1591
|
+
init_cli();
|
|
1592
|
+
init_style();
|
|
1593
|
+
init_text2();
|
|
1594
|
+
});
|
|
1595
|
+
|
|
1596
|
+
// ../kit/src/secrets.ts
|
|
1597
|
+
var SECRET_WORDS;
|
|
1598
|
+
var init_secrets = __esm(() => {
|
|
1599
|
+
SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1600
|
+
});
|
|
1601
|
+
|
|
1602
|
+
// ../kit/src/sessions.ts
|
|
1603
|
+
var {Glob } = globalThis.Bun;
|
|
1604
|
+
var SESSION_FILES, ACCOUNT_DIRS;
|
|
1605
|
+
var init_sessions = __esm(() => {
|
|
1606
|
+
SESSION_FILES = new Glob("*.json");
|
|
1607
|
+
ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1608
|
+
});
|
|
1609
|
+
|
|
1610
|
+
// ../kit/src/size.ts
|
|
1611
|
+
function parseSize(text, bareUnit = 1) {
|
|
1612
|
+
const match = SIZE.exec(text.trim());
|
|
1613
|
+
if (match === null)
|
|
1614
|
+
return;
|
|
1615
|
+
const suffix = match[2].toLowerCase();
|
|
1616
|
+
return Math.round(Number(match[1]) * (suffix === "" ? bareUnit : 1024 ** POWERS[suffix]));
|
|
1617
|
+
}
|
|
1618
|
+
function formatSize(bytes) {
|
|
1619
|
+
let value = bytes;
|
|
1620
|
+
let unit = 0;
|
|
1621
|
+
while (value >= 1024 && unit < UNITS2.length - 1) {
|
|
1622
|
+
value /= 1024;
|
|
1623
|
+
unit++;
|
|
1624
|
+
}
|
|
1625
|
+
return unit === 0 ? `${value}B` : `${value.toFixed(value < 10 ? 1 : 0)}${UNITS2[unit]}`;
|
|
1626
|
+
}
|
|
1627
|
+
var SIZE, POWERS, UNITS2;
|
|
1628
|
+
var init_size = __esm(() => {
|
|
1629
|
+
SIZE = /^(\d+(?:\.\d+)?)\s*([kmgt]?)i?b?$/i;
|
|
1630
|
+
POWERS = { "": 0, k: 1, m: 2, g: 3, t: 4 };
|
|
1631
|
+
UNITS2 = ["B", "K", "M", "G", "T"];
|
|
1632
|
+
});
|
|
1633
|
+
|
|
1634
|
+
// ../kit/src/watch.ts
|
|
1635
|
+
var init_watch = __esm(() => {
|
|
1636
|
+
init_args();
|
|
1637
|
+
init_input();
|
|
1638
|
+
init_style();
|
|
1639
|
+
});
|
|
1640
|
+
|
|
1641
|
+
// ../kit/src/workspace-root.ts
|
|
1642
|
+
var init_workspace_root = __esm(() => {
|
|
1643
|
+
init_user_config();
|
|
1644
|
+
});
|
|
1645
|
+
|
|
1646
|
+
// ../kit/src/index.ts
|
|
1647
|
+
var init_src = __esm(() => {
|
|
1648
|
+
init_excerpt();
|
|
1649
|
+
init_advisory();
|
|
1650
|
+
init_args();
|
|
1651
|
+
init_argv();
|
|
1652
|
+
init_chart();
|
|
1653
|
+
init_ci();
|
|
1654
|
+
init_cli();
|
|
1655
|
+
init_completions();
|
|
1656
|
+
init_config();
|
|
1657
|
+
init_folders();
|
|
1658
|
+
init_format();
|
|
1659
|
+
init_git();
|
|
1660
|
+
init_limit();
|
|
1661
|
+
init_logs();
|
|
1662
|
+
init_mode();
|
|
1663
|
+
init_process();
|
|
1664
|
+
init_report();
|
|
1665
|
+
init_secrets();
|
|
1666
|
+
init_sessions();
|
|
1667
|
+
init_size();
|
|
1668
|
+
init_style();
|
|
1669
|
+
init_text2();
|
|
1670
|
+
init_theme();
|
|
1671
|
+
init_tool();
|
|
1672
|
+
init_usage();
|
|
1673
|
+
init_user_config();
|
|
1674
|
+
init_watch();
|
|
1675
|
+
init_workspace_root();
|
|
1676
|
+
});
|
|
1677
|
+
|
|
1678
|
+
// ../arc/src/proc.ts
|
|
1679
|
+
import process17 from "process";
|
|
1680
|
+
async function interactive(argv, cwd = process17.cwd()) {
|
|
1681
|
+
return Bun.spawn(argv, { cwd, stdin: "inherit", stdout: "inherit", stderr: "inherit" }).exited;
|
|
1682
|
+
}
|
|
1683
|
+
var init_proc = __esm(() => {
|
|
1684
|
+
init_src();
|
|
1685
|
+
});
|
|
1686
|
+
|
|
1687
|
+
// ../arc/src/extract.ts
|
|
1688
|
+
import { existsSync as existsSync3, rmSync, statSync as statSync2 } from "fs";
|
|
1689
|
+
import { basename, join as join6, resolve as resolve4 } from "path";
|
|
1690
|
+
function archiveSuffix(file) {
|
|
1691
|
+
return extractorOf(file)?.[0];
|
|
1692
|
+
}
|
|
1693
|
+
function extractorOf(file) {
|
|
1694
|
+
return EXTRACTORS.find(([suffix]) => file.toLowerCase().endsWith(suffix));
|
|
1695
|
+
}
|
|
1696
|
+
async function extractArchive(file, cwd) {
|
|
1697
|
+
if (!existsSync3(file) || !statSync2(file).isFile())
|
|
1698
|
+
return fail(`'${file}' is not a file`, 1);
|
|
1699
|
+
const extractor = extractorOf(file);
|
|
1700
|
+
if (extractor === undefined)
|
|
1701
|
+
return fail(`'${file}' cannot be extracted: unknown extension`, 1);
|
|
1702
|
+
const [suffix, argvOf] = extractor;
|
|
1703
|
+
const argv = argvOf(resolve4(file));
|
|
1704
|
+
if (Bun.which(argv[0] ?? "") === null)
|
|
1705
|
+
return fail(`${argv[0]} is not on PATH`, 1);
|
|
1706
|
+
if (!LONE.has(suffix))
|
|
1707
|
+
return await interactive(argv, cwd) === 0 ? 0 : 1;
|
|
1708
|
+
const name = basename(file).slice(0, -suffix.length);
|
|
1709
|
+
if (name === "")
|
|
1710
|
+
return fail(`'${file}' has no name left once ${suffix} is taken off`, 1);
|
|
1711
|
+
const target = join6(cwd, name);
|
|
1712
|
+
if (await Bun.spawn(argv, { stdin: "ignore", stdout: Bun.file(target), stderr: "inherit" }).exited === 0)
|
|
1713
|
+
return 0;
|
|
1714
|
+
rmSync(target, { force: true });
|
|
1715
|
+
return 1;
|
|
1716
|
+
}
|
|
1717
|
+
var EXTRACTORS, LONE;
|
|
1718
|
+
var init_extract = __esm(() => {
|
|
1719
|
+
init_src();
|
|
1720
|
+
init_proc();
|
|
1721
|
+
EXTRACTORS = [
|
|
1722
|
+
[".tar.bz2", (file) => ["tar", "xjf", file]],
|
|
1723
|
+
[".tar.gz", (file) => ["tar", "xzf", file]],
|
|
1724
|
+
[".tar.xz", (file) => ["tar", "xJf", file]],
|
|
1725
|
+
[".tar.zst", (file) => ["tar", "--zstd", "-xf", file]],
|
|
1726
|
+
[".tbz2", (file) => ["tar", "xjf", file]],
|
|
1727
|
+
[".tgz", (file) => ["tar", "xzf", file]],
|
|
1728
|
+
[".tar", (file) => ["tar", "xf", file]],
|
|
1729
|
+
[".tbz", (file) => ["tar", "xjf", file]],
|
|
1730
|
+
[".txz", (file) => ["tar", "xJf", file]],
|
|
1731
|
+
[".tzst", (file) => ["tar", "--zstd", "-xf", file]],
|
|
1732
|
+
[".bz2", (file) => ["bunzip2", "-c", file]],
|
|
1733
|
+
[".gz", (file) => ["gunzip", "-c", file]],
|
|
1734
|
+
[".xz", (file) => ["xz", "-dc", file]],
|
|
1735
|
+
[".zst", (file) => ["zstd", "-dc", file]],
|
|
1736
|
+
[".zip", (file) => ["unzip", file]],
|
|
1737
|
+
[".z", (file) => ["gzip", "-dc", file]],
|
|
1738
|
+
[".rar", (file) => ["unrar", "x", file]],
|
|
1739
|
+
[".7z", (file) => ["7z", "x", file]]
|
|
1740
|
+
];
|
|
1741
|
+
LONE = new Set([".bz2", ".gz", ".xz", ".zst", ".z"]);
|
|
1742
|
+
});
|
|
1743
|
+
|
|
1744
|
+
// src/download.ts
|
|
1745
|
+
import { existsSync as existsSync4, rmSync as rmSync2 } from "fs";
|
|
1746
|
+
import { basename as basename2, join as join7 } from "path";
|
|
1747
|
+
async function download(url, dir, maxSize) {
|
|
1748
|
+
const response = await reach(url);
|
|
1749
|
+
const name = fileName(response, url);
|
|
1750
|
+
const path = join7(dir, name);
|
|
1751
|
+
if (existsSync4(path))
|
|
1752
|
+
return fail(`'${path}' already exists`, 1, "download into another folder with -o, or none to get a new one");
|
|
1753
|
+
const length = Number(response.headers.get("content-length") ?? Number.NaN);
|
|
1754
|
+
const total = Number.isFinite(length) && length > 0 ? length : undefined;
|
|
1755
|
+
if (total !== undefined && total > maxSize)
|
|
1756
|
+
return fail(`${url} is ${formatSize(total)}, over --max-size ${formatSize(maxSize)}`, 1);
|
|
1757
|
+
const line = progressLine();
|
|
1758
|
+
const hasher = new Bun.CryptoHasher("sha256");
|
|
1759
|
+
const writer = Bun.file(path).writer();
|
|
1760
|
+
const head = [];
|
|
1761
|
+
let headSize = 0;
|
|
1762
|
+
let size = 0;
|
|
1763
|
+
line.update({ step: name, ...counted(0, total) });
|
|
1764
|
+
try {
|
|
1765
|
+
for await (const chunk of response.body ?? new ReadableStream) {
|
|
1766
|
+
size += chunk.length;
|
|
1767
|
+
if (size > maxSize)
|
|
1768
|
+
fail(`${url} goes over --max-size ${formatSize(maxSize)}`, 1);
|
|
1769
|
+
if (headSize < HEAD_BYTES) {
|
|
1770
|
+
head.push(chunk.subarray(0, HEAD_BYTES - headSize));
|
|
1771
|
+
headSize += head.at(-1).length;
|
|
1772
|
+
}
|
|
1773
|
+
hasher.update(chunk);
|
|
1774
|
+
await writer.write(chunk);
|
|
1775
|
+
line.update({ step: name, ...counted(size, total) });
|
|
1776
|
+
}
|
|
1777
|
+
await writer.end();
|
|
1778
|
+
} catch (error) {
|
|
1779
|
+
await writer.end();
|
|
1780
|
+
rmSync2(path, { force: true });
|
|
1781
|
+
line.failed(name);
|
|
1782
|
+
throw error;
|
|
1783
|
+
}
|
|
1784
|
+
line.done(`${name} ${formatSize(size)}`);
|
|
1785
|
+
const start = Buffer.concat(head);
|
|
1786
|
+
return {
|
|
1787
|
+
path,
|
|
1788
|
+
name,
|
|
1789
|
+
size,
|
|
1790
|
+
url: response.url === "" ? url : response.url,
|
|
1791
|
+
type: response.headers.get("content-type") ?? "",
|
|
1792
|
+
sha256: hasher.digest("hex"),
|
|
1793
|
+
html: HTML_START.test(start.toString("utf8")),
|
|
1794
|
+
text: !start.includes(0)
|
|
1795
|
+
};
|
|
1796
|
+
}
|
|
1797
|
+
async function reach(url) {
|
|
1798
|
+
let response;
|
|
1799
|
+
try {
|
|
1800
|
+
response = await fetch(url);
|
|
1801
|
+
} catch (error) {
|
|
1802
|
+
return fail(`cannot reach ${url}: ${error instanceof Error ? error.message : String(error)}`, 1);
|
|
1803
|
+
}
|
|
1804
|
+
return response.ok ? response : fail(`${url} answered ${response.status} ${response.statusText}`.trimEnd(), 1);
|
|
1805
|
+
}
|
|
1806
|
+
function fileName(response, requested) {
|
|
1807
|
+
const disposition = DISPOSITION_NAME.exec(response.headers.get("content-disposition") ?? "")?.[1];
|
|
1808
|
+
const raw = disposition ?? new URL(response.url === "" ? requested : response.url).pathname.split("/").at(-1) ?? "";
|
|
1809
|
+
const name = basename2(decoded(raw).replaceAll("\\", "/")).replaceAll("\x00", "");
|
|
1810
|
+
return name === "" || name === "." || name === ".." ? "download" : name;
|
|
1811
|
+
}
|
|
1812
|
+
function decoded(text) {
|
|
1813
|
+
try {
|
|
1814
|
+
return decodeURIComponent(text);
|
|
1815
|
+
} catch {
|
|
1816
|
+
return text;
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
function counted(done, total) {
|
|
1820
|
+
if (total === undefined)
|
|
1821
|
+
return {};
|
|
1822
|
+
const [unit, scale] = total >= 1024 ** 2 ? ["MiB", 1024 ** 2] : ["KiB", 1024];
|
|
1823
|
+
return { done: Math.floor(done / scale), total: Math.ceil(total / scale), unit };
|
|
1824
|
+
}
|
|
1825
|
+
var HEAD_BYTES = 8192, HTML_START, DISPOSITION_NAME;
|
|
1826
|
+
var init_download = __esm(() => {
|
|
1827
|
+
init_src();
|
|
1828
|
+
init_progress();
|
|
1829
|
+
HTML_START = /^\s*<(?:!doctype html|html)[\s>]/i;
|
|
1830
|
+
DISPOSITION_NAME = /filename\*?=(?:UTF-8'')?"?([^";]+)"?/i;
|
|
1831
|
+
});
|
|
1832
|
+
|
|
1833
|
+
// src/install.ts
|
|
1834
|
+
import { chmodSync, closeSync, copyFileSync, existsSync as existsSync5, mkdirSync as mkdirSync2, openSync, readSync, renameSync, statSync as statSync3 } from "fs";
|
|
1835
|
+
import { homedir as homedir4 } from "os";
|
|
1836
|
+
import { basename as basename3, delimiter, join as join8, relative } from "path";
|
|
1837
|
+
import process18 from "process";
|
|
1838
|
+
function binDir() {
|
|
1839
|
+
return join8(homedir4(), ".local", "bin");
|
|
1840
|
+
}
|
|
1841
|
+
function binDirOnPath() {
|
|
1842
|
+
return (process18.env.PATH ?? "").split(delimiter).includes(binDir());
|
|
1843
|
+
}
|
|
1844
|
+
async function pickBinary(root, wanted) {
|
|
1845
|
+
const found = [];
|
|
1846
|
+
for await (const file of new Bun.Glob("**/*").scan({ cwd: root, onlyFiles: true, dot: true }))
|
|
1847
|
+
found.push(join8(root, file));
|
|
1848
|
+
const executables = found.filter(isExecutable).sort();
|
|
1849
|
+
const matching = wanted === undefined ? executables : executables.filter((file) => basename3(file) === wanted);
|
|
1850
|
+
const listed = executables.map((file) => relative(root, file)).join(", ");
|
|
1851
|
+
if (matching.length === 1)
|
|
1852
|
+
return matching[0];
|
|
1853
|
+
if (executables.length === 0)
|
|
1854
|
+
return fail(`the archive holds no executable`, 1);
|
|
1855
|
+
if (matching.length === 0)
|
|
1856
|
+
return fail(`the archive holds no executable named ${wanted}: ${listed}`, 1);
|
|
1857
|
+
return fail(`the archive holds several executables: ${listed}`, 1, "name the one to install: --bin <name>");
|
|
1858
|
+
}
|
|
1859
|
+
function installBinary(source, name, force) {
|
|
1860
|
+
const target = join8(binDir(), name);
|
|
1861
|
+
if (existsSync5(target) && !force)
|
|
1862
|
+
return fail(`'${target}' already exists`, 1, "pass --force to replace it");
|
|
1863
|
+
mkdirSync2(binDir(), { recursive: true });
|
|
1864
|
+
copyFileSync(source, `${target}.dl-tmp`);
|
|
1865
|
+
chmodSync(`${target}.dl-tmp`, 493);
|
|
1866
|
+
renameSync(`${target}.dl-tmp`, target);
|
|
1867
|
+
return target;
|
|
1868
|
+
}
|
|
1869
|
+
function isExecutable(file) {
|
|
1870
|
+
if ((statSync3(file).mode & 73) !== 0)
|
|
1871
|
+
return true;
|
|
1872
|
+
const start = Buffer.alloc(4);
|
|
1873
|
+
const fd = openSync(file, "r");
|
|
1874
|
+
readSync(fd, start, 0, 4, 0);
|
|
1875
|
+
closeSync(fd);
|
|
1876
|
+
return start.equals(ELF);
|
|
1877
|
+
}
|
|
1878
|
+
var ELF;
|
|
1879
|
+
var init_install = __esm(() => {
|
|
1880
|
+
init_src();
|
|
1881
|
+
ELF = Buffer.from([127, 69, 76, 70]);
|
|
1882
|
+
});
|
|
1883
|
+
|
|
1884
|
+
// src/script.ts
|
|
1885
|
+
function summarize(script) {
|
|
1886
|
+
const findings = [];
|
|
1887
|
+
const env = new Set;
|
|
1888
|
+
for (const [index, text] of script.split(`
|
|
1889
|
+
`).entries()) {
|
|
1890
|
+
if (COMMENT.test(text))
|
|
1891
|
+
continue;
|
|
1892
|
+
const does = PATTERNS.filter(([, pattern]) => pattern.test(text)).map(([word]) => word);
|
|
1893
|
+
if (does.length > 0)
|
|
1894
|
+
findings.push({ line: index + 1, does: does.join(", "), text: text.trim() });
|
|
1895
|
+
for (const [, name] of text.matchAll(VARIABLE)) {
|
|
1896
|
+
if (UPPER_CASE.test(name) && !SHELL_OWN.has(name))
|
|
1897
|
+
env.add(name);
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
return { findings, env: [...env].sort() };
|
|
1901
|
+
}
|
|
1902
|
+
var PATTERNS, COMMENT, VARIABLE, UPPER_CASE, SHELL_OWN;
|
|
1903
|
+
var init_script = __esm(() => {
|
|
1904
|
+
PATTERNS = [
|
|
1905
|
+
["fetches", /\b(?:curl|wget)\b|https?:\/\//],
|
|
1906
|
+
["sudo", /\b(?:sudo|doas)\b/],
|
|
1907
|
+
["removes", /\brm\s+-[a-z]*[rf]/i],
|
|
1908
|
+
["profile", /\.(?:bashrc|bash_profile|zshrc|zprofile|zshenv|profile)\b|\.config\/fish\b/],
|
|
1909
|
+
["system", /(?:^|[\s"'=:])\/(?:usr|etc|opt|bin|sbin|lib)\//],
|
|
1910
|
+
["runs", /\|\s*(?:sudo\s+)?(?:ba|z|da)?sh\b|\beval\b/]
|
|
1911
|
+
];
|
|
1912
|
+
COMMENT = /^\s*#/;
|
|
1913
|
+
VARIABLE = /\$\{?([A-Z_]\w*)/gi;
|
|
1914
|
+
UPPER_CASE = /^[A-Z_][A-Z0-9_]*$/;
|
|
1915
|
+
SHELL_OWN = new Set(["HOME", "PATH", "PWD", "OLDPWD", "SHELL", "USER", "IFS", "TERM", "LINENO", "RANDOM", "UID", "EUID", "BASH_SOURCE", "BASH_VERSION", "ZSH_VERSION"]);
|
|
1916
|
+
});
|
|
1917
|
+
|
|
1918
|
+
// src/state.ts
|
|
1919
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync6, mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync as renameSync2, rmSync as rmSync3, writeFileSync } from "fs";
|
|
1920
|
+
import { dirname as dirname4, join as join9 } from "path";
|
|
1921
|
+
function stateDir() {
|
|
1922
|
+
return join9(stateHome(), CLI_FOLDER, "dl");
|
|
1923
|
+
}
|
|
1924
|
+
function seenDir(url) {
|
|
1925
|
+
return join9(stateDir(), "seen", new Bun.CryptoHasher("sha256").update(url).digest("hex").slice(0, 32));
|
|
1926
|
+
}
|
|
1927
|
+
function lastSeen(url) {
|
|
1928
|
+
const dir = seenDir(url);
|
|
1929
|
+
const meta = join9(dir, "seen.json");
|
|
1930
|
+
if (!existsSync6(meta))
|
|
1931
|
+
return;
|
|
1932
|
+
const content = join9(dir, "content");
|
|
1933
|
+
return { seen: JSON.parse(readFileSync4(meta, "utf8")), content: existsSync6(content) ? content : undefined };
|
|
1934
|
+
}
|
|
1935
|
+
function remember(url, file) {
|
|
1936
|
+
const dir = seenDir(url);
|
|
1937
|
+
const content = join9(dir, "content");
|
|
1938
|
+
mkdirSync3(dir, { recursive: true });
|
|
1939
|
+
rmSync3(content, { force: true });
|
|
1940
|
+
if (file.text && !file.html && file.size <= KEPT_TEXT)
|
|
1941
|
+
copyFileSync2(file.path, content);
|
|
1942
|
+
writeJson(join9(dir, "seen.json"), { url, sha256: file.sha256, size: file.size, at: new Date().toISOString() });
|
|
1943
|
+
}
|
|
1944
|
+
function ledgerPath() {
|
|
1945
|
+
return join9(stateDir(), "ledger.json");
|
|
1946
|
+
}
|
|
1947
|
+
function readLedger() {
|
|
1948
|
+
const path = ledgerPath();
|
|
1949
|
+
return existsSync6(path) ? JSON.parse(readFileSync4(path, "utf8")) : [];
|
|
1950
|
+
}
|
|
1951
|
+
function record(entry) {
|
|
1952
|
+
writeJson(ledgerPath(), [...readLedger().filter((other) => other.kind !== entry.kind || other.name !== entry.name), entry]);
|
|
1953
|
+
}
|
|
1954
|
+
function writeJson(path, value) {
|
|
1955
|
+
mkdirSync3(dirname4(path), { recursive: true });
|
|
1956
|
+
writeFileSync(`${path}.tmp`, `${JSON.stringify(value, null, 2)}
|
|
1957
|
+
`);
|
|
1958
|
+
renameSync2(`${path}.tmp`, path);
|
|
1959
|
+
}
|
|
1960
|
+
var KEPT_TEXT;
|
|
1961
|
+
var init_state = __esm(() => {
|
|
1962
|
+
init_src();
|
|
1963
|
+
KEPT_TEXT = 1024 * 1024;
|
|
1964
|
+
});
|
|
1965
|
+
|
|
1966
|
+
// src/sums.ts
|
|
1967
|
+
import { basename as basename4 } from "path";
|
|
1968
|
+
function sumFor(text, name) {
|
|
1969
|
+
const entries = [];
|
|
1970
|
+
for (const line of text.split(`
|
|
1971
|
+
`).map((line) => line.trim())) {
|
|
1972
|
+
const gnu = GNU_LINE.exec(line);
|
|
1973
|
+
const bsd = gnu === null ? BSD_LINE.exec(line) : null;
|
|
1974
|
+
if (gnu !== null)
|
|
1975
|
+
entries.push([gnu[1], gnu[2]]);
|
|
1976
|
+
else if (bsd !== null)
|
|
1977
|
+
entries.push([bsd[2], bsd[1]]);
|
|
1978
|
+
}
|
|
1979
|
+
const named = entries.find(([, file]) => file !== undefined && basename4(file) === name);
|
|
1980
|
+
if (named !== undefined)
|
|
1981
|
+
return named[0].toLowerCase();
|
|
1982
|
+
const [only] = entries;
|
|
1983
|
+
return entries.length === 1 && only[1] === undefined ? only[0].toLowerCase() : undefined;
|
|
1984
|
+
}
|
|
1985
|
+
async function fetchSum(url, name) {
|
|
1986
|
+
return sumFor(await (await reach(url)).text(), name) ?? fail(`${url} holds no sha256 for ${name}`, 1);
|
|
1987
|
+
}
|
|
1988
|
+
var GNU_LINE, BSD_LINE;
|
|
1989
|
+
var init_sums = __esm(() => {
|
|
1990
|
+
init_src();
|
|
1991
|
+
init_download();
|
|
1992
|
+
GNU_LINE = /^([0-9a-f]{64})(?:\s+\*?(\S.*))?$/i;
|
|
1993
|
+
BSD_LINE = /^SHA256 \((.+)\) = ([0-9a-f]{64})$/i;
|
|
1994
|
+
});
|
|
1995
|
+
|
|
1996
|
+
// src/get.ts
|
|
1997
|
+
var exports_get = {};
|
|
1998
|
+
__export(exports_get, {
|
|
1999
|
+
get: () => get
|
|
2000
|
+
});
|
|
2001
|
+
import { chmodSync as chmodSync2, existsSync as existsSync7, mkdirSync as mkdirSync4, mkdtempSync, rmSync as rmSync4 } from "fs";
|
|
2002
|
+
import { tmpdir } from "os";
|
|
2003
|
+
import { basename as basename5, extname, join as join10, resolve as resolve5 } from "path";
|
|
2004
|
+
import process19 from "process";
|
|
2005
|
+
async function get(args) {
|
|
2006
|
+
const { values, positionals: [url], rest = [] } = parse(args, USAGE, OPTIONS, {
|
|
2007
|
+
positionals: ["<url>"],
|
|
2008
|
+
rest: true,
|
|
2009
|
+
exits: EXITS,
|
|
2010
|
+
replaces: "curl -fsSL <url> | sh, curl -LO then sha256sum -c by hand, and unpacking a release to copy its binary into ~/.local/bin",
|
|
2011
|
+
examples: [
|
|
2012
|
+
["dl https://bun.sh/install", "download it to read it"],
|
|
2013
|
+
["dl https://bun.sh/install --exec --sha256 <sha>", "run the script that was read"],
|
|
2014
|
+
["dl https://example.com/releases/tool-linux-amd64 --sums https://example.com/releases/SHA256SUMS --bin tool", "a checked binary, installed"],
|
|
2015
|
+
["dl https://example.com/tool.tar.gz -x", "download and unpack"]
|
|
2016
|
+
]
|
|
2017
|
+
});
|
|
2018
|
+
if (!URL.canParse(url) || !["http:", "https:"].includes(new URL(url).protocol))
|
|
2019
|
+
badUsage(`'${url}' is not an http or https URL`);
|
|
2020
|
+
if (values.sha256 !== undefined && !SHA256.test(values.sha256))
|
|
2021
|
+
badUsage(`--sha256 takes 64 hex digits, not '${values.sha256}'`);
|
|
2022
|
+
if (values.yes === true && values.exec !== true)
|
|
2023
|
+
badUsage("--yes goes with --exec");
|
|
2024
|
+
if (values.force === true && values.bin === undefined)
|
|
2025
|
+
badUsage("--force goes with --bin");
|
|
2026
|
+
if (rest.length > 0 && values.exec !== true)
|
|
2027
|
+
badUsage("arguments after -- go to an --exec script");
|
|
2028
|
+
if (values.bin !== undefined && (values.bin.includes("/") || values.bin === "." || values.bin === ".."))
|
|
2029
|
+
badUsage(`--bin takes a command name, not '${values.bin}'`);
|
|
2030
|
+
const maxSize = parseSize(values["max-size"] ?? DEFAULT_MAX_SIZE) ?? badUsage(`--max-size takes a size such as 500M or 2G, not '${values["max-size"]}'`);
|
|
2031
|
+
const created = values.output === undefined;
|
|
2032
|
+
const dir = created ? mkdtempSync(join10(tmpdir(), "dl-")) : resolve5(values.output);
|
|
2033
|
+
mkdirSync4(dir, { recursive: true });
|
|
2034
|
+
const expectsFile = values.exec === true || values.bin !== undefined || values.extract === true;
|
|
2035
|
+
const { file, verified } = await fetchChecked(url, dir, created, { maxSize, expectsFile, sha256: values.sha256?.toLowerCase(), sums: values.sums });
|
|
2036
|
+
const last = lastSeen(url);
|
|
2037
|
+
const report = { path: file.path, size: file.size, url: file.url, type: file.type, sha256: file.sha256, verified, seen: "first download" };
|
|
2038
|
+
if (last !== undefined && last.seen.sha256 === file.sha256)
|
|
2039
|
+
report.seen = `same as the download of ${formatAge(last.seen.at)}`;
|
|
2040
|
+
else if (last !== undefined)
|
|
2041
|
+
report.seen = `changed since the download of ${formatAge(last.seen.at)}, was ${last.seen.sha256.slice(0, 12)}`;
|
|
2042
|
+
if (last?.content !== undefined && last.seen.sha256 !== file.sha256 && file.text)
|
|
2043
|
+
report.diff = await diff(last.content, file, values.json !== true);
|
|
2044
|
+
remember(url, file);
|
|
2045
|
+
const extracted = values.extract === true || values.bin !== undefined && archiveSuffix(file.name) !== undefined;
|
|
2046
|
+
if (extracted)
|
|
2047
|
+
report.extracted = await extract(file);
|
|
2048
|
+
if (values.bin !== undefined) {
|
|
2049
|
+
const source = report.extracted === undefined ? file.path : await pickBinary(report.extracted, values.bin === "" ? undefined : values.bin);
|
|
2050
|
+
const name = values.bin === "" ? basename5(source) : values.bin;
|
|
2051
|
+
report.installed = installBinary(source, name, values.force === true);
|
|
2052
|
+
record({ kind: "bin", name, url, sha256: file.sha256, path: report.installed, at: new Date().toISOString() });
|
|
2053
|
+
}
|
|
2054
|
+
if (values.exec === true)
|
|
2055
|
+
report.script = summarize(await Bun.file(file.path).text());
|
|
2056
|
+
print(report, url, values.json === true);
|
|
2057
|
+
if (values.exec !== true)
|
|
2058
|
+
return 0;
|
|
2059
|
+
if (!verified && values.yes !== true)
|
|
2060
|
+
return fail("not run: no --sha256 or --sums pins this script", 1, `read ${file.path}, then: dl ${url} --exec --sha256 ${file.sha256}`);
|
|
2061
|
+
return runScript(file, url, rest);
|
|
2062
|
+
}
|
|
2063
|
+
async function fetchChecked(url, dir, created, checks) {
|
|
2064
|
+
let file;
|
|
2065
|
+
try {
|
|
2066
|
+
file = await download(url, dir, checks.maxSize);
|
|
2067
|
+
if (file.html && (checks.expectsFile || !HTML_EXTENSIONS.has(extname(file.name).toLowerCase())))
|
|
2068
|
+
fail(`${url} answered an HTML page, not a file`, 1);
|
|
2069
|
+
const expected = checks.sha256 ?? (checks.sums === undefined ? undefined : await fetchSum(checks.sums, file.name));
|
|
2070
|
+
if (expected !== undefined && expected !== file.sha256)
|
|
2071
|
+
fail(`sha256 mismatch for ${file.name}: expected ${expected}, got ${file.sha256}; the file was deleted`, 1);
|
|
2072
|
+
return { file, verified: expected !== undefined };
|
|
2073
|
+
} catch (error) {
|
|
2074
|
+
if (file !== undefined)
|
|
2075
|
+
rmSync4(file.path, { force: true });
|
|
2076
|
+
if (created)
|
|
2077
|
+
rmSync4(dir, { recursive: true, force: true });
|
|
2078
|
+
throw error;
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
async function diff(last, file, colored) {
|
|
2082
|
+
if (Bun.which("git") === null)
|
|
2083
|
+
return "";
|
|
2084
|
+
const color = colored && takesControlCodes(process19.stdout) ? "--color=always" : "--no-color";
|
|
2085
|
+
const child = Bun.spawn(["git", "diff", "--no-index", color, "--", last, file.path], { stdin: "ignore", stdout: "pipe", stderr: "ignore" });
|
|
2086
|
+
const lines = (await child.stdout.text()).trimEnd().split(`
|
|
2087
|
+
`);
|
|
2088
|
+
await child.exited;
|
|
2089
|
+
const hunks = lines.findIndex((line) => Bun.stripANSI(line).startsWith("@@"));
|
|
2090
|
+
return hunks === -1 ? "" : ["--- last", `+++ ${file.name}`, ...lines.slice(hunks)].join(`
|
|
2091
|
+
`);
|
|
2092
|
+
}
|
|
2093
|
+
async function extract(file) {
|
|
2094
|
+
const suffix = archiveSuffix(file.name) ?? fail(`${file.name} is no archive arc can extract`, 1);
|
|
2095
|
+
const folder = join10(file.path, "..", file.name.slice(0, -suffix.length) || "extracted");
|
|
2096
|
+
if (existsSync7(folder))
|
|
2097
|
+
return fail(`'${folder}' already exists`, 1);
|
|
2098
|
+
mkdirSync4(folder);
|
|
2099
|
+
return await extractArchive(file.path, folder) !== 0 ? fail(`extracting ${file.name} failed`, 1) : folder;
|
|
2100
|
+
}
|
|
2101
|
+
function print(report, url, json) {
|
|
2102
|
+
if (json) {
|
|
2103
|
+
printJson(report);
|
|
2104
|
+
return;
|
|
2105
|
+
}
|
|
2106
|
+
const rows = [
|
|
2107
|
+
["path", report.path],
|
|
2108
|
+
["size", formatSize(report.size)],
|
|
2109
|
+
...report.url === url ? [] : [["url", report.url]],
|
|
2110
|
+
["type", report.type === "" ? "-" : report.type],
|
|
2111
|
+
["sha256", `${report.sha256}${report.verified ? " verified" : ""}`],
|
|
2112
|
+
["seen", report.seen],
|
|
2113
|
+
...report.extracted === undefined ? [] : [["extracted", report.extracted]],
|
|
2114
|
+
...report.installed === undefined ? [] : [["installed", report.installed]],
|
|
2115
|
+
...report.installed === undefined || binDirOnPath() ? [] : [["note", `${binDir()} is not on PATH`]]
|
|
2116
|
+
];
|
|
2117
|
+
console.log(table(rows));
|
|
2118
|
+
if (report.diff !== undefined && report.diff !== "")
|
|
2119
|
+
console.log(`
|
|
2120
|
+
${report.diff}`);
|
|
2121
|
+
if (report.script === undefined)
|
|
2122
|
+
return;
|
|
2123
|
+
const { findings, env } = report.script;
|
|
2124
|
+
console.log(findings.length === 0 ? `
|
|
2125
|
+
script: fetches, sudo, removes, profile, system and runs found nowhere` : `
|
|
2126
|
+
script:
|
|
2127
|
+
${table(findings.map(({ line, does, text }) => [`line ${line}`, does, truncate(text, LINE_WIDTH)]))}`);
|
|
2128
|
+
if (env.length > 0)
|
|
2129
|
+
console.log(`reads: ${env.join(", ")}`);
|
|
2130
|
+
}
|
|
2131
|
+
async function runScript(file, url, args) {
|
|
2132
|
+
const shebang = (await Bun.file(file.path).text()).startsWith("#!");
|
|
2133
|
+
chmodSync2(file.path, 448);
|
|
2134
|
+
const code = await Bun.spawn(shebang ? [file.path, ...args] : ["sh", file.path, ...args], { stdin: "inherit", stdout: "inherit", stderr: "inherit" }).exited;
|
|
2135
|
+
if (code !== 0)
|
|
2136
|
+
return fail(`the script exited ${code}`, 1);
|
|
2137
|
+
const { host, pathname } = new URL(url);
|
|
2138
|
+
record({ kind: "script", name: `${host}${pathname}`, url, sha256: file.sha256, at: new Date().toISOString() });
|
|
2139
|
+
return 0;
|
|
2140
|
+
}
|
|
2141
|
+
var USAGE = `dl [options] <url> [-- <script args>]: downloads a file into a new folder of its own, checks its sha256, then extracts it, installs it as a command or runs it as a script
|
|
2142
|
+
|
|
2143
|
+
Without -o the file lands in a new folder under the temp folder; with -o in that folder, created if missing, where nothing is overwritten.
|
|
2144
|
+
Prints where the file went, its size, final URL, type and sha256, and how it compares with the last download of the same URL: a text file that changed since shows its diff.
|
|
2145
|
+
--sha256 or --sums checks the file, which is deleted on a mismatch. An HTML page arriving where a file was expected fails, as does a download over --max-size.
|
|
2146
|
+
--extract unpacks an archive into a new folder beside it, through arc's extractor. --bin installs the file, or the one executable its archive holds, in ~/.local/bin.
|
|
2147
|
+
--exec lists what the script does (what it fetches, sudo, recursive removals, shell profiles and system folders it touches, code it runs in a shell, the variables it reads) and runs it only when --sha256 or --sums pins it, the content then being the one that was read, or with --yes. Arguments after -- go to the script.
|
|
2148
|
+
--bin and --exec record what they installed or ran in the ledger dl ls lists.`, EXITS, OPTIONS, SHA256, DEFAULT_MAX_SIZE = "2G", HTML_EXTENSIONS, LINE_WIDTH = 120;
|
|
2149
|
+
var init_get = __esm(() => {
|
|
2150
|
+
init_extract();
|
|
2151
|
+
init_src();
|
|
2152
|
+
init_download();
|
|
2153
|
+
init_install();
|
|
2154
|
+
init_script();
|
|
2155
|
+
init_state();
|
|
2156
|
+
init_sums();
|
|
2157
|
+
EXITS = [
|
|
2158
|
+
[0, "downloaded, and extracted, installed or run as asked"],
|
|
2159
|
+
[1, "an unreachable URL, an error status, a sha256 mismatch, an HTML page in place of a file, a download over --max-size, a script nothing pins, or one that failed"],
|
|
2160
|
+
[2, "a usage error"]
|
|
2161
|
+
];
|
|
2162
|
+
OPTIONS = {
|
|
2163
|
+
output: { type: "string", short: "o", description: "the folder to download into, created if missing, instead of a new one under the temp folder" },
|
|
2164
|
+
sha256: { type: "string", description: "the sha256 the file must have", conflicts: ["sums"] },
|
|
2165
|
+
sums: { type: "string", description: "the URL of a checksums file (SHA256SUMS) giving the file's sha256" },
|
|
2166
|
+
extract: { type: "boolean", short: "x", description: "unpack the archive into a new folder beside it" },
|
|
2167
|
+
bin: { type: "string", optional: { bare: "" }, description: "install the file, or the one executable its archive holds, in ~/.local/bin, under the name given or its own", conflicts: ["exec"] },
|
|
2168
|
+
force: { type: "boolean", description: "let --bin replace a command of the same name" },
|
|
2169
|
+
exec: { type: "boolean", description: "run the file as a script, once --sha256 or --sums pins it, or with --yes" },
|
|
2170
|
+
yes: { type: "boolean", description: "run an --exec script that nothing pins" },
|
|
2171
|
+
"max-size": { type: "string", description: "the largest download taken, 2G by default" },
|
|
2172
|
+
json: jsonOption()
|
|
2173
|
+
};
|
|
2174
|
+
SHA256 = /^[0-9a-f]{64}$/i;
|
|
2175
|
+
HTML_EXTENSIONS = new Set(["", ".html", ".htm"]);
|
|
2176
|
+
});
|
|
2177
|
+
|
|
2178
|
+
// src/ls.ts
|
|
2179
|
+
var exports_ls = {};
|
|
2180
|
+
__export(exports_ls, {
|
|
2181
|
+
ls: () => ls
|
|
2182
|
+
});
|
|
2183
|
+
function ls(args) {
|
|
2184
|
+
const { values } = parse(args, USAGE2, { json: jsonOption() }, {
|
|
2185
|
+
exits: EXITS2,
|
|
2186
|
+
replaces: "remembering which tools came from a curl and from where",
|
|
2187
|
+
examples: ["dl ls", "dl ls --json"]
|
|
2188
|
+
});
|
|
2189
|
+
const entries = readLedger().sort((a, b) => a.name.localeCompare(b.name));
|
|
2190
|
+
if (values.json === true)
|
|
2191
|
+
printJson(entries);
|
|
2192
|
+
else if (entries.length === 0)
|
|
2193
|
+
console.log("nothing installed or run through dl yet");
|
|
2194
|
+
else
|
|
2195
|
+
console.log(table([["name", "kind", "when", "sha256", "from"], ...entries.map((entry) => [entry.name, entry.kind, formatAge(entry.at), entry.sha256.slice(0, 12), entry.url])], { header: true }));
|
|
2196
|
+
return 0;
|
|
2197
|
+
}
|
|
2198
|
+
var USAGE2 = `dl ls [options]: lists the commands dl installed with --bin and the scripts it ran with --exec, with where each came from and when
|
|
2199
|
+
|
|
2200
|
+
A command installed again, or a script run again, keeps one line, the latest.`, EXITS2;
|
|
2201
|
+
var init_ls = __esm(() => {
|
|
2202
|
+
init_src();
|
|
2203
|
+
init_state();
|
|
2204
|
+
EXITS2 = [[0, "listed, even nothing"], [2, "a usage error"]];
|
|
2205
|
+
});
|
|
2206
|
+
|
|
2207
|
+
// src/cli.ts
|
|
2208
|
+
init_src();
|
|
2209
|
+
import process20 from "process";
|
|
2210
|
+
process20.exitCode = await runCli({
|
|
2211
|
+
name: "dl",
|
|
2212
|
+
about: "downloads a file into a folder of its own, checks its sha256, then extracts it, installs it as a command or runs it as a script once it is pinned",
|
|
2213
|
+
replaces: "curl -fsSL <url> | sh, curl -LO then sha256sum -c by hand, and unpacking a release to copy its binary into ~/.local/bin",
|
|
2214
|
+
examples: [["dl https://bun.sh/install", "download a script to read it"], ["dl https://bun.sh/install --exec --sha256 <sha>", "run the script that was read"], ["dl https://example.com/tool.tar.gz --sums https://example.com/SHA256SUMS --bin tool", "a checked binary, installed"], ["dl ls", "what dl installed or ran"]],
|
|
2215
|
+
defaultCommand: "get",
|
|
2216
|
+
commands: {
|
|
2217
|
+
get: { summary: "download a file, check it, then extract, install or run it as asked", run: async (args) => (await Promise.resolve().then(() => (init_get(), exports_get))).get(args) },
|
|
2218
|
+
ls: { summary: "list the commands dl installed and the scripts it ran", run: async (args) => (await Promise.resolve().then(() => (init_ls(), exports_ls))).ls(args) }
|
|
2219
|
+
}
|
|
2220
|
+
});
|