@kaynooo/cli-dev 0.6.1 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/cli.js +1147 -910
- package/package.json +5 -5
package/dist/cli.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
2
|
// @bun
|
|
3
|
+
var __esm = (fn, res, err) => () => {
|
|
4
|
+
if (fn)
|
|
5
|
+
try {
|
|
6
|
+
res = fn(fn = 0);
|
|
7
|
+
} catch (e) {
|
|
8
|
+
err = [e];
|
|
9
|
+
}
|
|
10
|
+
if (err)
|
|
11
|
+
throw err[0];
|
|
12
|
+
return res;
|
|
13
|
+
};
|
|
3
14
|
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
// ../kit/src/args.ts
|
|
7
|
-
import process6 from "process";
|
|
8
|
-
import { parseArgs } from "util";
|
|
9
|
-
|
|
10
|
-
// ../kit/src/format.ts
|
|
11
|
-
import process4 from "process";
|
|
12
|
-
|
|
13
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
14
|
-
var N = new Map;
|
|
15
|
-
var Nt = /\s+\S*$/;
|
|
16
|
-
var Y = /\s/;
|
|
17
|
-
function ko(t, e, r = "...") {
|
|
15
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rkhsft4a.js
|
|
16
|
+
function Ao(t, e, r = "...") {
|
|
18
17
|
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
19
18
|
if (t.length <= e)
|
|
20
19
|
return t;
|
|
@@ -25,13 +24,22 @@ function ko(t, e, r = "...") {
|
|
|
25
24
|
c = c.trimEnd();
|
|
26
25
|
return s ? (c + n).slice(0, l) : c + n;
|
|
27
26
|
}
|
|
28
|
-
var
|
|
29
|
-
var
|
|
27
|
+
var N, Nt, Y, be, W;
|
|
28
|
+
var init_chunk_rkhsft4a = __esm(() => {
|
|
29
|
+
N = new Map;
|
|
30
|
+
Nt = /\s+\S*$/;
|
|
31
|
+
Y = /\s/;
|
|
32
|
+
be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
33
|
+
W = new Map;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/text.js
|
|
37
|
+
var init_text = __esm(() => {
|
|
38
|
+
init_chunk_rkhsft4a();
|
|
39
|
+
});
|
|
30
40
|
|
|
31
41
|
// ../kit/src/mode.ts
|
|
32
42
|
import process2 from "process";
|
|
33
|
-
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
34
|
-
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
35
43
|
function isSet(value) {
|
|
36
44
|
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
37
45
|
}
|
|
@@ -48,12 +56,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
48
56
|
function isInteractive(streams = process2) {
|
|
49
57
|
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
50
58
|
}
|
|
59
|
+
var MODES, AGENT_VARIABLES;
|
|
60
|
+
var init_mode = __esm(() => {
|
|
61
|
+
MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
62
|
+
AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
63
|
+
});
|
|
51
64
|
|
|
52
|
-
//
|
|
53
|
-
import process3 from "process";
|
|
54
|
-
|
|
55
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
56
|
-
var G2 = /^[a-f0-9]+$/i;
|
|
65
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
57
66
|
function b(r) {
|
|
58
67
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
59
68
|
if (!G2.test(e))
|
|
@@ -64,11 +73,6 @@ function b(r) {
|
|
|
64
73
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
65
74
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
66
75
|
}
|
|
67
|
-
var B2 = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
68
|
-
let [l, n, c] = b(r);
|
|
69
|
-
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
70
|
-
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
71
|
-
var h = new Set(["", "1", "2", "3", "true"]);
|
|
72
76
|
function C(r, e = globalThis.process?.env ?? {}) {
|
|
73
77
|
if (e.FORCE_COLOR !== undefined)
|
|
74
78
|
return h.has(e.FORCE_COLOR);
|
|
@@ -82,7 +86,7 @@ function f(r, e = []) {
|
|
|
82
86
|
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
83
87
|
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
84
88
|
return new Proxy(c, { get(t, i) {
|
|
85
|
-
let a =
|
|
89
|
+
let a = B[i];
|
|
86
90
|
if (Array.isArray(a)) {
|
|
87
91
|
let s = g.get(i);
|
|
88
92
|
if (s === undefined)
|
|
@@ -105,32 +109,66 @@ function f(r, e = []) {
|
|
|
105
109
|
function Fe(r = {}) {
|
|
106
110
|
return f(r);
|
|
107
111
|
}
|
|
108
|
-
var
|
|
112
|
+
var G2, B, h, o;
|
|
113
|
+
var init_chunk_x450vn3m = __esm(() => {
|
|
114
|
+
G2 = /^[a-f0-9]+$/i;
|
|
115
|
+
B = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
116
|
+
let [l, n, c] = b(r);
|
|
117
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
118
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
119
|
+
h = new Set(["", "1", "2", "3", "true"]);
|
|
120
|
+
o = Fe();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
|
|
124
|
+
var init_colors = __esm(() => {
|
|
125
|
+
init_chunk_x450vn3m();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// ../kit/src/config.ts
|
|
129
|
+
var init_config = __esm(() => {
|
|
130
|
+
init_args();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// ../kit/src/user-config.ts
|
|
134
|
+
var init_user_config = () => {};
|
|
109
135
|
|
|
110
136
|
// ../kit/src/theme.ts
|
|
111
|
-
var ENDS
|
|
112
|
-
var
|
|
113
|
-
|
|
114
|
-
|
|
137
|
+
var ENDS, STYLES, MAX_FILE_BYTES, warned;
|
|
138
|
+
var init_theme = __esm(() => {
|
|
139
|
+
init_config();
|
|
140
|
+
init_user_config();
|
|
141
|
+
ENDS = new Map;
|
|
142
|
+
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"]);
|
|
143
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
144
|
+
warned = new Set;
|
|
145
|
+
});
|
|
115
146
|
|
|
116
147
|
// ../kit/src/style.ts
|
|
148
|
+
import process3 from "process";
|
|
117
149
|
function takesControlCodes(stream, env = process3.env) {
|
|
118
150
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
119
151
|
}
|
|
120
152
|
function paint(stream, env = process3.env) {
|
|
121
153
|
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
122
154
|
}
|
|
123
|
-
var STATUS_WORDS
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
155
|
+
var STATUS_WORDS, STATUS_OF;
|
|
156
|
+
var init_style = __esm(() => {
|
|
157
|
+
init_colors();
|
|
158
|
+
init_mode();
|
|
159
|
+
init_theme();
|
|
160
|
+
STATUS_WORDS = {
|
|
161
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
162
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
163
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
164
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
165
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
166
|
+
};
|
|
167
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
168
|
+
});
|
|
131
169
|
|
|
132
170
|
// ../kit/src/format.ts
|
|
133
|
-
|
|
171
|
+
import process4 from "process";
|
|
134
172
|
function formatSeconds(total) {
|
|
135
173
|
let rest = Math.max(0, Math.round(total));
|
|
136
174
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -152,9 +190,8 @@ function upTo(text, separator) {
|
|
|
152
190
|
return end === -1 ? text : text.slice(0, end);
|
|
153
191
|
}
|
|
154
192
|
function truncate(text, width) {
|
|
155
|
-
return
|
|
193
|
+
return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
156
194
|
}
|
|
157
|
-
var ESCAPE = String.fromCharCode(27);
|
|
158
195
|
function textWidth(text) {
|
|
159
196
|
return Bun.stringWidth(text);
|
|
160
197
|
}
|
|
@@ -164,14 +201,39 @@ function jsonText(value, replacer, { stream = process4.stdout, env = process4.en
|
|
|
164
201
|
function printJson(value) {
|
|
165
202
|
console.log(jsonText(value));
|
|
166
203
|
}
|
|
204
|
+
var UNITS, ESCAPE;
|
|
205
|
+
var init_format = __esm(() => {
|
|
206
|
+
init_text();
|
|
207
|
+
init_mode();
|
|
208
|
+
init_style();
|
|
209
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
210
|
+
ESCAPE = String.fromCharCode(27);
|
|
211
|
+
});
|
|
167
212
|
|
|
168
213
|
// ../kit/src/help.ts
|
|
169
214
|
import process5 from "process";
|
|
170
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
171
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
172
|
-
var FULL_STOP = /\.$/;
|
|
173
215
|
function usageLine(usage, colors = paint(process5.stdout)) {
|
|
174
|
-
|
|
216
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
217
|
+
`);
|
|
218
|
+
const blank = lines.indexOf("");
|
|
219
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
220
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
221
|
+
const colon = synopses[0].indexOf(": ");
|
|
222
|
+
const inline = synopses[0].slice(colon + 2);
|
|
223
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
224
|
+
if (colon !== -1)
|
|
225
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
226
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
227
|
+
`)}`;
|
|
228
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
229
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
230
|
+
return [head, ...lead, ...rest].join(`
|
|
231
|
+
`);
|
|
232
|
+
}
|
|
233
|
+
function prose(line, colors) {
|
|
234
|
+
if (colors.cyan("x") === "x")
|
|
235
|
+
return line;
|
|
236
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
175
237
|
}
|
|
176
238
|
function helpText(usage, options, colors = paint(process5.stdout), { examples = [], exits = [] } = {}) {
|
|
177
239
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -206,7 +268,6 @@ function exampleRows(examples, colors = paint(process5.stdout)) {
|
|
|
206
268
|
return [];
|
|
207
269
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
208
270
|
}
|
|
209
|
-
var MAX_INLINE_CHOICES = 24;
|
|
210
271
|
function optionRows(options, colors = paint(process5.stdout)) {
|
|
211
272
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
212
273
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -221,6 +282,15 @@ function optionRows(options, colors = paint(process5.stdout)) {
|
|
|
221
282
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
222
283
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
223
284
|
}
|
|
285
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
286
|
+
var init_help = __esm(() => {
|
|
287
|
+
init_mode();
|
|
288
|
+
init_style();
|
|
289
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
290
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
291
|
+
FULL_STOP = /\.$/;
|
|
292
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
293
|
+
});
|
|
224
294
|
|
|
225
295
|
// ../kit/src/text.ts
|
|
226
296
|
function distance(a, b) {
|
|
@@ -248,9 +318,10 @@ function closest(name, names) {
|
|
|
248
318
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
249
319
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
250
320
|
}
|
|
321
|
+
var init_text2 = () => {};
|
|
322
|
+
|
|
251
323
|
// ../kit/src/input.ts
|
|
252
324
|
import { fstatSync } from "fs";
|
|
253
|
-
var WHOLE = /^\d+$/;
|
|
254
325
|
function wholeNumber(value, name, fallback, min = 1) {
|
|
255
326
|
if (value === undefined)
|
|
256
327
|
return fallback;
|
|
@@ -263,40 +334,28 @@ function isStdinPiped() {
|
|
|
263
334
|
const stat = fstatSync(0);
|
|
264
335
|
return stat.isFIFO() || stat.isFile();
|
|
265
336
|
}
|
|
337
|
+
var WHOLE;
|
|
338
|
+
var init_input = __esm(() => {
|
|
339
|
+
init_args();
|
|
340
|
+
WHOLE = /^\d+$/;
|
|
341
|
+
});
|
|
266
342
|
|
|
267
343
|
// ../kit/src/args.ts
|
|
268
|
-
|
|
344
|
+
import process6 from "process";
|
|
345
|
+
import { parseArgs } from "util";
|
|
269
346
|
function jsonOption(holds) {
|
|
270
347
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
271
348
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
hint;
|
|
275
|
-
constructor(message, code, hint) {
|
|
276
|
-
super(message);
|
|
277
|
-
this.code = code;
|
|
278
|
-
this.hint = hint;
|
|
279
|
-
}
|
|
349
|
+
function copyOption(what) {
|
|
350
|
+
return { type: "boolean", description: `also copy ${what} to the clipboard` };
|
|
280
351
|
}
|
|
281
352
|
function fail(message, code = 2, hint) {
|
|
282
353
|
throw new Exit(message, code, hint);
|
|
283
354
|
}
|
|
284
|
-
|
|
285
|
-
class UsageError extends Exit {
|
|
286
|
-
constructor(message, hint) {
|
|
287
|
-
super(message, 2, hint);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
355
|
function badUsage(message) {
|
|
291
356
|
throw new UsageError(message);
|
|
292
357
|
}
|
|
293
358
|
|
|
294
|
-
class HelpShown extends Exit {
|
|
295
|
-
constructor() {
|
|
296
|
-
super("help shown", 0);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
359
|
class Completing {
|
|
301
360
|
options;
|
|
302
361
|
positionals;
|
|
@@ -307,11 +366,6 @@ class Completing {
|
|
|
307
366
|
this.candidates = candidates;
|
|
308
367
|
}
|
|
309
368
|
}
|
|
310
|
-
var completion = { active: false };
|
|
311
|
-
var OUTPUT_OPTIONS = {
|
|
312
|
-
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
313
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
314
|
-
};
|
|
315
369
|
function applyOutput(color, plain, env = process6.env) {
|
|
316
370
|
const when = plain === true ? "never" : color ?? "auto";
|
|
317
371
|
if (when === "auto")
|
|
@@ -465,7 +519,6 @@ function parseError(error) {
|
|
|
465
519
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
466
520
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
467
521
|
}
|
|
468
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
469
522
|
function nearestOption(message, options, allowNegative) {
|
|
470
523
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
471
524
|
if (typed === undefined)
|
|
@@ -481,911 +534,1095 @@ function nearestOption(message, options, allowNegative) {
|
|
|
481
534
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
482
535
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
483
536
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
537
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
538
|
+
var init_args = __esm(() => {
|
|
539
|
+
init_format();
|
|
540
|
+
init_help();
|
|
541
|
+
init_text2();
|
|
542
|
+
init_help();
|
|
543
|
+
init_input();
|
|
544
|
+
DASHES = /^-+/;
|
|
545
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
546
|
+
Exit = class Exit extends Error {
|
|
547
|
+
code;
|
|
548
|
+
hint;
|
|
549
|
+
[EXIT] = true;
|
|
550
|
+
constructor(message, code, hint) {
|
|
551
|
+
super(message);
|
|
552
|
+
this.code = code;
|
|
553
|
+
this.hint = hint;
|
|
554
|
+
}
|
|
555
|
+
static [Symbol.hasInstance](value) {
|
|
556
|
+
if (this !== Exit)
|
|
557
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
558
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
UsageError = class UsageError extends Exit {
|
|
562
|
+
constructor(message, hint) {
|
|
563
|
+
super(message, 2, hint);
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
HelpShown = class HelpShown extends Exit {
|
|
567
|
+
constructor() {
|
|
568
|
+
super("help shown", 0);
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
completion = { active: false };
|
|
572
|
+
OUTPUT_OPTIONS = {
|
|
573
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
574
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
575
|
+
};
|
|
576
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
// ../kit/src/folders.ts
|
|
580
|
+
import { homedir as homedir2 } from "os";
|
|
581
|
+
import { join as join3 } from "path";
|
|
582
|
+
import process12 from "process";
|
|
583
|
+
function cacheFolder({ home = homedir2(), env = process12.env } = {}) {
|
|
584
|
+
return env.XDG_CACHE_HOME ?? join3(home, ".cache");
|
|
494
585
|
}
|
|
495
|
-
|
|
586
|
+
var SKIPPED_FOLDERS;
|
|
587
|
+
var init_folders = __esm(() => {
|
|
588
|
+
init_user_config();
|
|
589
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
// ../kit/src/answers.ts
|
|
593
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync3, writeFileSync } from "fs";
|
|
594
|
+
import { dirname as dirname3, join as join4 } from "path";
|
|
595
|
+
function answersFile() {
|
|
596
|
+
return join4(cacheFolder(), "kaynooo-cli", "answers.json");
|
|
597
|
+
}
|
|
598
|
+
function stored() {
|
|
496
599
|
try {
|
|
497
|
-
|
|
600
|
+
const parsed = JSON.parse(readFileSync3(answersFile(), "utf-8"));
|
|
601
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
602
|
+
return {};
|
|
603
|
+
return Object.fromEntries(Object.entries(parsed).filter((entry) => Array.isArray(entry[1]) && entry[1].every((answer) => typeof answer === "string")));
|
|
498
604
|
} catch {
|
|
499
|
-
return;
|
|
605
|
+
return {};
|
|
500
606
|
}
|
|
501
607
|
}
|
|
502
|
-
function
|
|
503
|
-
|
|
504
|
-
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve(word) === script || realPath(word) === target));
|
|
505
|
-
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
506
|
-
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
507
|
-
}
|
|
508
|
-
// ../kit/src/process.ts
|
|
509
|
-
var CLIPBOARDS = [["wl-copy"], ["xclip", "-selection", "clipboard"], ["xsel", "--clipboard", "--input"], ["pbcopy"], ["clip.exe"]];
|
|
510
|
-
async function copyText(text, which = Bun.which) {
|
|
511
|
-
for (const [command, ...args] of CLIPBOARDS) {
|
|
512
|
-
const found = which(command);
|
|
513
|
-
if (found !== null && await pipeInto([found, ...args], text))
|
|
514
|
-
return true;
|
|
515
|
-
}
|
|
516
|
-
return false;
|
|
608
|
+
function earlierAnswers(key) {
|
|
609
|
+
return stored()[key] ?? [];
|
|
517
610
|
}
|
|
518
|
-
|
|
611
|
+
function rememberAnswer(key, answer) {
|
|
612
|
+
const all = stored();
|
|
613
|
+
const file = answersFile();
|
|
614
|
+
all[key] = [answer, ...(all[key] ?? []).filter((earlier) => earlier !== answer)].slice(0, KEPT);
|
|
519
615
|
try {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
} catch {
|
|
523
|
-
return false;
|
|
524
|
-
}
|
|
616
|
+
mkdirSync2(dirname3(file), { recursive: true });
|
|
617
|
+
writeFileSync(file, JSON.stringify(all));
|
|
618
|
+
} catch {}
|
|
525
619
|
}
|
|
620
|
+
var KEPT = 50;
|
|
621
|
+
var init_answers = __esm(() => {
|
|
622
|
+
init_folders();
|
|
623
|
+
});
|
|
526
624
|
|
|
527
|
-
// ../kit/src/
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
532
|
-
// ../kit/src/cli.ts
|
|
533
|
-
import { readFileSync as readFileSync2, realpathSync as realpathSync2 } from "fs";
|
|
534
|
-
import { dirname as dirname2, join as join2 } from "path";
|
|
535
|
-
import process10 from "process";
|
|
536
|
-
|
|
537
|
-
// ../kit/src/completions.ts
|
|
538
|
-
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
539
|
-
var 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'
|
|
540
|
-
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
541
|
-
set -l current (commandline -ct)
|
|
542
|
-
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
543
|
-
if test "$line" = __files__
|
|
544
|
-
__fish_complete_path $current
|
|
545
|
-
else
|
|
546
|
-
echo $line
|
|
547
|
-
end
|
|
548
|
-
end
|
|
549
|
-
end`;
|
|
550
|
-
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
551
|
-
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
552
|
-
local -a lines
|
|
553
|
-
COMPREPLY=()
|
|
554
|
-
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
555
|
-
for line in "\${lines[@]}"; do
|
|
556
|
-
if [[ $line == __files__ ]]; then
|
|
557
|
-
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
558
|
-
else
|
|
559
|
-
words+="\${line%%$'\\t'*}"$'\\n'
|
|
560
|
-
fi
|
|
561
|
-
done
|
|
562
|
-
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
563
|
-
}`;
|
|
564
|
-
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
565
|
-
local line
|
|
566
|
-
local -a described plain
|
|
567
|
-
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
568
|
-
if [[ $line == __files__ ]]; then
|
|
569
|
-
_files
|
|
570
|
-
elif [[ $line == *$'\\t'* ]]; then
|
|
571
|
-
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
572
|
-
else
|
|
573
|
-
plain+=("$line")
|
|
574
|
-
fi
|
|
575
|
-
done
|
|
576
|
-
(( \${#described} )) && _describe -V value described
|
|
577
|
-
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
578
|
-
return 0
|
|
579
|
-
}`;
|
|
580
|
-
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
581
|
-
if (shell === "fish")
|
|
582
|
-
return `${header}
|
|
583
|
-
${FISH_FUNCTION}
|
|
584
|
-
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
585
|
-
`).join("")}`;
|
|
586
|
-
if (shell === "bash")
|
|
587
|
-
return `${header}
|
|
588
|
-
${BASH_FUNCTION}
|
|
589
|
-
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
590
|
-
`;
|
|
591
|
-
return `${header}
|
|
592
|
-
${ZSH_FUNCTION}
|
|
593
|
-
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
594
|
-
`;
|
|
625
|
+
// ../kit/src/job.ts
|
|
626
|
+
import process14 from "process";
|
|
627
|
+
function stopJob() {
|
|
628
|
+
process14.kill(0, "SIGTSTP");
|
|
595
629
|
}
|
|
630
|
+
var init_job = () => {};
|
|
596
631
|
|
|
597
|
-
// ../kit/src/
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
var CANCELLED = 130;
|
|
601
|
-
function base64(text) {
|
|
602
|
-
return Buffer.from(text).toString("base64");
|
|
603
|
-
}
|
|
604
|
-
function notification(title, body, env = process8.env) {
|
|
605
|
-
const id = `kit${process8.pid}`;
|
|
606
|
-
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\\`];
|
|
607
|
-
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
632
|
+
// ../kit/src/picker/line.ts
|
|
633
|
+
function isEditKey(key) {
|
|
634
|
+
return EDIT_KEYS.has(key);
|
|
608
635
|
}
|
|
609
|
-
function
|
|
610
|
-
|
|
611
|
-
return;
|
|
612
|
-
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
636
|
+
function endsKills(key) {
|
|
637
|
+
return typeof key !== "object" && !isEditKey(key);
|
|
613
638
|
}
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
import { appendFileSync, mkdirSync } from "fs";
|
|
617
|
-
import { homedir } from "os";
|
|
618
|
-
import { dirname, isAbsolute, join } from "path";
|
|
619
|
-
import process9 from "process";
|
|
620
|
-
|
|
621
|
-
// ../kit/src/logs.ts
|
|
622
|
-
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
623
|
-
var CLI_FOLDER = "kaynooo-cli";
|
|
624
|
-
|
|
625
|
-
// ../kit/src/usage.ts
|
|
626
|
-
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
627
|
-
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
628
|
-
var LONGEST_NAME = 40;
|
|
629
|
-
var usageError;
|
|
630
|
-
function noteUsageError(message) {
|
|
631
|
-
usageError = message;
|
|
639
|
+
function isWord(char) {
|
|
640
|
+
return char !== undefined && WORD_CHARACTER.test(char);
|
|
632
641
|
}
|
|
633
|
-
function
|
|
634
|
-
|
|
635
|
-
|
|
642
|
+
function wordStart(chars, from) {
|
|
643
|
+
let at = from;
|
|
644
|
+
while (at > 0 && !isWord(chars[at - 1]))
|
|
645
|
+
at--;
|
|
646
|
+
while (at > 0 && isWord(chars[at - 1]))
|
|
647
|
+
at--;
|
|
648
|
+
return at;
|
|
636
649
|
}
|
|
637
|
-
function
|
|
638
|
-
|
|
650
|
+
function wordEnd(chars, from) {
|
|
651
|
+
let at = from;
|
|
652
|
+
while (at < chars.length && !isWord(chars[at]))
|
|
653
|
+
at++;
|
|
654
|
+
while (at < chars.length && isWord(chars[at]))
|
|
655
|
+
at++;
|
|
656
|
+
return at;
|
|
639
657
|
}
|
|
640
|
-
function
|
|
641
|
-
|
|
642
|
-
|
|
658
|
+
function spacedStart(chars, from) {
|
|
659
|
+
let at = from;
|
|
660
|
+
while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
|
|
661
|
+
at--;
|
|
662
|
+
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
663
|
+
at--;
|
|
664
|
+
return at;
|
|
643
665
|
}
|
|
644
|
-
function
|
|
645
|
-
|
|
646
|
-
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
647
|
-
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
666
|
+
function cut(chars, from, to) {
|
|
667
|
+
return { text: [...chars.slice(0, from), ...chars.slice(to)].join(""), caret: from };
|
|
648
668
|
}
|
|
649
|
-
function
|
|
650
|
-
const
|
|
651
|
-
|
|
652
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
669
|
+
function insert(chars, at, text) {
|
|
670
|
+
const typed = [...text];
|
|
671
|
+
return { text: [...chars.slice(0, at), ...typed, ...chars.slice(at)].join(""), caret: at + typed.length };
|
|
653
672
|
}
|
|
654
|
-
function
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
...OUTPUT_OPTIONS,
|
|
668
|
-
help: { type: "boolean", short: "h", description: "show this help" }
|
|
669
|
-
};
|
|
670
|
-
var TOP_OPTIONS = {
|
|
671
|
-
...LEVEL_OPTIONS,
|
|
672
|
-
version: { type: "boolean", short: "v", description: "print the version" },
|
|
673
|
-
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
674
|
-
};
|
|
675
|
-
async function commandRows(all, colors) {
|
|
676
|
-
const commands = shown(all);
|
|
677
|
-
const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
|
|
678
|
-
const groups = new Map([["Commands:", []]]);
|
|
679
|
-
const summaries = await Promise.all(Object.values(commands).map(async ({ summary }) => resolveSummary(summary)));
|
|
680
|
-
for (const [index, [name, { group }]] of Object.entries(commands).entries()) {
|
|
681
|
-
const heading = group === undefined ? "Commands:" : `${group}:`;
|
|
682
|
-
const rows = groups.get(heading) ?? [];
|
|
683
|
-
rows.push(` ${colors.cyan(name.padEnd(width))} ${colors.dim(summaries[index])}`);
|
|
684
|
-
groups.set(heading, rows);
|
|
685
|
-
}
|
|
686
|
-
return [...groups].filter(([, rows]) => rows.length > 0).flatMap(([heading, rows], index) => [...index === 0 ? [] : [""], colors.bold(heading), ...rows]);
|
|
687
|
-
}
|
|
688
|
-
function shown(commands) {
|
|
689
|
-
return Object.fromEntries(Object.entries(commands).filter(([, { hidden }]) => hidden !== true));
|
|
673
|
+
function editLine(line, key) {
|
|
674
|
+
const { killed = "", chained = false } = line;
|
|
675
|
+
const chars = [...line.text];
|
|
676
|
+
const at = Math.min(Math.max(line.caret, 0), chars.length);
|
|
677
|
+
const edited = edit(chars, at, key, killed);
|
|
678
|
+
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
679
|
+
return line.killed === undefined ? edited : { ...edited, killed };
|
|
680
|
+
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
681
|
+
if (taken === "")
|
|
682
|
+
return { ...edited, killed, chained };
|
|
683
|
+
if (!chained)
|
|
684
|
+
return { ...edited, killed: taken, chained: true };
|
|
685
|
+
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
690
686
|
}
|
|
691
|
-
function
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
687
|
+
function edit(chars, at, key, killed) {
|
|
688
|
+
const text = chars.join("");
|
|
689
|
+
if (typeof key === "object")
|
|
690
|
+
return insert(chars, at, key.text);
|
|
691
|
+
switch (key) {
|
|
692
|
+
case "left":
|
|
693
|
+
return { text, caret: Math.max(at - 1, 0) };
|
|
694
|
+
case "right":
|
|
695
|
+
return { text, caret: Math.min(at + 1, chars.length) };
|
|
696
|
+
case "wordleft":
|
|
697
|
+
return { text, caret: wordStart(chars, at) };
|
|
698
|
+
case "wordright":
|
|
699
|
+
return { text, caret: wordEnd(chars, at) };
|
|
700
|
+
case "linestart":
|
|
701
|
+
return { text, caret: 0 };
|
|
702
|
+
case "lineend":
|
|
703
|
+
return { text, caret: chars.length };
|
|
704
|
+
case "erase":
|
|
705
|
+
return cut(chars, Math.max(at - 1, 0), at);
|
|
706
|
+
case "delete":
|
|
707
|
+
return cut(chars, at, Math.min(at + 1, chars.length));
|
|
708
|
+
case "word":
|
|
709
|
+
return cut(chars, spacedStart(chars, at), at);
|
|
710
|
+
case "killword":
|
|
711
|
+
return cut(chars, wordStart(chars, at), at);
|
|
712
|
+
case "killnext":
|
|
713
|
+
return cut(chars, at, wordEnd(chars, at));
|
|
714
|
+
case "clear":
|
|
715
|
+
return cut(chars, 0, at);
|
|
716
|
+
case "killend":
|
|
717
|
+
return cut(chars, at, chars.length);
|
|
718
|
+
case "yank":
|
|
719
|
+
return insert(chars, at, killed);
|
|
703
720
|
}
|
|
704
|
-
return argv.slice(index);
|
|
705
721
|
}
|
|
706
|
-
|
|
707
|
-
|
|
722
|
+
function visible({ text, caret }, room) {
|
|
723
|
+
const chars = [...text];
|
|
724
|
+
const at = Math.min(Math.max(caret, 0), chars.length);
|
|
725
|
+
const cells = at === chars.length ? [...chars, " "] : chars;
|
|
726
|
+
const widths = cells.map((char) => Bun.stringWidth(char));
|
|
727
|
+
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
728
|
+
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
729
|
+
let start = at;
|
|
730
|
+
let end = at + 1;
|
|
731
|
+
while (start > 0 && fits(start - 1, end))
|
|
732
|
+
start--;
|
|
733
|
+
while (end < cells.length && fits(start, end + 1))
|
|
734
|
+
end++;
|
|
735
|
+
const left = start > 0 ? "\u2026" : "";
|
|
736
|
+
const right = end < cells.length ? "\u2026" : "";
|
|
737
|
+
return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
|
|
708
738
|
}
|
|
709
|
-
|
|
710
|
-
|
|
739
|
+
var EDIT_KEYS, BACKWARD_KILLS, FORWARD_KILLS, WORD_CHARACTER, SPACE;
|
|
740
|
+
var init_line = __esm(() => {
|
|
741
|
+
EDIT_KEYS = new Set(["left", "right", "wordleft", "wordright", "linestart", "lineend", "erase", "delete", "word", "killword", "killnext", "clear", "killend", "yank"]);
|
|
742
|
+
BACKWARD_KILLS = new Set(["word", "killword", "clear"]);
|
|
743
|
+
FORWARD_KILLS = new Set(["killnext", "killend"]);
|
|
744
|
+
WORD_CHARACTER = /[\p{L}\p{N}_]/u;
|
|
745
|
+
SPACE = /\s/;
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
// ../kit/src/picker/score.ts
|
|
749
|
+
var BOUNDARY_AFTER, NONE;
|
|
750
|
+
var init_score = __esm(() => {
|
|
751
|
+
BOUNDARY_AFTER = new Set([" ", "/", "-", "_", ".", ":", "\\", "(", "[", ",", "\t"]);
|
|
752
|
+
NONE = Number.NEGATIVE_INFINITY;
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
// ../kit/src/picker/state.ts
|
|
756
|
+
function repeat(value, count) {
|
|
757
|
+
return Array.from({ length: count }).fill(value);
|
|
711
758
|
}
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
759
|
+
function parseKeys(input, paste = { active: false }, ctrls = []) {
|
|
760
|
+
const codes = new Map(ctrls.map((name) => [String.fromCharCode(name.codePointAt(name.length - 1) - 96), name]));
|
|
761
|
+
return (input.match(KEY_SEQUENCES) ?? []).flatMap((sequence) => {
|
|
762
|
+
const wheel = MOUSE.exec(sequence)?.[1];
|
|
763
|
+
if (wheel !== undefined)
|
|
764
|
+
return repeat(wheel === "64" ? "up" : "down", wheel === "64" || wheel === "65" ? WHEEL_LINES : 0);
|
|
765
|
+
const named = codes.get(sequence);
|
|
766
|
+
const key = named === undefined ? KEYS[sequence] : { ctrl: named };
|
|
767
|
+
if (sequence === PASTE_START || sequence === PASTE_END) {
|
|
768
|
+
paste.active = sequence === PASTE_START;
|
|
769
|
+
return [];
|
|
770
|
+
}
|
|
771
|
+
if (paste.active && (sequence === "\r" || sequence === `
|
|
772
|
+
`))
|
|
773
|
+
return [];
|
|
774
|
+
if (key !== undefined)
|
|
775
|
+
return [key];
|
|
776
|
+
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
777
|
+
});
|
|
721
778
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
"",
|
|
734
|
-
|
|
735
|
-
"",
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
"",
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
"",
|
|
743
|
-
|
|
744
|
-
|
|
779
|
+
var IS_CONTROL, PASTE_START = "\x1B[200~", PASTE_END = "\x1B[201~", KEY_SEQUENCES, MOUSE, WHEEL_LINES = 3, KEYS;
|
|
780
|
+
var init_state = __esm(() => {
|
|
781
|
+
init_text2();
|
|
782
|
+
init_line();
|
|
783
|
+
init_score();
|
|
784
|
+
IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
785
|
+
KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
786
|
+
MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
787
|
+
KEYS = {
|
|
788
|
+
"\x1B[A": "up",
|
|
789
|
+
"\x1BOA": "up",
|
|
790
|
+
"\x10": "up",
|
|
791
|
+
"\x1B[B": "down",
|
|
792
|
+
"\x1BOB": "down",
|
|
793
|
+
"\x0E": "down",
|
|
794
|
+
"\x1B[5~": "pageup",
|
|
795
|
+
"\x1B[6~": "pagedown",
|
|
796
|
+
"\x1B[H": "home",
|
|
797
|
+
"\x1B[1~": "home",
|
|
798
|
+
"\x1BOH": "home",
|
|
799
|
+
"\x1B[F": "end",
|
|
800
|
+
"\x1B[4~": "end",
|
|
801
|
+
"\x1BOF": "end",
|
|
802
|
+
"\r": "enter",
|
|
803
|
+
"\n": "enter",
|
|
804
|
+
"\x03": "cancel",
|
|
805
|
+
"\x1B": "cancel",
|
|
806
|
+
"\x1B[D": "left",
|
|
807
|
+
"\x1BOD": "left",
|
|
808
|
+
"\x1B[C": "right",
|
|
809
|
+
"\x1BOC": "right",
|
|
810
|
+
"\x1B[1;5D": "wordleft",
|
|
811
|
+
"\x1B[1;3D": "wordleft",
|
|
812
|
+
"\x1Bb": "wordleft",
|
|
813
|
+
"\x1B[1;5C": "wordright",
|
|
814
|
+
"\x1B[1;3C": "wordright",
|
|
815
|
+
"\x1Bf": "wordright",
|
|
816
|
+
"\x01": "linestart",
|
|
817
|
+
"\x05": "lineend",
|
|
818
|
+
"\x7F": "erase",
|
|
819
|
+
"\x1B[3~": "delete",
|
|
820
|
+
"\b": "killword",
|
|
821
|
+
"\x1B\x7F": "killword",
|
|
822
|
+
"\x1B[3;5~": "killnext",
|
|
823
|
+
"\x1Bd": "killnext",
|
|
824
|
+
"\x15": "clear",
|
|
825
|
+
"\v": "killend",
|
|
826
|
+
"\x17": "word",
|
|
827
|
+
"\x19": "yank",
|
|
828
|
+
"\x1A": "suspend",
|
|
829
|
+
"\t": "tab",
|
|
830
|
+
"\x1F": "help",
|
|
831
|
+
"\x1BOP": "help",
|
|
832
|
+
"\x1B[11~": "help"
|
|
833
|
+
};
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
// ../kit/src/redraw.ts
|
|
837
|
+
function overwrite(lines, columns) {
|
|
838
|
+
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
745
839
|
`);
|
|
746
840
|
}
|
|
747
|
-
function
|
|
748
|
-
|
|
749
|
-
const styled = takesControlCodes(process10.stderr);
|
|
750
|
-
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
751
|
-
const under = (label, text, tint) => text === undefined ? "" : `
|
|
752
|
-
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
753
|
-
console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
|
|
841
|
+
function rowsTaken(lines, columns) {
|
|
842
|
+
return lines.reduce((rows, line) => rows + Math.max(1, Math.ceil(textWidth(line) / columns)), 0);
|
|
754
843
|
}
|
|
755
|
-
|
|
756
|
-
|
|
844
|
+
var SYNC_START = "\x1B[?2026h", SYNC_END = "\x1B[?2026l";
|
|
845
|
+
var init_redraw = __esm(() => {
|
|
846
|
+
init_format();
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
// ../kit/src/prompt.ts
|
|
850
|
+
import process15 from "process";
|
|
851
|
+
function readKeys(input, paste = { active: false }) {
|
|
852
|
+
return parseKeys(input, paste).filter((key) => typeof key === "object" ? "text" in key : PROMPT_KEYS.has(key) || isEditKey(key));
|
|
757
853
|
}
|
|
758
|
-
function
|
|
759
|
-
|
|
760
|
-
return (end === -1 ? argv : argv.slice(0, end)).includes("--json");
|
|
854
|
+
function roomAfter(question, columns) {
|
|
855
|
+
return Math.max(columns - textWidth(`? ${question} `) % columns - 1, 1);
|
|
761
856
|
}
|
|
762
|
-
function
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
767
|
-
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
768
|
-
if (error instanceof Exit && error.code === 2)
|
|
769
|
-
noteUsageError(error.message);
|
|
770
|
-
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
771
|
-
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
772
|
-
return error instanceof Exit ? error.code : 1;
|
|
857
|
+
function withCaret(colors, line, room, dim = false) {
|
|
858
|
+
const { before, at, after } = visible(line, room);
|
|
859
|
+
const tone = dim ? colors.dim : (text) => text;
|
|
860
|
+
return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
|
|
773
861
|
}
|
|
774
|
-
|
|
775
|
-
const
|
|
776
|
-
let
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
return reportThrown(prefix, error);
|
|
781
|
-
}
|
|
782
|
-
const [name, ...args] = argv;
|
|
783
|
-
const fallback = level.defaultCommand === undefined ? undefined : level.commands[level.defaultCommand];
|
|
784
|
-
if (name === undefined && level.runBare && fallback !== undefined && "run" in fallback) {
|
|
785
|
-
try {
|
|
786
|
-
return await fallback.run([]);
|
|
787
|
-
} catch (error) {
|
|
788
|
-
return reportThrown(`${prefix} ${level.defaultCommand}`, error, redact, false);
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
if (name === undefined && level.path.length > 1) {
|
|
792
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process10.stderr));
|
|
793
|
-
return 2;
|
|
794
|
-
}
|
|
795
|
-
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
796
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process10.stdout));
|
|
797
|
-
return 0;
|
|
798
|
-
}
|
|
799
|
-
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
800
|
-
console.log(version);
|
|
801
|
-
return 0;
|
|
802
|
-
}
|
|
803
|
-
let command = level.commands[level.aliases?.[name] ?? name];
|
|
804
|
-
let rest = args;
|
|
805
|
-
let ran = name;
|
|
806
|
-
if (command === undefined && level.lazy.length > 0) {
|
|
807
|
-
level = await expand(level, [...level.path.slice(1), ...argv]);
|
|
808
|
-
command = level.commands[level.aliases?.[name] ?? name];
|
|
809
|
-
}
|
|
810
|
-
if (command === undefined && level.defaultCommand !== undefined) {
|
|
811
|
-
command = level.commands[level.defaultCommand];
|
|
812
|
-
rest = argv;
|
|
813
|
-
ran = level.defaultCommand;
|
|
814
|
-
}
|
|
815
|
-
if (command === undefined) {
|
|
816
|
-
const meant = closest(name, Object.keys(shown(level.commands)));
|
|
817
|
-
printError(prefix, `no command ${name}`, meant === undefined ? `run ${prefix} --help for its commands` : `did you mean ${meant}?`);
|
|
818
|
-
return 2;
|
|
819
|
-
}
|
|
820
|
-
if ("commands" in command) {
|
|
821
|
-
const { summary } = command;
|
|
822
|
-
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 });
|
|
823
|
-
}
|
|
824
|
-
try {
|
|
825
|
-
return await command.run(rest);
|
|
826
|
-
} catch (error) {
|
|
827
|
-
return reportThrown(`${prefix} ${ran}`, error, redact, wantsJson(rest));
|
|
862
|
+
function sharedStart(texts) {
|
|
863
|
+
const [first = [], ...rest] = texts.map((text) => [...text]);
|
|
864
|
+
let length = first.length;
|
|
865
|
+
for (const chars of rest) {
|
|
866
|
+
const differs = chars.findIndex((char, index) => char !== first[index]);
|
|
867
|
+
length = Math.min(length, differs === -1 ? chars.length : differs);
|
|
828
868
|
}
|
|
869
|
+
return first.slice(0, length).join("");
|
|
829
870
|
}
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
} catch (error) {
|
|
837
|
-
if (error instanceof Completing)
|
|
838
|
-
return error;
|
|
839
|
-
} finally {
|
|
840
|
-
completion.active = false;
|
|
841
|
-
}
|
|
842
|
-
return new Completing({});
|
|
871
|
+
function listed2(colors, found, columns) {
|
|
872
|
+
const shared = sharedStart(found);
|
|
873
|
+
const cut = Math.max(shared.lastIndexOf("/"), shared.lastIndexOf(" ")) + 1;
|
|
874
|
+
const names = found.slice(0, MAX_LISTED).map((each) => each.slice(cut));
|
|
875
|
+
const more = found.length > MAX_LISTED ? ` \u2026 ${found.length - MAX_LISTED} more` : "";
|
|
876
|
+
return ` ${colors.dim(truncate(names.join(" ") + more, Math.max(columns - 3, 1)))}`;
|
|
843
877
|
}
|
|
844
|
-
async function
|
|
845
|
-
|
|
878
|
+
async function input2(question, { default: fallback, mask = false, validate, history, complete, ...settings } = {}) {
|
|
879
|
+
let line = { text: "", caret: 0 };
|
|
880
|
+
let invalid;
|
|
881
|
+
let completions = [];
|
|
882
|
+
const remembered = history === undefined || mask ? undefined : history;
|
|
883
|
+
const earlier = remembered === undefined ? [] : earlierAnswers(remembered);
|
|
884
|
+
let recalled = -1;
|
|
885
|
+
let draft = line;
|
|
886
|
+
const taken = () => line.text === "" ? fallback ?? "" : line.text;
|
|
887
|
+
const shown = () => mask ? "*".repeat([...taken()].length) : taken();
|
|
888
|
+
const accepted = await ask(question, settings, (colors, state, { columns }) => {
|
|
889
|
+
if (state !== "asking")
|
|
890
|
+
return [answer(colors, question, state, shown())];
|
|
891
|
+
const typed = line.text === "" ? { text: shown(), caret: [...shown()].length } : { text: shown(), caret: line.caret };
|
|
892
|
+
return [`${colors.cyan("?")} ${question} ${withCaret(colors, typed, roomAfter(question, columns), line.text === "")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`], ...completions.length > 1 ? [listed2(colors, completions, columns)] : []];
|
|
893
|
+
}, (key) => {
|
|
894
|
+
if (key === "cancel")
|
|
895
|
+
return "cancel";
|
|
896
|
+
invalid = undefined;
|
|
897
|
+
completions = [];
|
|
898
|
+
if (line.chained === true && endsKills(key))
|
|
899
|
+
line = { ...line, chained: false };
|
|
900
|
+
if (key === "tab") {
|
|
901
|
+
const chars = [...line.text];
|
|
902
|
+
const before = chars.slice(0, line.caret).join("");
|
|
903
|
+
const found = complete?.(before) ?? [];
|
|
904
|
+
const filled = sharedStart(found);
|
|
905
|
+
if ([...filled].length > [...before].length)
|
|
906
|
+
line = { ...line, text: filled + chars.slice(line.caret).join(""), caret: [...filled].length };
|
|
907
|
+
else
|
|
908
|
+
completions = found;
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
if (key === "enter") {
|
|
912
|
+
invalid = validate?.(taken());
|
|
913
|
+
return invalid === undefined ? "enter" : undefined;
|
|
914
|
+
}
|
|
915
|
+
if (key === "up" || key === "down") {
|
|
916
|
+
const to = Math.min(Math.max(recalled + (key === "up" ? 1 : -1), -1), earlier.length - 1);
|
|
917
|
+
if (recalled === -1)
|
|
918
|
+
draft = line;
|
|
919
|
+
recalled = to;
|
|
920
|
+
const shown = to === -1 ? draft : { text: earlier[to], caret: [...earlier[to]].length };
|
|
921
|
+
line = { ...shown, killed: line.killed ?? "" };
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
const edit = { home: "linestart", end: "lineend" }[key] ?? key;
|
|
925
|
+
if (typeof edit === "object" || isEditKey(edit))
|
|
926
|
+
line = editLine(line, edit);
|
|
927
|
+
return;
|
|
928
|
+
});
|
|
929
|
+
if (!accepted)
|
|
930
|
+
return;
|
|
931
|
+
if (remembered !== undefined && taken() !== "")
|
|
932
|
+
rememberAnswer(remembered, taken());
|
|
933
|
+
return taken();
|
|
846
934
|
}
|
|
847
|
-
function
|
|
848
|
-
return
|
|
935
|
+
function answer(colors, question, state, picked) {
|
|
936
|
+
return state === "enter" ? `${colors.green("\u2713")} ${question} ${colors.cyan(picked)}` : `${colors.red("\u2717")} ${question} ${colors.dim("cancelled")}`;
|
|
849
937
|
}
|
|
850
|
-
function
|
|
851
|
-
const
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
938
|
+
async function ask(question, { hint, terminal = process15 }, render, press) {
|
|
939
|
+
const { stdin, stderr } = terminal;
|
|
940
|
+
if (!isInteractive(terminal))
|
|
941
|
+
fail(`cannot ask "${question}" off a terminal`, 2, hint);
|
|
942
|
+
const colors = paint(stderr);
|
|
943
|
+
let current = "asking";
|
|
944
|
+
let outcome;
|
|
945
|
+
const columns = () => stderr.columns || 80;
|
|
946
|
+
const draw = (state, last = false) => {
|
|
947
|
+
const frame = render(colors, state, { columns: columns(), rows: stderr.rows || 24 });
|
|
948
|
+
const rows = rowsTaken(frame, columns());
|
|
949
|
+
stderr.write(`${SYNC_START}\r${overwrite(frame, columns())}\x1B[0J${last || rows < 2 ? "" : `\x1B[${rows - 1}A`}${last ? "" : "\r"}${SYNC_END}`);
|
|
950
|
+
current = state;
|
|
951
|
+
};
|
|
952
|
+
const redraw = () => draw(current);
|
|
953
|
+
const paste = { active: false };
|
|
954
|
+
const stop = terminal.stop ?? (terminal === process15 ? stopJob : undefined);
|
|
955
|
+
const suspend = () => {
|
|
956
|
+
if (stop === undefined)
|
|
957
|
+
return;
|
|
958
|
+
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
959
|
+
stdin.setRawMode(false);
|
|
960
|
+
stop();
|
|
961
|
+
stdin.setRawMode(true);
|
|
962
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
963
|
+
};
|
|
964
|
+
try {
|
|
965
|
+
stderr.on?.("resize", redraw);
|
|
966
|
+
stdin.setRawMode(true);
|
|
967
|
+
stdin.resume();
|
|
968
|
+
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
969
|
+
draw("asking");
|
|
970
|
+
return await new Promise((resolve) => {
|
|
971
|
+
function onData(data) {
|
|
972
|
+
for (const key of readKeys(data.toString(), paste)) {
|
|
973
|
+
if (key === "suspend") {
|
|
974
|
+
suspend();
|
|
975
|
+
continue;
|
|
976
|
+
}
|
|
977
|
+
const pressed = press(key);
|
|
978
|
+
if (pressed !== undefined) {
|
|
979
|
+
settle(pressed);
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
draw("asking");
|
|
984
|
+
}
|
|
985
|
+
function onEnd() {
|
|
986
|
+
settle("cancel");
|
|
987
|
+
}
|
|
988
|
+
function settle(settled) {
|
|
989
|
+
outcome = settled;
|
|
990
|
+
stdin.off("data", onData);
|
|
991
|
+
stdin.off("end", onEnd);
|
|
992
|
+
resolve(settled === "enter");
|
|
993
|
+
}
|
|
994
|
+
stdin.on("data", onData);
|
|
995
|
+
stdin.on("end", onEnd);
|
|
996
|
+
});
|
|
997
|
+
} finally {
|
|
998
|
+
stderr.off?.("resize", redraw);
|
|
999
|
+
draw(outcome ?? "cancel", true);
|
|
1000
|
+
stderr.write(`
|
|
1001
|
+
\x1B[?25h\x1B[?2004l`);
|
|
1002
|
+
stdin.setRawMode(false);
|
|
1003
|
+
stdin.pause();
|
|
865
1004
|
}
|
|
866
|
-
const last = positionals.at(-1);
|
|
867
|
-
if (typed.length < positionals.length)
|
|
868
|
-
return { name: positionals[typed.length], typed };
|
|
869
|
-
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
870
1005
|
}
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
1006
|
+
var PROMPT_KEYS, MAX_LISTED = 12;
|
|
1007
|
+
var init_prompt = __esm(() => {
|
|
1008
|
+
init_answers();
|
|
1009
|
+
init_args();
|
|
1010
|
+
init_format();
|
|
1011
|
+
init_job();
|
|
1012
|
+
init_mode();
|
|
1013
|
+
init_line();
|
|
1014
|
+
init_state();
|
|
1015
|
+
init_redraw();
|
|
1016
|
+
init_style();
|
|
1017
|
+
PROMPT_KEYS = new Set(["up", "down", "pageup", "pagedown", "home", "end", "enter", "cancel", "suspend", "tab"]);
|
|
1018
|
+
});
|
|
1019
|
+
|
|
1020
|
+
// src/cli.ts
|
|
1021
|
+
import process16 from "process";
|
|
1022
|
+
|
|
1023
|
+
// ../kit/src/index.ts
|
|
1024
|
+
init_args();
|
|
1025
|
+
|
|
1026
|
+
// ../kit/src/argv.ts
|
|
1027
|
+
import { readFileSync, realpathSync } from "fs";
|
|
1028
|
+
import { resolve } from "path";
|
|
1029
|
+
import process7 from "process";
|
|
1030
|
+
function commandLine() {
|
|
1031
|
+
try {
|
|
1032
|
+
return readFileSync("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
1033
|
+
} catch {
|
|
1034
|
+
return;
|
|
881
1035
|
}
|
|
882
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
883
|
-
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
884
1036
|
}
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
if (listing || command === undefined) {
|
|
891
|
-
({ commands, aliases } = await expand(scope, [...before, ...words]));
|
|
892
|
-
command = commands[aliases?.[word] ?? word];
|
|
893
|
-
}
|
|
894
|
-
if (listing) {
|
|
895
|
-
const own = await Promise.all(Object.entries(shown(commands)).map(async ([name, { summary }]) => `${name} ${await resolveSummary(summary)}`));
|
|
896
|
-
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
897
|
-
const values = fallback !== undefined && "run" in fallback ? await leafCandidates(fallback.run, [word]) : [];
|
|
898
|
-
const valueOf = (line) => line.slice(0, line.includes("\t") ? line.indexOf("\t") : undefined);
|
|
899
|
-
return [...own, ...values.filter((line) => line !== FILES && !(valueOf(line) in commands))];
|
|
900
|
-
}
|
|
901
|
-
if (command === undefined) {
|
|
902
|
-
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
903
|
-
return fallback !== undefined && "run" in fallback ? leafCandidates(fallback.run, words) : [];
|
|
1037
|
+
function realPath(word) {
|
|
1038
|
+
try {
|
|
1039
|
+
return realpathSync(resolve(word));
|
|
1040
|
+
} catch {
|
|
1041
|
+
return;
|
|
904
1042
|
}
|
|
905
|
-
return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
|
|
906
1043
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
1044
|
+
function scriptArgs(argv = process7.argv.slice(2), cmdline = commandLine(), script = process7.argv[1]) {
|
|
1045
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
1046
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve(word) === script || realPath(word) === target));
|
|
1047
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
1048
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
910
1049
|
}
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
1050
|
+
// ../kit/src/chart.ts
|
|
1051
|
+
init_format();
|
|
1052
|
+
init_mode();
|
|
1053
|
+
init_style();
|
|
1054
|
+
init_theme();
|
|
1055
|
+
// ../kit/src/ci.ts
|
|
1056
|
+
init_args();
|
|
1057
|
+
init_format();
|
|
1058
|
+
|
|
1059
|
+
// ../kit/src/progress.ts
|
|
1060
|
+
init_format();
|
|
1061
|
+
|
|
1062
|
+
// ../kit/src/process.ts
|
|
1063
|
+
var CLIPBOARDS = [["wl-copy"], ["xclip", "-selection", "clipboard"], ["xsel", "--clipboard", "--input"], ["pbcopy"], ["clip.exe"]];
|
|
1064
|
+
async function copyText(text, which = Bun.which) {
|
|
1065
|
+
for (const [command, ...args] of CLIPBOARDS) {
|
|
1066
|
+
const found = which(command);
|
|
1067
|
+
if (found !== null && await pipeInto([found, ...args], text))
|
|
1068
|
+
return true;
|
|
916
1069
|
}
|
|
917
|
-
|
|
918
|
-
return 0;
|
|
919
|
-
}
|
|
920
|
-
async function printCandidates(found) {
|
|
921
|
-
for (const line of await found)
|
|
922
|
-
console.log(line);
|
|
923
|
-
return 0;
|
|
1070
|
+
return false;
|
|
924
1071
|
}
|
|
925
|
-
function
|
|
926
|
-
let resolved = entry;
|
|
1072
|
+
async function pipeInto(argv, text) {
|
|
927
1073
|
try {
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
const { version } = JSON.parse(readFileSync2(join2(dir, "package.json"), "utf8"));
|
|
933
|
-
if (typeof version === "string")
|
|
934
|
-
return version;
|
|
935
|
-
} catch {}
|
|
936
|
-
if (dirname2(dir) === dir)
|
|
937
|
-
return "0.0.0";
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
async function runCli(cli, argv = scriptArgs()) {
|
|
941
|
-
const version = cli.version ?? packageVersion();
|
|
942
|
-
if (argv[0] === COMPLETE)
|
|
943
|
-
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
944
|
-
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
945
|
-
return printCompletionScript(cli.name, flagValue(argv));
|
|
946
|
-
const started = performance.now();
|
|
947
|
-
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 });
|
|
948
|
-
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
|
949
|
-
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
950
|
-
if (cli.usage !== false) {
|
|
951
|
-
try {
|
|
952
|
-
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
953
|
-
} catch {}
|
|
954
|
-
}
|
|
955
|
-
return code;
|
|
956
|
-
}
|
|
957
|
-
function commandPath(scope, argv) {
|
|
958
|
-
const path = [];
|
|
959
|
-
let level = scope;
|
|
960
|
-
for (const word of argv.filter((each) => !each.startsWith("-"))) {
|
|
961
|
-
const name = level.aliases !== undefined && Object.hasOwn(level.aliases, word) ? level.aliases[word] ?? word : word;
|
|
962
|
-
const command = Object.hasOwn(level.commands, name) ? level.commands[name] : undefined;
|
|
963
|
-
if (command === undefined)
|
|
964
|
-
break;
|
|
965
|
-
path.push(word);
|
|
966
|
-
if (!("commands" in command))
|
|
967
|
-
break;
|
|
968
|
-
level = scopeOf(command.commands, command.extraCommands, command.aliases);
|
|
1074
|
+
const copy = Bun.spawn(argv, { stdin: new Blob([text]), stdout: "ignore", stderr: "ignore" });
|
|
1075
|
+
return await copy.exited === 0;
|
|
1076
|
+
} catch {
|
|
1077
|
+
return false;
|
|
969
1078
|
}
|
|
970
|
-
return path.length === 0 ? undefined : path.join(" ");
|
|
971
1079
|
}
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
1080
|
+
|
|
1081
|
+
// ../kit/src/progress.ts
|
|
1082
|
+
init_style();
|
|
1083
|
+
init_theme();
|
|
1084
|
+
var ESC = String.fromCharCode(27);
|
|
1085
|
+
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
1086
|
+
var RESET_STYLE = `${ESC}[0m`;
|
|
1087
|
+
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
1088
|
+
|
|
1089
|
+
// ../kit/src/ci.ts
|
|
1090
|
+
init_style();
|
|
1091
|
+
|
|
1092
|
+
// ../kit/src/tool.ts
|
|
1093
|
+
init_format();
|
|
1094
|
+
// ../kit/src/cli.ts
|
|
1095
|
+
init_args();
|
|
1096
|
+
import { readFileSync as readFileSync2, realpathSync as realpathSync2 } from "fs";
|
|
1097
|
+
import { dirname as dirname2, join as join2 } from "path";
|
|
975
1098
|
import process11 from "process";
|
|
976
|
-
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
977
|
-
function cacheFolder({ home = homedir2(), env = process11.env } = {}) {
|
|
978
|
-
return env.XDG_CACHE_HOME ?? join3(home, ".cache");
|
|
979
|
-
}
|
|
980
|
-
// ../kit/src/secrets.ts
|
|
981
|
-
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
982
|
-
// ../kit/src/sessions.ts
|
|
983
|
-
var {Glob } = globalThis.Bun;
|
|
984
|
-
var SESSION_FILES = new Glob("*.json");
|
|
985
|
-
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
986
|
-
// ../kit/src/prompt.ts
|
|
987
|
-
import process14 from "process";
|
|
988
1099
|
|
|
989
|
-
// ../kit/src/
|
|
990
|
-
import
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
1100
|
+
// ../kit/src/askpass.ts
|
|
1101
|
+
import process8 from "process";
|
|
1102
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
1103
|
+
async function askpassClient(argv) {
|
|
1104
|
+
const socketPath = process8.env[SOCKET_VARIABLE];
|
|
1105
|
+
if (socketPath === undefined)
|
|
1106
|
+
return;
|
|
1107
|
+
const request = { prompt: argv[0] ?? "", ...process8.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
1108
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
1109
|
+
let received = "";
|
|
997
1110
|
try {
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1111
|
+
await Bun.connect({
|
|
1112
|
+
unix: socketPath,
|
|
1113
|
+
socket: {
|
|
1114
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
1115
|
+
`),
|
|
1116
|
+
data: (_, chunk) => {
|
|
1117
|
+
received += chunk.toString();
|
|
1118
|
+
},
|
|
1119
|
+
close: () => resolve(received),
|
|
1120
|
+
error: () => resolve("")
|
|
1121
|
+
}
|
|
1122
|
+
});
|
|
1002
1123
|
} catch {
|
|
1003
|
-
return
|
|
1124
|
+
return 1;
|
|
1004
1125
|
}
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
} catch {}
|
|
1126
|
+
const reply = await promise;
|
|
1127
|
+
if (reply === "")
|
|
1128
|
+
return 1;
|
|
1129
|
+
const { answer } = JSON.parse(reply);
|
|
1130
|
+
if (request.notice === true)
|
|
1131
|
+
return 0;
|
|
1132
|
+
if (answer === undefined)
|
|
1133
|
+
return 1;
|
|
1134
|
+
process8.stdout.write(`${answer}
|
|
1135
|
+
`);
|
|
1136
|
+
return 0;
|
|
1017
1137
|
}
|
|
1018
1138
|
|
|
1019
|
-
// ../kit/src/
|
|
1020
|
-
|
|
1021
|
-
function
|
|
1022
|
-
|
|
1139
|
+
// ../kit/src/completions.ts
|
|
1140
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
1141
|
+
var 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'
|
|
1142
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
1143
|
+
set -l current (commandline -ct)
|
|
1144
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
1145
|
+
if test "$line" = __files__
|
|
1146
|
+
__fish_complete_path $current
|
|
1147
|
+
else
|
|
1148
|
+
echo $line
|
|
1149
|
+
end
|
|
1150
|
+
end
|
|
1151
|
+
end`;
|
|
1152
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1153
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
1154
|
+
local -a lines
|
|
1155
|
+
COMPREPLY=()
|
|
1156
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
1157
|
+
for line in "\${lines[@]}"; do
|
|
1158
|
+
if [[ $line == __files__ ]]; then
|
|
1159
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
1160
|
+
else
|
|
1161
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
1162
|
+
fi
|
|
1163
|
+
done
|
|
1164
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
1165
|
+
}`;
|
|
1166
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
1167
|
+
local line
|
|
1168
|
+
local -a described plain
|
|
1169
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
1170
|
+
if [[ $line == __files__ ]]; then
|
|
1171
|
+
_files
|
|
1172
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
1173
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
1174
|
+
else
|
|
1175
|
+
plain+=("$line")
|
|
1176
|
+
fi
|
|
1177
|
+
done
|
|
1178
|
+
(( \${#described} )) && _describe -V value described
|
|
1179
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
1180
|
+
return 0
|
|
1181
|
+
}`;
|
|
1182
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
1183
|
+
if (shell === "fish")
|
|
1184
|
+
return `${header}
|
|
1185
|
+
${FISH_FUNCTION}
|
|
1186
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
1187
|
+
`).join("")}`;
|
|
1188
|
+
if (shell === "bash")
|
|
1189
|
+
return `${header}
|
|
1190
|
+
${BASH_FUNCTION}
|
|
1191
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
1192
|
+
`;
|
|
1193
|
+
return `${header}
|
|
1194
|
+
${ZSH_FUNCTION}
|
|
1195
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
1196
|
+
`;
|
|
1023
1197
|
}
|
|
1024
1198
|
|
|
1025
|
-
// ../kit/src/
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1199
|
+
// ../kit/src/notify.ts
|
|
1200
|
+
init_format();
|
|
1201
|
+
init_mode();
|
|
1202
|
+
import process9 from "process";
|
|
1203
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
1204
|
+
var CANCELLED = 130;
|
|
1205
|
+
function base64(text) {
|
|
1206
|
+
return Buffer.from(text).toString("base64");
|
|
1031
1207
|
}
|
|
1032
|
-
function
|
|
1033
|
-
|
|
1208
|
+
function notification(title, body, env = process9.env) {
|
|
1209
|
+
const id = `kit${process9.pid}`;
|
|
1210
|
+
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\\`];
|
|
1211
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
1034
1212
|
}
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1213
|
+
function notifyEnd(command, code, ms, { stream = process9.stderr, env = process9.env } = {}) {
|
|
1214
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
1215
|
+
return;
|
|
1216
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
1039
1217
|
}
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1218
|
+
|
|
1219
|
+
// ../kit/src/cli.ts
|
|
1220
|
+
init_style();
|
|
1221
|
+
init_text2();
|
|
1222
|
+
|
|
1223
|
+
// ../kit/src/usage.ts
|
|
1224
|
+
import { appendFileSync, mkdirSync } from "fs";
|
|
1225
|
+
import { homedir } from "os";
|
|
1226
|
+
import { dirname, isAbsolute, join } from "path";
|
|
1227
|
+
import process10 from "process";
|
|
1228
|
+
|
|
1229
|
+
// ../kit/src/logs.ts
|
|
1230
|
+
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
1231
|
+
var CLI_FOLDER = "kaynooo-cli";
|
|
1232
|
+
|
|
1233
|
+
// ../kit/src/usage.ts
|
|
1234
|
+
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
1235
|
+
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
1236
|
+
var LONGEST_NAME = 40;
|
|
1237
|
+
var usageError;
|
|
1238
|
+
function noteUsageError(message) {
|
|
1239
|
+
usageError = message;
|
|
1047
1240
|
}
|
|
1048
|
-
function
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
at++;
|
|
1052
|
-
while (at < chars.length && isWord(chars[at]))
|
|
1053
|
-
at++;
|
|
1054
|
-
return at;
|
|
1241
|
+
function stateHome(env = process10.env) {
|
|
1242
|
+
const dir = env.XDG_STATE_HOME;
|
|
1243
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
|
|
1055
1244
|
}
|
|
1056
|
-
function
|
|
1057
|
-
|
|
1058
|
-
while (at > 0 && SPACE.test(chars[at - 1] ?? ""))
|
|
1059
|
-
at--;
|
|
1060
|
-
while (at > 0 && !SPACE.test(chars[at - 1] ?? ""))
|
|
1061
|
-
at--;
|
|
1062
|
-
return at;
|
|
1245
|
+
function usagePath(env = process10.env) {
|
|
1246
|
+
return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
1063
1247
|
}
|
|
1064
|
-
function
|
|
1065
|
-
|
|
1248
|
+
function usageRecorded(env = process10.env) {
|
|
1249
|
+
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
1250
|
+
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
1066
1251
|
}
|
|
1067
|
-
function
|
|
1068
|
-
const
|
|
1069
|
-
|
|
1252
|
+
function flagNames(argv) {
|
|
1253
|
+
const end = argv.indexOf("--");
|
|
1254
|
+
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
1255
|
+
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
1070
1256
|
}
|
|
1071
|
-
function
|
|
1072
|
-
const
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
const edited = edit(chars, at, key, killed);
|
|
1076
|
-
if (typeof key === "object" || !BACKWARD_KILLS.has(key) && !FORWARD_KILLS.has(key))
|
|
1077
|
-
return line.killed === undefined ? edited : { ...edited, killed };
|
|
1078
|
-
const taken = chars.slice(edited.caret, edited.caret + chars.length - [...edited.text].length).join("");
|
|
1079
|
-
if (taken === "")
|
|
1080
|
-
return { ...edited, killed, chained };
|
|
1081
|
-
if (!chained)
|
|
1082
|
-
return { ...edited, killed: taken, chained: true };
|
|
1083
|
-
return { ...edited, killed: BACKWARD_KILLS.has(key) ? taken + killed : killed + taken, chained: true };
|
|
1257
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
1258
|
+
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
1259
|
+
usageError = undefined;
|
|
1260
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
1084
1261
|
}
|
|
1085
|
-
function
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
case "wordleft":
|
|
1095
|
-
return { text, caret: wordStart(chars, at) };
|
|
1096
|
-
case "wordright":
|
|
1097
|
-
return { text, caret: wordEnd(chars, at) };
|
|
1098
|
-
case "linestart":
|
|
1099
|
-
return { text, caret: 0 };
|
|
1100
|
-
case "lineend":
|
|
1101
|
-
return { text, caret: chars.length };
|
|
1102
|
-
case "erase":
|
|
1103
|
-
return cut(chars, Math.max(at - 1, 0), at);
|
|
1104
|
-
case "delete":
|
|
1105
|
-
return cut(chars, at, Math.min(at + 1, chars.length));
|
|
1106
|
-
case "word":
|
|
1107
|
-
return cut(chars, spacedStart(chars, at), at);
|
|
1108
|
-
case "killword":
|
|
1109
|
-
return cut(chars, wordStart(chars, at), at);
|
|
1110
|
-
case "killnext":
|
|
1111
|
-
return cut(chars, at, wordEnd(chars, at));
|
|
1112
|
-
case "clear":
|
|
1113
|
-
return cut(chars, 0, at);
|
|
1114
|
-
case "killend":
|
|
1115
|
-
return cut(chars, at, chars.length);
|
|
1116
|
-
case "yank":
|
|
1117
|
-
return insert(chars, at, killed);
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
function visible({ text, caret }, room) {
|
|
1121
|
-
const chars = [...text];
|
|
1122
|
-
const at = Math.min(Math.max(caret, 0), chars.length);
|
|
1123
|
-
const cells = at === chars.length ? [...chars, " "] : chars;
|
|
1124
|
-
const widths = cells.map((char) => Bun.stringWidth(char));
|
|
1125
|
-
const width = (from, to) => widths.slice(from, to).reduce((sum, size) => sum + size, 0);
|
|
1126
|
-
const fits = (from, to) => (from > 0 ? 1 : 0) + width(from, to) + (to < cells.length ? 1 : 0) <= room;
|
|
1127
|
-
let start = at;
|
|
1128
|
-
let end = at + 1;
|
|
1129
|
-
while (start > 0 && fits(start - 1, end))
|
|
1130
|
-
start--;
|
|
1131
|
-
while (end < cells.length && fits(start, end + 1))
|
|
1132
|
-
end++;
|
|
1133
|
-
const left = start > 0 ? "\u2026" : "";
|
|
1134
|
-
const right = end < cells.length ? "\u2026" : "";
|
|
1135
|
-
return { before: left + chars.slice(start, at).join(""), at: chars[at], after: chars.slice(at + 1, end).join("") + right, column: left.length + width(start, at) };
|
|
1262
|
+
function recordUsage(entry, env = process10.env) {
|
|
1263
|
+
if (!usageRecorded(env))
|
|
1264
|
+
return;
|
|
1265
|
+
try {
|
|
1266
|
+
const path = usagePath(env);
|
|
1267
|
+
mkdirSync(dirname(path), { recursive: true, mode: 448 });
|
|
1268
|
+
appendFileSync(path, `${JSON.stringify(entry)}
|
|
1269
|
+
`, { mode: 384 });
|
|
1270
|
+
} catch {}
|
|
1136
1271
|
}
|
|
1137
1272
|
|
|
1138
|
-
// ../kit/src/
|
|
1139
|
-
var
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
// ../kit/src/picker/state.ts
|
|
1143
|
-
var IS_CONTROL = /[\x00-\x1F\x7F-\x9F]/;
|
|
1144
|
-
var PASTE_START = "\x1B[200~";
|
|
1145
|
-
var PASTE_END = "\x1B[201~";
|
|
1146
|
-
var KEY_SEQUENCES = /\x1B\[<[0-9;]*[A-Za-z]|\x1B\[[0-9;]*[A-Z~]|\x1BO[A-Z]|\x1B[\s\S]|[\s\S]/gu;
|
|
1147
|
-
var MOUSE = /^\x1B\[<(\d+);\d+;\d+[a-z]$/i;
|
|
1148
|
-
var WHEEL_LINES = 3;
|
|
1149
|
-
var KEYS = {
|
|
1150
|
-
"\x1B[A": "up",
|
|
1151
|
-
"\x1BOA": "up",
|
|
1152
|
-
"\x10": "up",
|
|
1153
|
-
"\x1B[B": "down",
|
|
1154
|
-
"\x1BOB": "down",
|
|
1155
|
-
"\x0E": "down",
|
|
1156
|
-
"\x1B[5~": "pageup",
|
|
1157
|
-
"\x1B[6~": "pagedown",
|
|
1158
|
-
"\x1B[H": "home",
|
|
1159
|
-
"\x1B[1~": "home",
|
|
1160
|
-
"\x1BOH": "home",
|
|
1161
|
-
"\x1B[F": "end",
|
|
1162
|
-
"\x1B[4~": "end",
|
|
1163
|
-
"\x1BOF": "end",
|
|
1164
|
-
"\r": "enter",
|
|
1165
|
-
"\n": "enter",
|
|
1166
|
-
"\x03": "cancel",
|
|
1167
|
-
"\x1B": "cancel",
|
|
1168
|
-
"\x1B[D": "left",
|
|
1169
|
-
"\x1BOD": "left",
|
|
1170
|
-
"\x1B[C": "right",
|
|
1171
|
-
"\x1BOC": "right",
|
|
1172
|
-
"\x1B[1;5D": "wordleft",
|
|
1173
|
-
"\x1B[1;3D": "wordleft",
|
|
1174
|
-
"\x1Bb": "wordleft",
|
|
1175
|
-
"\x1B[1;5C": "wordright",
|
|
1176
|
-
"\x1B[1;3C": "wordright",
|
|
1177
|
-
"\x1Bf": "wordright",
|
|
1178
|
-
"\x01": "linestart",
|
|
1179
|
-
"\x05": "lineend",
|
|
1180
|
-
"\x7F": "erase",
|
|
1181
|
-
"\x1B[3~": "delete",
|
|
1182
|
-
"\b": "killword",
|
|
1183
|
-
"\x1B\x7F": "killword",
|
|
1184
|
-
"\x1B[3;5~": "killnext",
|
|
1185
|
-
"\x1Bd": "killnext",
|
|
1186
|
-
"\x15": "clear",
|
|
1187
|
-
"\v": "killend",
|
|
1188
|
-
"\x17": "word",
|
|
1189
|
-
"\x19": "yank",
|
|
1190
|
-
"\x1A": "suspend",
|
|
1191
|
-
"\t": "tab",
|
|
1192
|
-
"\x1F": "help",
|
|
1193
|
-
"\x1BOP": "help",
|
|
1194
|
-
"\x1B[11~": "help"
|
|
1273
|
+
// ../kit/src/cli.ts
|
|
1274
|
+
var LEVEL_OPTIONS = {
|
|
1275
|
+
...OUTPUT_OPTIONS,
|
|
1276
|
+
help: { type: "boolean", short: "h", description: "show this help" }
|
|
1195
1277
|
};
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
return [];
|
|
1214
|
-
if (key !== undefined)
|
|
1215
|
-
return [key];
|
|
1216
|
-
return IS_CONTROL.test(sequence) || sequence.startsWith("\x1B") ? [] : [{ text: sequence }];
|
|
1217
|
-
});
|
|
1218
|
-
}
|
|
1219
|
-
|
|
1220
|
-
// ../kit/src/redraw.ts
|
|
1221
|
-
var SYNC_START = "\x1B[?2026h";
|
|
1222
|
-
var SYNC_END = "\x1B[?2026l";
|
|
1223
|
-
function overwrite(lines, columns) {
|
|
1224
|
-
return lines.map((line) => textWidth(line) % columns === 0 ? `\x1B[2K${line}` : `${line}\x1B[K`).join(`
|
|
1225
|
-
`);
|
|
1278
|
+
var TOP_OPTIONS = {
|
|
1279
|
+
...LEVEL_OPTIONS,
|
|
1280
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
1281
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
1282
|
+
};
|
|
1283
|
+
async function commandRows(all, colors) {
|
|
1284
|
+
const commands = shown(all);
|
|
1285
|
+
const width = Math.max(0, ...Object.keys(commands).map((name) => name.length));
|
|
1286
|
+
const groups = new Map([["Commands:", []]]);
|
|
1287
|
+
const summaries = await Promise.all(Object.values(commands).map(async ({ summary }) => resolveSummary(summary)));
|
|
1288
|
+
for (const [index, [name, { group }]] of Object.entries(commands).entries()) {
|
|
1289
|
+
const heading = group === undefined ? "Commands:" : `${group}:`;
|
|
1290
|
+
const rows = groups.get(heading) ?? [];
|
|
1291
|
+
rows.push(` ${colors.cyan(name.padEnd(width))} ${colors.dim(summaries[index])}`);
|
|
1292
|
+
groups.set(heading, rows);
|
|
1293
|
+
}
|
|
1294
|
+
return [...groups].filter(([, rows]) => rows.length > 0).flatMap(([heading, rows], index) => [...index === 0 ? [] : [""], colors.bold(heading), ...rows]);
|
|
1226
1295
|
}
|
|
1227
|
-
function
|
|
1228
|
-
return
|
|
1296
|
+
function shown(commands) {
|
|
1297
|
+
return Object.fromEntries(Object.entries(commands).filter(([, { hidden }]) => hidden !== true));
|
|
1229
1298
|
}
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1299
|
+
function takeOutputFlags(argv) {
|
|
1300
|
+
let index = 0;
|
|
1301
|
+
for (;index < argv.length; index++) {
|
|
1302
|
+
const word = argv[index];
|
|
1303
|
+
if (word === "--plain")
|
|
1304
|
+
applyOutput(undefined, true);
|
|
1305
|
+
else if (word.startsWith("--color="))
|
|
1306
|
+
applyOutput(word.slice("--color=".length), undefined);
|
|
1307
|
+
else if (word === "--color" && argv[index + 1] !== undefined)
|
|
1308
|
+
applyOutput(argv[++index], undefined);
|
|
1309
|
+
else
|
|
1310
|
+
break;
|
|
1311
|
+
}
|
|
1312
|
+
return argv.slice(index);
|
|
1236
1313
|
}
|
|
1237
|
-
function
|
|
1238
|
-
return
|
|
1314
|
+
async function resolveSummary(summary) {
|
|
1315
|
+
return typeof summary === "string" ? summary : summary();
|
|
1239
1316
|
}
|
|
1240
|
-
function
|
|
1241
|
-
|
|
1242
|
-
const tone = dim ? colors.dim : (text) => text;
|
|
1243
|
-
return `${tone(before)}${at === undefined ? colors.dim("\u2588") : colors.inverse(at)}${tone(after)}`;
|
|
1317
|
+
function scopeOf(commands, extra, aliases) {
|
|
1318
|
+
return { commands: typeof commands === "function" ? {} : commands, lazy: [...typeof commands === "function" ? [commands] : [], ...extra === undefined ? [] : [extra]], aliases };
|
|
1244
1319
|
}
|
|
1245
|
-
function
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1320
|
+
async function expand(scope, words) {
|
|
1321
|
+
if (scope.lazy.length === 0)
|
|
1322
|
+
return scope;
|
|
1323
|
+
const commands = { ...scope.commands };
|
|
1324
|
+
for (const added of await Promise.all(scope.lazy.map(async (lazy) => lazy(words)))) {
|
|
1325
|
+
for (const [name, command] of Object.entries(added))
|
|
1326
|
+
commands[name] ??= command;
|
|
1251
1327
|
}
|
|
1252
|
-
return
|
|
1328
|
+
return { ...scope, commands, lazy: [] };
|
|
1253
1329
|
}
|
|
1254
|
-
function
|
|
1255
|
-
const
|
|
1256
|
-
const
|
|
1257
|
-
const
|
|
1258
|
-
|
|
1259
|
-
|
|
1330
|
+
async function help2({ path, header, summary: lazySummary, commands, defaultCommand, examples, replaces }, stream) {
|
|
1331
|
+
const colors = paint(stream);
|
|
1332
|
+
const prefix = path.join(" ");
|
|
1333
|
+
const summary = await resolveSummary(lazySummary);
|
|
1334
|
+
if (wantsHelpJson())
|
|
1335
|
+
return JSON.stringify(description(`${prefix} <command> [options]: ${summary}`, { examples, replaces }));
|
|
1336
|
+
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
1337
|
+
const options = fallback !== undefined && "run" in fallback ? await optionsOf(fallback.run) : undefined;
|
|
1338
|
+
const own = Object.entries(options ?? {}).filter(([name]) => !(name in TOP_OPTIONS));
|
|
1339
|
+
return [
|
|
1340
|
+
header(colors, summary),
|
|
1341
|
+
"",
|
|
1342
|
+
usageLine(`${prefix} ${defaultCommand === undefined ? colors.cyan("<command>") : `[${colors.cyan("<command>")}]`} [options]`, colors),
|
|
1343
|
+
"",
|
|
1344
|
+
...await commandRows(commands, colors),
|
|
1345
|
+
...own.length === 0 ? [] : ["", `${colors.bold(`Options of ${defaultCommand}:`)} ${colors.dim("the command run when none is named")}`, ...optionRows(Object.fromEntries(own), colors)],
|
|
1346
|
+
"",
|
|
1347
|
+
colors.bold("Options:"),
|
|
1348
|
+
...optionRows(path.length === 1 ? TOP_OPTIONS : LEVEL_OPTIONS, colors),
|
|
1349
|
+
...exampleRows(examples ?? [], colors),
|
|
1350
|
+
"",
|
|
1351
|
+
`${colors.dim("Run")} ${prefix} ${colors.cyan("<command>")} --help ${colors.dim("for its options.")}`
|
|
1352
|
+
].join(`
|
|
1353
|
+
`);
|
|
1260
1354
|
}
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
const
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
let draft = line;
|
|
1269
|
-
const taken = () => line.text === "" ? fallback ?? "" : line.text;
|
|
1270
|
-
const shown = () => mask ? "*".repeat([...taken()].length) : taken();
|
|
1271
|
-
const accepted = await ask(question, settings, (colors, state, { columns }) => {
|
|
1272
|
-
if (state !== "asking")
|
|
1273
|
-
return [answer(colors, question, state, shown())];
|
|
1274
|
-
const typed = line.text === "" ? { text: shown(), caret: [...shown()].length } : { text: shown(), caret: line.caret };
|
|
1275
|
-
return [`${colors.cyan("?")} ${question} ${withCaret(colors, typed, roomAfter(question, columns), line.text === "")}`, ...invalid === undefined ? [] : [` ${colors.red(invalid)}`], ...completions.length > 1 ? [listed2(colors, completions, columns)] : []];
|
|
1276
|
-
}, (key) => {
|
|
1277
|
-
if (key === "cancel")
|
|
1278
|
-
return "cancel";
|
|
1279
|
-
invalid = undefined;
|
|
1280
|
-
completions = [];
|
|
1281
|
-
if (line.chained === true && endsKills(key))
|
|
1282
|
-
line = { ...line, chained: false };
|
|
1283
|
-
if (key === "tab") {
|
|
1284
|
-
const chars = [...line.text];
|
|
1285
|
-
const before = chars.slice(0, line.caret).join("");
|
|
1286
|
-
const found = complete?.(before) ?? [];
|
|
1287
|
-
const filled = sharedStart(found);
|
|
1288
|
-
if ([...filled].length > [...before].length)
|
|
1289
|
-
line = { ...line, text: filled + chars.slice(line.caret).join(""), caret: [...filled].length };
|
|
1290
|
-
else
|
|
1291
|
-
completions = found;
|
|
1292
|
-
return;
|
|
1293
|
-
}
|
|
1294
|
-
if (key === "enter") {
|
|
1295
|
-
invalid = validate?.(taken());
|
|
1296
|
-
return invalid === undefined ? "enter" : undefined;
|
|
1297
|
-
}
|
|
1298
|
-
if (key === "up" || key === "down") {
|
|
1299
|
-
const to = Math.min(Math.max(recalled + (key === "up" ? 1 : -1), -1), earlier.length - 1);
|
|
1300
|
-
if (recalled === -1)
|
|
1301
|
-
draft = line;
|
|
1302
|
-
recalled = to;
|
|
1303
|
-
const shown = to === -1 ? draft : { text: earlier[to], caret: [...earlier[to]].length };
|
|
1304
|
-
line = { ...shown, killed: line.killed ?? "" };
|
|
1305
|
-
return;
|
|
1306
|
-
}
|
|
1307
|
-
const edit = { home: "linestart", end: "lineend" }[key] ?? key;
|
|
1308
|
-
if (typeof edit === "object" || isEditKey(edit))
|
|
1309
|
-
line = editLine(line, edit);
|
|
1310
|
-
return;
|
|
1311
|
-
});
|
|
1312
|
-
if (!accepted)
|
|
1313
|
-
return;
|
|
1314
|
-
if (remembered !== undefined && taken() !== "")
|
|
1315
|
-
rememberAnswer(remembered, taken());
|
|
1316
|
-
return taken();
|
|
1355
|
+
function printError(prefix, message, hint, cause) {
|
|
1356
|
+
const colors = paint(process11.stderr);
|
|
1357
|
+
const styled = takesControlCodes(process11.stderr);
|
|
1358
|
+
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
1359
|
+
const under = (label, text, tint) => text === undefined ? "" : `
|
|
1360
|
+
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
1361
|
+
console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
|
|
1317
1362
|
}
|
|
1318
|
-
function
|
|
1319
|
-
|
|
1363
|
+
function printJsonError(message, hint, cause) {
|
|
1364
|
+
console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
|
|
1320
1365
|
}
|
|
1321
|
-
|
|
1322
|
-
const
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
const
|
|
1329
|
-
const
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
const
|
|
1339
|
-
|
|
1340
|
-
return;
|
|
1341
|
-
stderr.write("\x1B[0J\x1B[?25h\x1B[?2004l");
|
|
1342
|
-
stdin.setRawMode(false);
|
|
1343
|
-
stop();
|
|
1344
|
-
stdin.setRawMode(true);
|
|
1345
|
-
stderr.write("\x1B[?25l\x1B[?2004h");
|
|
1346
|
-
};
|
|
1366
|
+
function wantsJson(argv) {
|
|
1367
|
+
const end = argv.indexOf("--");
|
|
1368
|
+
return (end === -1 ? argv : argv.slice(0, end)).includes("--json");
|
|
1369
|
+
}
|
|
1370
|
+
function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
1371
|
+
if (error instanceof HelpShown)
|
|
1372
|
+
return 0;
|
|
1373
|
+
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
1374
|
+
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
1375
|
+
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
1376
|
+
if (error instanceof Exit && error.code === 2)
|
|
1377
|
+
noteUsageError(error.message);
|
|
1378
|
+
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
1379
|
+
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
1380
|
+
return error instanceof Exit ? error.code : 1;
|
|
1381
|
+
}
|
|
1382
|
+
async function dispatch(level, typed, { version, redact }) {
|
|
1383
|
+
const prefix = level.path.join(" ");
|
|
1384
|
+
let argv;
|
|
1347
1385
|
try {
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1386
|
+
argv = takeOutputFlags(typed);
|
|
1387
|
+
} catch (error) {
|
|
1388
|
+
return reportThrown(prefix, error);
|
|
1389
|
+
}
|
|
1390
|
+
const [name, ...args] = argv;
|
|
1391
|
+
const fallback = level.defaultCommand === undefined ? undefined : level.commands[level.defaultCommand];
|
|
1392
|
+
if (name === undefined && level.runBare && fallback !== undefined && "run" in fallback) {
|
|
1393
|
+
try {
|
|
1394
|
+
return await fallback.run([]);
|
|
1395
|
+
} catch (error) {
|
|
1396
|
+
return reportThrown(`${prefix} ${level.defaultCommand}`, error, redact, false);
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
if (name === undefined && level.path.length > 1) {
|
|
1400
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process11.stderr));
|
|
1401
|
+
return 2;
|
|
1402
|
+
}
|
|
1403
|
+
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
1404
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process11.stdout));
|
|
1405
|
+
return 0;
|
|
1406
|
+
}
|
|
1407
|
+
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
1408
|
+
console.log(version);
|
|
1409
|
+
return 0;
|
|
1410
|
+
}
|
|
1411
|
+
let command = level.commands[level.aliases?.[name] ?? name];
|
|
1412
|
+
let rest = args;
|
|
1413
|
+
let ran = name;
|
|
1414
|
+
if (command === undefined && level.lazy.length > 0) {
|
|
1415
|
+
level = await expand(level, [...level.path.slice(1), ...argv]);
|
|
1416
|
+
command = level.commands[level.aliases?.[name] ?? name];
|
|
1417
|
+
}
|
|
1418
|
+
if (command === undefined && level.defaultCommand !== undefined) {
|
|
1419
|
+
command = level.commands[level.defaultCommand];
|
|
1420
|
+
rest = argv;
|
|
1421
|
+
ran = level.defaultCommand;
|
|
1422
|
+
}
|
|
1423
|
+
if (command === undefined) {
|
|
1424
|
+
const meant = closest(name, Object.keys(shown(level.commands)));
|
|
1425
|
+
printError(prefix, `no command ${name}`, meant === undefined ? `run ${prefix} --help for its commands` : `did you mean ${meant}?`);
|
|
1426
|
+
return 2;
|
|
1427
|
+
}
|
|
1428
|
+
if ("commands" in command) {
|
|
1429
|
+
const { summary } = command;
|
|
1430
|
+
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 });
|
|
1431
|
+
}
|
|
1432
|
+
try {
|
|
1433
|
+
return await command.run(rest);
|
|
1434
|
+
} catch (error) {
|
|
1435
|
+
return reportThrown(`${prefix} ${ran}`, error, redact, wantsJson(rest));
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
var COMPLETE = "__complete";
|
|
1439
|
+
var FILES = "__files__";
|
|
1440
|
+
async function completingOf(run) {
|
|
1441
|
+
completion.active = true;
|
|
1442
|
+
try {
|
|
1443
|
+
await run([]);
|
|
1444
|
+
} catch (error) {
|
|
1445
|
+
if (error instanceof Completing)
|
|
1446
|
+
return error;
|
|
1380
1447
|
} finally {
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1448
|
+
completion.active = false;
|
|
1449
|
+
}
|
|
1450
|
+
return new Completing({});
|
|
1451
|
+
}
|
|
1452
|
+
async function optionsOf(run) {
|
|
1453
|
+
return (await completingOf(run)).options;
|
|
1454
|
+
}
|
|
1455
|
+
function candidateLine(candidate) {
|
|
1456
|
+
return typeof candidate === "string" ? candidate : candidate.join("\t");
|
|
1457
|
+
}
|
|
1458
|
+
function positionalBeingTyped(before, { options, positionals }) {
|
|
1459
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
1460
|
+
const typed = [];
|
|
1461
|
+
let at = 0;
|
|
1462
|
+
while (at < before.length) {
|
|
1463
|
+
const word = before[at];
|
|
1464
|
+
if (word === "--") {
|
|
1465
|
+
typed.push(...before.slice(at + 1));
|
|
1466
|
+
break;
|
|
1467
|
+
}
|
|
1468
|
+
if (!word.startsWith("-"))
|
|
1469
|
+
typed.push(word);
|
|
1470
|
+
else if (takesValue(word))
|
|
1471
|
+
at++;
|
|
1472
|
+
at++;
|
|
1473
|
+
}
|
|
1474
|
+
const last = positionals.at(-1);
|
|
1475
|
+
if (typed.length < positionals.length)
|
|
1476
|
+
return { name: positionals[typed.length], typed };
|
|
1477
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
1478
|
+
}
|
|
1479
|
+
async function leafCandidates(run, words) {
|
|
1480
|
+
const completing = await completingOf(run);
|
|
1481
|
+
if ((words.at(-1) ?? "").startsWith("-"))
|
|
1482
|
+
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
1483
|
+
const flag = words.at(-2);
|
|
1484
|
+
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
1485
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
1486
|
+
if (option?.type === "string") {
|
|
1487
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
1488
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1489
|
+
}
|
|
1490
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
1491
|
+
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
1492
|
+
}
|
|
1493
|
+
async function candidates(scope, defaultCommand, words, before = []) {
|
|
1494
|
+
const [word = "", ...rest] = words;
|
|
1495
|
+
const listing = rest.length === 0 && !word.startsWith("-");
|
|
1496
|
+
let { commands, aliases } = scope;
|
|
1497
|
+
let command = commands[aliases?.[word] ?? word];
|
|
1498
|
+
if (listing || command === undefined) {
|
|
1499
|
+
({ commands, aliases } = await expand(scope, [...before, ...words]));
|
|
1500
|
+
command = commands[aliases?.[word] ?? word];
|
|
1501
|
+
}
|
|
1502
|
+
if (listing) {
|
|
1503
|
+
const own = await Promise.all(Object.entries(shown(commands)).map(async ([name, { summary }]) => `${name} ${await resolveSummary(summary)}`));
|
|
1504
|
+
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
1505
|
+
const values = fallback !== undefined && "run" in fallback ? await leafCandidates(fallback.run, [word]) : [];
|
|
1506
|
+
const valueOf = (line) => line.slice(0, line.includes("\t") ? line.indexOf("\t") : undefined);
|
|
1507
|
+
return [...own, ...values.filter((line) => line !== FILES && !(valueOf(line) in commands))];
|
|
1508
|
+
}
|
|
1509
|
+
if (command === undefined) {
|
|
1510
|
+
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand];
|
|
1511
|
+
return fallback !== undefined && "run" in fallback ? leafCandidates(fallback.run, words) : [];
|
|
1512
|
+
}
|
|
1513
|
+
return "commands" in command ? candidates(scopeOf(command.commands, command.extraCommands, command.aliases), undefined, rest, [...before, word]) : leafCandidates(command.run, rest);
|
|
1514
|
+
}
|
|
1515
|
+
var COMPLETIONS = "--completions";
|
|
1516
|
+
function flagValue([flag = "", ...rest]) {
|
|
1517
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1518
|
+
}
|
|
1519
|
+
function printCompletionScript(name, args) {
|
|
1520
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1521
|
+
if (shell === undefined || args.length !== 1) {
|
|
1522
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1523
|
+
return 2;
|
|
1387
1524
|
}
|
|
1525
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1526
|
+
return 0;
|
|
1388
1527
|
}
|
|
1528
|
+
async function printCandidates(found) {
|
|
1529
|
+
for (const line of await found)
|
|
1530
|
+
console.log(line);
|
|
1531
|
+
return 0;
|
|
1532
|
+
}
|
|
1533
|
+
function packageVersion(entry = Bun.main) {
|
|
1534
|
+
let resolved = entry;
|
|
1535
|
+
try {
|
|
1536
|
+
resolved = realpathSync2(entry);
|
|
1537
|
+
} catch {}
|
|
1538
|
+
for (let dir = dirname2(resolved);; dir = dirname2(dir)) {
|
|
1539
|
+
try {
|
|
1540
|
+
const { version } = JSON.parse(readFileSync2(join2(dir, "package.json"), "utf8"));
|
|
1541
|
+
if (typeof version === "string")
|
|
1542
|
+
return version;
|
|
1543
|
+
} catch {}
|
|
1544
|
+
if (dirname2(dir) === dir)
|
|
1545
|
+
return "0.0.0";
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
1549
|
+
const version = cli.version ?? packageVersion();
|
|
1550
|
+
const answered = await askpassClient(argv);
|
|
1551
|
+
if (answered !== undefined)
|
|
1552
|
+
return answered;
|
|
1553
|
+
if (argv[0] === COMPLETE)
|
|
1554
|
+
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1555
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1556
|
+
return printCompletionScript(cli.name, flagValue(argv));
|
|
1557
|
+
const started = performance.now();
|
|
1558
|
+
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 });
|
|
1559
|
+
const command = commandPath(scopeOf(cli.commands, cli.extraCommands, cli.aliases), argv);
|
|
1560
|
+
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1561
|
+
if (cli.usage !== false) {
|
|
1562
|
+
try {
|
|
1563
|
+
recordUsage(usageEntry(cli.name, command, argv, code, { ms: performance.now() - started }));
|
|
1564
|
+
} catch {}
|
|
1565
|
+
}
|
|
1566
|
+
return code;
|
|
1567
|
+
}
|
|
1568
|
+
function commandPath(scope, argv) {
|
|
1569
|
+
const path = [];
|
|
1570
|
+
let level = scope;
|
|
1571
|
+
for (const word of argv.filter((each) => !each.startsWith("-"))) {
|
|
1572
|
+
const name = level.aliases !== undefined && Object.hasOwn(level.aliases, word) ? level.aliases[word] ?? word : word;
|
|
1573
|
+
const command = Object.hasOwn(level.commands, name) ? level.commands[name] : undefined;
|
|
1574
|
+
if (command === undefined)
|
|
1575
|
+
break;
|
|
1576
|
+
path.push(word);
|
|
1577
|
+
if (!("commands" in command))
|
|
1578
|
+
break;
|
|
1579
|
+
level = scopeOf(command.commands, command.extraCommands, command.aliases);
|
|
1580
|
+
}
|
|
1581
|
+
return path.length === 0 ? undefined : path.join(" ");
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
// ../kit/src/index.ts
|
|
1585
|
+
init_config();
|
|
1586
|
+
|
|
1587
|
+
// ../kit/src/excerpt.ts
|
|
1588
|
+
init_text2();
|
|
1589
|
+
|
|
1590
|
+
// ../kit/src/index.ts
|
|
1591
|
+
init_folders();
|
|
1592
|
+
init_format();
|
|
1593
|
+
|
|
1594
|
+
// ../kit/src/git.ts
|
|
1595
|
+
init_args();
|
|
1596
|
+
// ../kit/src/limit.ts
|
|
1597
|
+
init_args();
|
|
1598
|
+
|
|
1599
|
+
// ../kit/src/index.ts
|
|
1600
|
+
init_mode();
|
|
1601
|
+
|
|
1602
|
+
// ../kit/src/report.ts
|
|
1603
|
+
init_style();
|
|
1604
|
+
init_text2();
|
|
1605
|
+
// ../kit/src/secrets.ts
|
|
1606
|
+
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1607
|
+
// ../kit/src/sessions.ts
|
|
1608
|
+
var {Glob } = globalThis.Bun;
|
|
1609
|
+
var SESSION_FILES = new Glob("*.json");
|
|
1610
|
+
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1611
|
+
|
|
1612
|
+
// ../kit/src/index.ts
|
|
1613
|
+
init_style();
|
|
1614
|
+
init_text2();
|
|
1615
|
+
init_theme();
|
|
1616
|
+
init_user_config();
|
|
1617
|
+
|
|
1618
|
+
// ../kit/src/watch.ts
|
|
1619
|
+
init_args();
|
|
1620
|
+
init_input();
|
|
1621
|
+
init_style();
|
|
1622
|
+
// ../kit/src/workspace-root.ts
|
|
1623
|
+
init_user_config();
|
|
1624
|
+
// src/cli.ts
|
|
1625
|
+
init_prompt();
|
|
1389
1626
|
|
|
1390
1627
|
// src/encode.ts
|
|
1391
1628
|
function b64Encode(bytes, url = false) {
|
|
@@ -1565,7 +1802,7 @@ var NUMBER = /^-?\d+(?:\.\d+)?$/;
|
|
|
1565
1802
|
var MILLISECONDS_FROM = 100000000000;
|
|
1566
1803
|
function instant(kind, ms, now, timeZone) {
|
|
1567
1804
|
if (Number.isNaN(new Date(ms).getTime()))
|
|
1568
|
-
throw new
|
|
1805
|
+
throw new RangeError("the date is out of range");
|
|
1569
1806
|
return { kind, ...zoned(ms, timeZone), ms, seconds: Math.floor(ms / 1000), relative: relative(ms, now) };
|
|
1570
1807
|
}
|
|
1571
1808
|
function convert(value, { now = Date.now(), timeZone } = {}) {
|
|
@@ -1656,18 +1893,18 @@ async function bytesInput(argument, what) {
|
|
|
1656
1893
|
return new Uint8Array(await Bun.stdin.arrayBuffer());
|
|
1657
1894
|
}
|
|
1658
1895
|
function printRows(rows) {
|
|
1659
|
-
const { cyan } = paint(
|
|
1896
|
+
const { cyan } = paint(process16.stdout);
|
|
1660
1897
|
const width = Math.max(...rows.map(([label]) => label.length));
|
|
1661
1898
|
for (const [label, value] of rows)
|
|
1662
1899
|
console.log(`${cyan(label.padEnd(width))} ${value}`);
|
|
1663
1900
|
}
|
|
1664
|
-
var PASSWORD_USAGE = `dev password [length] [format] [-b|--bcrypt [password]]: a random password of <length> bytes (default ${DEFAULT_LENGTH}) as hex, base64 (default) or base64url
|
|
1901
|
+
var PASSWORD_USAGE = `dev password [length] [format] [-b|--bcrypt [password]] [--copy]: a random password of <length> bytes (default ${DEFAULT_LENGTH}) as hex, base64 (default) or base64url
|
|
1665
1902
|
|
|
1666
|
-
Printed on stdout and copied
|
|
1903
|
+
Printed on stdout, and copied with --copy. With --bcrypt the bcrypt hash (cost 10) prints, of the password given (- asks for it masked on a terminal, or reads stdin, keeping it out of the shell history) or of a generated one, which prints on stderr and is the one --copy copies. The hash has the $2y$ prefix htpasswd -B writes.`;
|
|
1667
1904
|
var PASSWORD_EXITS = [[0, "it printed the password or hash"], [2, "a usage error"], [130, "the prompt was cancelled"]];
|
|
1668
1905
|
var PASSWORD_OPTIONS = {
|
|
1669
1906
|
bcrypt: { type: "string", short: "b", optional: { bare: "", accepts: STDIN_OR_VALUE }, description: "print the bcrypt hash of the password given, or of a generated one" },
|
|
1670
|
-
|
|
1907
|
+
copy: copyOption("the password, or the hash of a password given"),
|
|
1671
1908
|
json: jsonOption("{password?, hash?, format, bytes, copied}")
|
|
1672
1909
|
};
|
|
1673
1910
|
var FORMAT_NOTES = { hex: "hexadecimal", base64: "base64", base64url: "url-safe base64" };
|
|
@@ -1687,13 +1924,13 @@ async function password(args) {
|
|
|
1687
1924
|
const given = bcrypt === "-" ? await secretInput("the password") : bcrypt;
|
|
1688
1925
|
const secret = given ?? generatePassword(bytes, format);
|
|
1689
1926
|
const hash = values.bcrypt === undefined ? undefined : await bcryptHash(secret);
|
|
1690
|
-
const copied = values
|
|
1927
|
+
const copied = values.copy === true && await copyText(given === undefined ? secret : hash ?? secret);
|
|
1691
1928
|
if (values.json === true) {
|
|
1692
1929
|
printJson({ ...hash === undefined ? {} : { hash }, ...given === undefined ? { password: secret } : {}, format, bytes, copied });
|
|
1693
1930
|
return 0;
|
|
1694
1931
|
}
|
|
1695
1932
|
if (copied)
|
|
1696
|
-
console.error(paint(
|
|
1933
|
+
console.error(paint(process16.stderr).dim("copied to clipboard"));
|
|
1697
1934
|
if (hash !== undefined && given === undefined)
|
|
1698
1935
|
console.error(secret);
|
|
1699
1936
|
console.log(hash ?? secret);
|
|
@@ -1722,7 +1959,7 @@ async function jwt(args) {
|
|
|
1722
1959
|
printJson({ header: decoded.header, payload: decoded.payload, claims, signatureBytes: decoded.signatureBytes });
|
|
1723
1960
|
return 0;
|
|
1724
1961
|
}
|
|
1725
|
-
const { bold } = paint(
|
|
1962
|
+
const { bold } = paint(process16.stdout);
|
|
1726
1963
|
console.log(`${bold("header")}
|
|
1727
1964
|
${JSON.stringify(decoded.header, null, 2)}
|
|
1728
1965
|
|
|
@@ -1908,13 +2145,13 @@ async function ip(args) {
|
|
|
1908
2145
|
}
|
|
1909
2146
|
}
|
|
1910
2147
|
if (import.meta.main) {
|
|
1911
|
-
|
|
2148
|
+
process16.exitCode = await runCli({
|
|
1912
2149
|
name: "dev",
|
|
1913
2150
|
about: "small developer utilities: passwords and bcrypt hashes, JWTs, timestamps, UUIDs, base64, URLs and file hashes",
|
|
1914
2151
|
replaces: "openssl rand, htpasswd, jwt.io, date -d, uuidgen, base64, sha256sum and one-off scripts for each",
|
|
1915
2152
|
examples: ["dev password", ["dev jwt <token>", "header, payload and expiry"], ["dev ts 1700000000", "an epoch as dates"]],
|
|
1916
2153
|
commands: {
|
|
1917
|
-
password: { summary: "a random password,
|
|
2154
|
+
password: { summary: "a random password, or its bcrypt hash", run: password },
|
|
1918
2155
|
jwt: { summary: "decode a JWT without verifying it, expiry shown as dates", run: jwt },
|
|
1919
2156
|
ts: { summary: "convert epochs, ISO dates and durations, local and UTC", run: ts },
|
|
1920
2157
|
uuid: { summary: "random UUIDs, v4 or v7", run: async (args) => Promise.resolve(uuid(args)) },
|