@kaynooo/cli-gloss 0.0.2 → 0.0.6
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/dist/gloss.js +469 -134
- package/package.json +5 -5
package/dist/gloss.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
2
|
// @bun
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
+
};
|
|
12
14
|
|
|
13
15
|
// ../kit/src/mode.ts
|
|
14
16
|
import process2 from "process";
|
|
15
|
-
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
16
|
-
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
17
17
|
function isSet(value) {
|
|
18
18
|
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
19
19
|
}
|
|
@@ -27,12 +27,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
27
27
|
return "terminal";
|
|
28
28
|
return isSet(env.CI) ? "ci" : "pipe";
|
|
29
29
|
}
|
|
30
|
+
var MODES, AGENT_VARIABLES;
|
|
31
|
+
var init_mode = __esm(() => {
|
|
32
|
+
MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
33
|
+
AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
34
|
+
});
|
|
30
35
|
|
|
31
|
-
//
|
|
32
|
-
import process6 from "process";
|
|
33
|
-
|
|
34
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
35
|
-
var G = /^[a-f0-9]+$/i;
|
|
36
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
36
37
|
function b(r) {
|
|
37
38
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
38
39
|
if (!G.test(e))
|
|
@@ -43,11 +44,6 @@ function b(r) {
|
|
|
43
44
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
44
45
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
45
46
|
}
|
|
46
|
-
var 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") => {
|
|
47
|
-
let [l, n, c] = b(r);
|
|
48
|
-
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
49
|
-
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
50
|
-
var h = new Set(["", "1", "2", "3", "true"]);
|
|
51
47
|
function C(r, e = globalThis.process?.env ?? {}) {
|
|
52
48
|
if (e.FORCE_COLOR !== undefined)
|
|
53
49
|
return h.has(e.FORCE_COLOR);
|
|
@@ -84,13 +80,21 @@ function f(r, e = []) {
|
|
|
84
80
|
function Fe(r = {}) {
|
|
85
81
|
return f(r);
|
|
86
82
|
}
|
|
87
|
-
var
|
|
83
|
+
var G, B, h, o;
|
|
84
|
+
var init_chunk_x450vn3m = __esm(() => {
|
|
85
|
+
G = /^[a-f0-9]+$/i;
|
|
86
|
+
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") => {
|
|
87
|
+
let [l, n, c] = b(r);
|
|
88
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
89
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
90
|
+
h = new Set(["", "1", "2", "3", "true"]);
|
|
91
|
+
o = Fe();
|
|
92
|
+
});
|
|
88
93
|
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
import process5 from "process";
|
|
94
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
|
|
95
|
+
var init_colors = __esm(() => {
|
|
96
|
+
init_chunk_x450vn3m();
|
|
97
|
+
});
|
|
94
98
|
|
|
95
99
|
// ../kit/src/config.ts
|
|
96
100
|
import { existsSync } from "fs";
|
|
@@ -106,48 +110,36 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
106
110
|
return;
|
|
107
111
|
}
|
|
108
112
|
}
|
|
113
|
+
var init_config = __esm(() => {
|
|
114
|
+
init_args();
|
|
115
|
+
});
|
|
109
116
|
|
|
110
117
|
// ../kit/src/user-config.ts
|
|
111
118
|
import { homedir } from "os";
|
|
112
|
-
import { join as join2 } from "path";
|
|
119
|
+
import { isAbsolute, join as join2 } from "path";
|
|
113
120
|
import process4 from "process";
|
|
121
|
+
function xdgFolder(value, fallback) {
|
|
122
|
+
return value !== undefined && isAbsolute(value) ? value : fallback;
|
|
123
|
+
}
|
|
114
124
|
function configBase(where = {}) {
|
|
115
125
|
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
116
|
-
return xdg
|
|
126
|
+
return xdgFolder(xdg, join2(where.home ?? homedir(), ".config"));
|
|
117
127
|
}
|
|
118
128
|
function userConfigPath(bin, where = {}) {
|
|
119
129
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
120
130
|
}
|
|
131
|
+
var init_user_config = () => {};
|
|
121
132
|
|
|
122
133
|
// ../kit/src/theme.ts
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
128
|
-
bins: {},
|
|
129
|
-
gradient: ["#c084fc", "#67e8f9"]
|
|
130
|
-
};
|
|
131
|
-
var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", plan: "magentaBright", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
132
|
-
var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", plan: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
133
|
-
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
134
|
-
var PRESETS = {
|
|
135
|
-
default: {},
|
|
136
|
-
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
137
|
-
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
138
|
-
ascii: { glyphs: ASCII }
|
|
139
|
-
};
|
|
140
|
-
var STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
|
|
141
|
-
var HEX = /^#[0-9a-f]{6}$/i;
|
|
142
|
-
var CONTROL = /\p{Cc}/u;
|
|
143
|
-
var MAX_FILE_BYTES = 64 * 1024;
|
|
144
|
-
var SPACES = /\s+/;
|
|
134
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
135
|
+
import { homedir as homedir2 } from "os";
|
|
136
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
137
|
+
import process5 from "process";
|
|
145
138
|
function isColorSpec(spec) {
|
|
146
139
|
if (typeof spec === "number")
|
|
147
140
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
148
141
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
149
142
|
}
|
|
150
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
151
143
|
function cubeLevel(channel) {
|
|
152
144
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
153
145
|
}
|
|
@@ -252,7 +244,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
252
244
|
function endsWalk(home) {
|
|
253
245
|
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
254
246
|
}
|
|
255
|
-
var warned = new Set;
|
|
256
247
|
function warnOnce(message) {
|
|
257
248
|
if (warned.has(message))
|
|
258
249
|
return;
|
|
@@ -289,8 +280,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
289
280
|
}
|
|
290
281
|
return { theme, sources, preset };
|
|
291
282
|
}
|
|
292
|
-
var current;
|
|
293
|
-
var currentKey = "";
|
|
294
283
|
function activeTheme() {
|
|
295
284
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
296
285
|
if (current === undefined || key !== currentKey) {
|
|
@@ -299,8 +288,38 @@ function activeTheme() {
|
|
|
299
288
|
}
|
|
300
289
|
return current;
|
|
301
290
|
}
|
|
291
|
+
var ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
|
|
292
|
+
var init_theme = __esm(() => {
|
|
293
|
+
init_config();
|
|
294
|
+
init_user_config();
|
|
295
|
+
ENDS = new Map;
|
|
296
|
+
DEFAULT = {
|
|
297
|
+
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
298
|
+
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
|
|
299
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
300
|
+
bins: {},
|
|
301
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
302
|
+
};
|
|
303
|
+
BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", plan: "magentaBright", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
304
|
+
MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", plan: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
305
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
306
|
+
PRESETS = {
|
|
307
|
+
default: {},
|
|
308
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
309
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
310
|
+
ascii: { glyphs: ASCII }
|
|
311
|
+
};
|
|
312
|
+
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"]);
|
|
313
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
314
|
+
CONTROL = /\p{Cc}/u;
|
|
315
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
316
|
+
SPACES = /\s+/;
|
|
317
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
318
|
+
warned = new Set;
|
|
319
|
+
});
|
|
302
320
|
|
|
303
321
|
// ../kit/src/style.ts
|
|
322
|
+
import process6 from "process";
|
|
304
323
|
function takesControlCodes(stream, env = process6.env) {
|
|
305
324
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
306
325
|
}
|
|
@@ -311,35 +330,81 @@ function role(name, stream, env = process6.env) {
|
|
|
311
330
|
const colors = paint(stream, env);
|
|
312
331
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
313
332
|
}
|
|
314
|
-
var STATUS_WORDS
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
333
|
+
var STATUS_WORDS, STATUS_OF;
|
|
334
|
+
var init_style = __esm(() => {
|
|
335
|
+
init_colors();
|
|
336
|
+
init_mode();
|
|
337
|
+
init_theme();
|
|
338
|
+
STATUS_WORDS = {
|
|
339
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
340
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
341
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
342
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
343
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
344
|
+
};
|
|
345
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
346
|
+
});
|
|
322
347
|
|
|
323
348
|
// ../kit/src/format.ts
|
|
349
|
+
import process7 from "process";
|
|
350
|
+
function formatSeconds(total) {
|
|
351
|
+
let rest = Math.max(0, Math.round(total));
|
|
352
|
+
const amounts = UNITS.map(([unit, size]) => {
|
|
353
|
+
const amount = Math.floor(rest / size);
|
|
354
|
+
rest -= amount * size;
|
|
355
|
+
return `${amount}${unit}`;
|
|
356
|
+
});
|
|
357
|
+
const first = amounts.findIndex((amount) => !amount.startsWith("0"));
|
|
358
|
+
if (first === -1)
|
|
359
|
+
return "0s";
|
|
360
|
+
const next = amounts[first + 1];
|
|
361
|
+
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
362
|
+
}
|
|
363
|
+
function formatDuration(ms) {
|
|
364
|
+
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
365
|
+
}
|
|
324
366
|
function upTo(text, separator) {
|
|
325
367
|
const end = text.indexOf(separator);
|
|
326
368
|
return end === -1 ? text : text.slice(0, end);
|
|
327
369
|
}
|
|
328
|
-
var ESCAPE = String.fromCharCode(27);
|
|
329
370
|
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
330
371
|
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
331
372
|
}
|
|
332
373
|
function printJson(value) {
|
|
333
374
|
console.log(jsonText(value));
|
|
334
375
|
}
|
|
376
|
+
var UNITS, ESCAPE;
|
|
377
|
+
var init_format = __esm(() => {
|
|
378
|
+
init_mode();
|
|
379
|
+
init_style();
|
|
380
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
381
|
+
ESCAPE = String.fromCharCode(27);
|
|
382
|
+
});
|
|
335
383
|
|
|
336
384
|
// ../kit/src/help.ts
|
|
337
385
|
import process8 from "process";
|
|
338
|
-
var OPTIONAL = /\[[^\]]+\]/g;
|
|
339
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
340
|
-
var FULL_STOP = /\.$/;
|
|
341
386
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
342
|
-
|
|
387
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
388
|
+
`);
|
|
389
|
+
const blank = lines.indexOf("");
|
|
390
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
391
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
392
|
+
const colon = synopses[0].indexOf(": ");
|
|
393
|
+
const inline = synopses[0].slice(colon + 2);
|
|
394
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
395
|
+
if (colon !== -1)
|
|
396
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
397
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
398
|
+
`)}`;
|
|
399
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
400
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
401
|
+
return [head, ...lead, ...rest].join(`
|
|
402
|
+
`);
|
|
403
|
+
}
|
|
404
|
+
function prose(line, colors) {
|
|
405
|
+
if (colors.cyan("x") === "x")
|
|
406
|
+
return line;
|
|
407
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
343
408
|
}
|
|
344
409
|
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
345
410
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -377,29 +442,48 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
377
442
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
378
443
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
379
444
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
380
|
-
const
|
|
445
|
+
const choices = option.choices?.join("|");
|
|
446
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
447
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
381
448
|
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
382
449
|
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
383
|
-
|
|
450
|
+
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
451
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
384
452
|
});
|
|
385
453
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
386
454
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
387
455
|
}
|
|
456
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
457
|
+
var init_help = __esm(() => {
|
|
458
|
+
init_mode();
|
|
459
|
+
init_style();
|
|
460
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
461
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
462
|
+
FULL_STOP = /\.$/;
|
|
463
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
464
|
+
});
|
|
388
465
|
|
|
389
466
|
// ../kit/src/text.ts
|
|
390
|
-
var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
|
|
391
467
|
function stripAnsi(text) {
|
|
392
468
|
return text.replace(ANSI, "");
|
|
393
469
|
}
|
|
394
470
|
function distance(a, b) {
|
|
395
|
-
|
|
396
|
-
|
|
471
|
+
const left = [...a];
|
|
472
|
+
const right = [...b];
|
|
473
|
+
let before = [];
|
|
474
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
475
|
+
for (const [i, x] of left.entries()) {
|
|
397
476
|
const current = [i + 1];
|
|
398
|
-
for (const [j,
|
|
399
|
-
|
|
477
|
+
for (const [j, y] of right.entries()) {
|
|
478
|
+
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
479
|
+
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
480
|
+
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
481
|
+
current.push(cost);
|
|
482
|
+
}
|
|
483
|
+
before = previous;
|
|
400
484
|
previous = current;
|
|
401
485
|
}
|
|
402
|
-
return previous[
|
|
486
|
+
return previous[right.length] ?? 0;
|
|
403
487
|
}
|
|
404
488
|
function closest(name, names) {
|
|
405
489
|
const started = names.find((known) => known.startsWith(name));
|
|
@@ -408,36 +492,26 @@ function closest(name, names) {
|
|
|
408
492
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
409
493
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
410
494
|
}
|
|
495
|
+
var ANSI;
|
|
496
|
+
var init_text = __esm(() => {
|
|
497
|
+
ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
// ../kit/src/input.ts
|
|
501
|
+
var init_input = __esm(() => {
|
|
502
|
+
init_args();
|
|
503
|
+
});
|
|
411
504
|
|
|
412
505
|
// ../kit/src/args.ts
|
|
413
|
-
|
|
506
|
+
import process9 from "process";
|
|
507
|
+
import { parseArgs } from "util";
|
|
414
508
|
function jsonOption(holds) {
|
|
415
509
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
416
510
|
}
|
|
417
|
-
class Exit extends Error {
|
|
418
|
-
code;
|
|
419
|
-
hint;
|
|
420
|
-
constructor(message, code, hint) {
|
|
421
|
-
super(message);
|
|
422
|
-
this.code = code;
|
|
423
|
-
this.hint = hint;
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
class UsageError extends Exit {
|
|
427
|
-
constructor(message, hint) {
|
|
428
|
-
super(message, 2, hint);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
511
|
function badUsage(message) {
|
|
432
512
|
throw new UsageError(message);
|
|
433
513
|
}
|
|
434
514
|
|
|
435
|
-
class HelpShown extends Exit {
|
|
436
|
-
constructor() {
|
|
437
|
-
super("help shown", 0);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
|
|
441
515
|
class Completing {
|
|
442
516
|
options;
|
|
443
517
|
positionals;
|
|
@@ -448,11 +522,6 @@ class Completing {
|
|
|
448
522
|
this.candidates = candidates;
|
|
449
523
|
}
|
|
450
524
|
}
|
|
451
|
-
var completion = { active: false };
|
|
452
|
-
var OUTPUT_OPTIONS = {
|
|
453
|
-
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
454
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
455
|
-
};
|
|
456
525
|
function applyOutput(color, plain, env = process9.env) {
|
|
457
526
|
const when = plain === true ? "never" : color ?? "auto";
|
|
458
527
|
if (when === "auto")
|
|
@@ -606,7 +675,6 @@ function parseError(error) {
|
|
|
606
675
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
607
676
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
608
677
|
}
|
|
609
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
610
678
|
function nearestOption(message, options, allowNegative) {
|
|
611
679
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
612
680
|
if (typed === undefined)
|
|
@@ -622,6 +690,61 @@ function nearestOption(message, options, allowNegative) {
|
|
|
622
690
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
623
691
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
624
692
|
}
|
|
693
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
694
|
+
var init_args = __esm(() => {
|
|
695
|
+
init_format();
|
|
696
|
+
init_help();
|
|
697
|
+
init_text();
|
|
698
|
+
init_help();
|
|
699
|
+
init_input();
|
|
700
|
+
DASHES = /^-+/;
|
|
701
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
702
|
+
Exit = class Exit extends Error {
|
|
703
|
+
code;
|
|
704
|
+
hint;
|
|
705
|
+
[EXIT] = true;
|
|
706
|
+
constructor(message, code, hint) {
|
|
707
|
+
super(message);
|
|
708
|
+
this.code = code;
|
|
709
|
+
this.hint = hint;
|
|
710
|
+
}
|
|
711
|
+
static [Symbol.hasInstance](value) {
|
|
712
|
+
if (this !== Exit)
|
|
713
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
714
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
UsageError = class UsageError extends Exit {
|
|
718
|
+
constructor(message, hint) {
|
|
719
|
+
super(message, 2, hint);
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
HelpShown = class HelpShown extends Exit {
|
|
723
|
+
constructor() {
|
|
724
|
+
super("help shown", 0);
|
|
725
|
+
}
|
|
726
|
+
};
|
|
727
|
+
completion = { active: false };
|
|
728
|
+
OUTPUT_OPTIONS = {
|
|
729
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
730
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
731
|
+
};
|
|
732
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
733
|
+
});
|
|
734
|
+
|
|
735
|
+
// ../kit/src/folders.ts
|
|
736
|
+
var SKIPPED_FOLDERS;
|
|
737
|
+
var init_folders = __esm(() => {
|
|
738
|
+
init_user_config();
|
|
739
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
// src/gloss.ts
|
|
743
|
+
import process18 from "process";
|
|
744
|
+
|
|
745
|
+
// ../kit/src/index.ts
|
|
746
|
+
init_args();
|
|
747
|
+
|
|
625
748
|
// ../kit/src/argv.ts
|
|
626
749
|
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
627
750
|
import { resolve as resolve3 } from "path";
|
|
@@ -646,27 +769,176 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
|
|
|
646
769
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
647
770
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
648
771
|
}
|
|
772
|
+
// ../kit/src/chart.ts
|
|
773
|
+
init_format();
|
|
774
|
+
init_mode();
|
|
775
|
+
init_style();
|
|
776
|
+
init_theme();
|
|
777
|
+
// ../kit/src/ci.ts
|
|
778
|
+
init_args();
|
|
779
|
+
init_format();
|
|
780
|
+
|
|
781
|
+
// ../kit/src/progress.ts
|
|
782
|
+
init_format();
|
|
783
|
+
|
|
784
|
+
// ../kit/src/process.ts
|
|
785
|
+
var GROUP_SIGNALS = new Set(["SIGINT", "SIGHUP"]);
|
|
786
|
+
|
|
649
787
|
// ../kit/src/progress.ts
|
|
788
|
+
init_style();
|
|
789
|
+
init_theme();
|
|
650
790
|
var ESC = String.fromCharCode(27);
|
|
651
791
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
652
792
|
var RESET_STYLE = `${ESC}[0m`;
|
|
653
793
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
794
|
+
|
|
795
|
+
// ../kit/src/ci.ts
|
|
796
|
+
init_style();
|
|
797
|
+
|
|
798
|
+
// ../kit/src/tool.ts
|
|
799
|
+
init_format();
|
|
654
800
|
// ../kit/src/cli.ts
|
|
801
|
+
init_args();
|
|
655
802
|
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
656
803
|
import { dirname as dirname3, join as join5 } from "path";
|
|
804
|
+
import process14 from "process";
|
|
805
|
+
|
|
806
|
+
// ../kit/src/askpass.ts
|
|
807
|
+
import process11 from "process";
|
|
808
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
809
|
+
async function askpassClient(argv) {
|
|
810
|
+
const socketPath = process11.env[SOCKET_VARIABLE];
|
|
811
|
+
if (socketPath === undefined)
|
|
812
|
+
return;
|
|
813
|
+
const request = { prompt: argv[0] ?? "", ...process11.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
814
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
815
|
+
let received = "";
|
|
816
|
+
try {
|
|
817
|
+
await Bun.connect({
|
|
818
|
+
unix: socketPath,
|
|
819
|
+
socket: {
|
|
820
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
821
|
+
`),
|
|
822
|
+
data: (_, chunk) => {
|
|
823
|
+
received += chunk.toString();
|
|
824
|
+
},
|
|
825
|
+
close: () => resolve(received),
|
|
826
|
+
error: () => resolve("")
|
|
827
|
+
}
|
|
828
|
+
});
|
|
829
|
+
} catch {
|
|
830
|
+
return 1;
|
|
831
|
+
}
|
|
832
|
+
const reply = await promise;
|
|
833
|
+
if (reply === "")
|
|
834
|
+
return 1;
|
|
835
|
+
const { answer } = JSON.parse(reply);
|
|
836
|
+
if (request.notice === true)
|
|
837
|
+
return 0;
|
|
838
|
+
if (answer === undefined)
|
|
839
|
+
return 1;
|
|
840
|
+
process11.stdout.write(`${answer}
|
|
841
|
+
`);
|
|
842
|
+
return 0;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
// ../kit/src/completions.ts
|
|
846
|
+
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
847
|
+
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'
|
|
848
|
+
set -l tokens (commandline -xpc 2>/dev/null; or commandline -opc)
|
|
849
|
+
set -l current (commandline -ct)
|
|
850
|
+
for line in ($bin __complete $tokens[2..-1] $current 2>/dev/null)
|
|
851
|
+
if test "$line" = __files__
|
|
852
|
+
__fish_complete_path $current
|
|
853
|
+
else
|
|
854
|
+
echo $line
|
|
855
|
+
end
|
|
856
|
+
end
|
|
857
|
+
end`;
|
|
858
|
+
var BASH_FUNCTION = `__kaynooo_cli_complete() {
|
|
859
|
+
local IFS=$'\\n' cur=\${COMP_WORDS[COMP_CWORD]} line words=
|
|
860
|
+
local -a lines
|
|
861
|
+
COMPREPLY=()
|
|
862
|
+
lines=($("\${COMP_WORDS[0]}" __complete "\${COMP_WORDS[@]:1:COMP_CWORD}" 2>/dev/null))
|
|
863
|
+
for line in "\${lines[@]}"; do
|
|
864
|
+
if [[ $line == __files__ ]]; then
|
|
865
|
+
COMPREPLY+=($(compgen -f -- "$cur"))
|
|
866
|
+
else
|
|
867
|
+
words+="\${line%%$'\\t'*}"$'\\n'
|
|
868
|
+
fi
|
|
869
|
+
done
|
|
870
|
+
COMPREPLY+=($(compgen -W "$words" -- "$cur"))
|
|
871
|
+
}`;
|
|
872
|
+
var ZSH_FUNCTION = `__kaynooo_cli_complete() {
|
|
873
|
+
local line
|
|
874
|
+
local -a described plain
|
|
875
|
+
for line in \${(f)"$("\${words[1]}" __complete "\${(@)words[2,CURRENT]}" 2>/dev/null)"}; do
|
|
876
|
+
if [[ $line == __files__ ]]; then
|
|
877
|
+
_files
|
|
878
|
+
elif [[ $line == *$'\\t'* ]]; then
|
|
879
|
+
described+=("\${\${line%%$'\\t'*}//:/\\\\:}:\${line#*$'\\t'}")
|
|
880
|
+
else
|
|
881
|
+
plain+=("$line")
|
|
882
|
+
fi
|
|
883
|
+
done
|
|
884
|
+
(( \${#described} )) && _describe -V value described
|
|
885
|
+
(( \${#plain} )) && compadd -- "\${plain[@]}"
|
|
886
|
+
return 0
|
|
887
|
+
}`;
|
|
888
|
+
function completionScript(shell, bins, header = `# Generated by \`${bins[0]} --completions ${shell}\``) {
|
|
889
|
+
if (shell === "fish")
|
|
890
|
+
return `${header}
|
|
891
|
+
${FISH_FUNCTION}
|
|
892
|
+
${bins.map((bin) => `complete -c ${bin} -f -a '(__kaynooo_cli_complete ${bin})'
|
|
893
|
+
`).join("")}`;
|
|
894
|
+
if (shell === "bash")
|
|
895
|
+
return `${header}
|
|
896
|
+
${BASH_FUNCTION}
|
|
897
|
+
complete -F __kaynooo_cli_complete ${bins.join(" ")}
|
|
898
|
+
`;
|
|
899
|
+
return `${header}
|
|
900
|
+
${ZSH_FUNCTION}
|
|
901
|
+
compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
902
|
+
`;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
// ../kit/src/notify.ts
|
|
906
|
+
init_format();
|
|
907
|
+
init_mode();
|
|
657
908
|
import process12 from "process";
|
|
909
|
+
var NOTIFY_AFTER_MS = 1e4;
|
|
910
|
+
var CANCELLED = 130;
|
|
911
|
+
function base64(text) {
|
|
912
|
+
return Buffer.from(text).toString("base64");
|
|
913
|
+
}
|
|
914
|
+
function notification(title, body, env = process12.env) {
|
|
915
|
+
const id = `kit${process12.pid}`;
|
|
916
|
+
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\\`];
|
|
917
|
+
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
918
|
+
}
|
|
919
|
+
function notifyEnd(command, code, ms, { stream = process12.stderr, env = process12.env } = {}) {
|
|
920
|
+
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
921
|
+
return;
|
|
922
|
+
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
// ../kit/src/cli.ts
|
|
926
|
+
init_style();
|
|
927
|
+
init_text();
|
|
658
928
|
|
|
659
929
|
// ../kit/src/usage.ts
|
|
660
930
|
import { appendFileSync, mkdirSync } from "fs";
|
|
661
931
|
import { homedir as homedir3 } from "os";
|
|
662
|
-
import { dirname as dirname2,
|
|
663
|
-
import
|
|
932
|
+
import { dirname as dirname2, join as join4 } from "path";
|
|
933
|
+
import process13 from "process";
|
|
664
934
|
|
|
665
935
|
// ../kit/src/logs.ts
|
|
936
|
+
init_user_config();
|
|
666
937
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
667
938
|
var CLI_FOLDER = "kaynooo-cli";
|
|
668
939
|
|
|
669
940
|
// ../kit/src/usage.ts
|
|
941
|
+
init_user_config();
|
|
670
942
|
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
671
943
|
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
672
944
|
var LONGEST_NAME = 40;
|
|
@@ -674,14 +946,13 @@ var usageError;
|
|
|
674
946
|
function noteUsageError(message) {
|
|
675
947
|
usageError = message;
|
|
676
948
|
}
|
|
677
|
-
function stateHome(env =
|
|
678
|
-
|
|
679
|
-
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
949
|
+
function stateHome(env = process13.env) {
|
|
950
|
+
return xdgFolder(env.XDG_STATE_HOME, join4(homedir3(), ".local", "state"));
|
|
680
951
|
}
|
|
681
|
-
function usagePath(env =
|
|
952
|
+
function usagePath(env = process13.env) {
|
|
682
953
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
683
954
|
}
|
|
684
|
-
function usageRecorded(env =
|
|
955
|
+
function usageRecorded(env = process13.env) {
|
|
685
956
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
686
957
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
687
958
|
}
|
|
@@ -690,12 +961,12 @@ function flagNames(argv) {
|
|
|
690
961
|
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
691
962
|
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
692
963
|
}
|
|
693
|
-
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
964
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
694
965
|
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
695
966
|
usageError = undefined;
|
|
696
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
967
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
697
968
|
}
|
|
698
|
-
function recordUsage(entry, env =
|
|
969
|
+
function recordUsage(entry, env = process13.env) {
|
|
699
970
|
if (!usageRecorded(env))
|
|
700
971
|
return;
|
|
701
972
|
try {
|
|
@@ -711,10 +982,14 @@ var LEVEL_OPTIONS = {
|
|
|
711
982
|
...OUTPUT_OPTIONS,
|
|
712
983
|
help: { type: "boolean", short: "h", description: "show this help" }
|
|
713
984
|
};
|
|
714
|
-
var TOP_OPTIONS = {
|
|
985
|
+
var TOP_OPTIONS = {
|
|
986
|
+
...LEVEL_OPTIONS,
|
|
987
|
+
version: { type: "boolean", short: "v", description: "print the version" },
|
|
988
|
+
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
989
|
+
};
|
|
715
990
|
function printError(prefix, message, hint, cause) {
|
|
716
|
-
const colors = paint(
|
|
717
|
-
const styled = takesControlCodes(
|
|
991
|
+
const colors = paint(process14.stderr);
|
|
992
|
+
const styled = takesControlCodes(process14.stderr);
|
|
718
993
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
719
994
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
720
995
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -791,6 +1066,19 @@ async function leafCandidates(run, words) {
|
|
|
791
1066
|
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
792
1067
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
793
1068
|
}
|
|
1069
|
+
var COMPLETIONS = "--completions";
|
|
1070
|
+
function flagValue([flag = "", ...rest]) {
|
|
1071
|
+
return flag.includes("=") ? [flag.slice(flag.indexOf("=") + 1), ...rest] : rest;
|
|
1072
|
+
}
|
|
1073
|
+
function printCompletionScript(name, args) {
|
|
1074
|
+
const shell = COMPLETION_SHELLS.find((each) => each === args[0]);
|
|
1075
|
+
if (shell === undefined || args.length !== 1) {
|
|
1076
|
+
printError(name, `${COMPLETIONS} takes one of ${COMPLETION_SHELLS.join(", ")}`, `${name} ${COMPLETIONS} fish`);
|
|
1077
|
+
return 2;
|
|
1078
|
+
}
|
|
1079
|
+
console.log(completionScript(shell, [name]).trimEnd());
|
|
1080
|
+
return 0;
|
|
1081
|
+
}
|
|
794
1082
|
async function printCandidates(found) {
|
|
795
1083
|
for (const line of await found)
|
|
796
1084
|
console.log(line);
|
|
@@ -812,42 +1100,86 @@ function packageVersion(entry = Bun.main) {
|
|
|
812
1100
|
}
|
|
813
1101
|
}
|
|
814
1102
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1103
|
+
const answered = await askpassClient(argv);
|
|
1104
|
+
if (answered !== undefined)
|
|
1105
|
+
return answered;
|
|
815
1106
|
if (argv[0] === COMPLETE)
|
|
816
1107
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
1108
|
+
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
1109
|
+
return printCompletionScript(name, flagValue(argv));
|
|
817
1110
|
if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
|
|
818
1111
|
console.log(version ?? packageVersion());
|
|
819
1112
|
return 0;
|
|
820
1113
|
}
|
|
821
1114
|
let code;
|
|
1115
|
+
const started = performance.now();
|
|
822
1116
|
try {
|
|
823
1117
|
code = await run(argv);
|
|
824
1118
|
} catch (error) {
|
|
825
1119
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
826
1120
|
}
|
|
1121
|
+
notifyEnd(name, code, performance.now() - started);
|
|
827
1122
|
if (usage !== false) {
|
|
828
1123
|
try {
|
|
829
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1124
|
+
recordUsage(usageEntry(name, undefined, argv, code, { ms: performance.now() - started }));
|
|
830
1125
|
} catch {}
|
|
831
1126
|
}
|
|
832
1127
|
return code;
|
|
833
1128
|
}
|
|
834
|
-
|
|
835
|
-
|
|
1129
|
+
|
|
1130
|
+
// ../kit/src/index.ts
|
|
1131
|
+
init_config();
|
|
1132
|
+
|
|
1133
|
+
// ../kit/src/excerpt.ts
|
|
1134
|
+
init_text();
|
|
1135
|
+
|
|
1136
|
+
// ../kit/src/index.ts
|
|
1137
|
+
init_folders();
|
|
1138
|
+
init_format();
|
|
1139
|
+
|
|
1140
|
+
// ../kit/src/git.ts
|
|
1141
|
+
init_args();
|
|
1142
|
+
// ../kit/src/limit.ts
|
|
1143
|
+
init_args();
|
|
1144
|
+
|
|
1145
|
+
// ../kit/src/index.ts
|
|
1146
|
+
init_mode();
|
|
1147
|
+
|
|
1148
|
+
// ../kit/src/report.ts
|
|
1149
|
+
init_style();
|
|
1150
|
+
init_text();
|
|
836
1151
|
// ../kit/src/secrets.ts
|
|
837
1152
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1153
|
+
var NOT_PASSWORDS = new Set(["compass", "encompass", "bypass", "overpass", "underpass", "surpass", "trespass"]);
|
|
838
1154
|
// ../kit/src/sessions.ts
|
|
839
1155
|
var {Glob } = globalThis.Bun;
|
|
840
1156
|
var SESSION_FILES = new Glob("*.json");
|
|
841
1157
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1158
|
+
|
|
1159
|
+
// ../kit/src/index.ts
|
|
1160
|
+
init_style();
|
|
1161
|
+
init_text();
|
|
1162
|
+
init_theme();
|
|
1163
|
+
init_user_config();
|
|
1164
|
+
|
|
1165
|
+
// ../kit/src/watch.ts
|
|
1166
|
+
init_args();
|
|
1167
|
+
init_input();
|
|
1168
|
+
init_style();
|
|
1169
|
+
// ../kit/src/workspace-root.ts
|
|
1170
|
+
init_user_config();
|
|
1171
|
+
// src/analyze.ts
|
|
1172
|
+
import { basename } from "path";
|
|
1173
|
+
|
|
842
1174
|
// src/help.ts
|
|
843
1175
|
import { tmpdir } from "os";
|
|
844
|
-
import
|
|
1176
|
+
import process17 from "process";
|
|
845
1177
|
|
|
846
1178
|
// src/man.ts
|
|
847
1179
|
import { existsSync as existsSync3, readdirSync, readFileSync as readFileSync4 } from "fs";
|
|
848
1180
|
import { homedir as homedir4 } from "os";
|
|
849
1181
|
import { join as join6 } from "path";
|
|
850
|
-
import
|
|
1182
|
+
import process16 from "process";
|
|
851
1183
|
var SECTIONS = ["1", "8", "6"];
|
|
852
1184
|
var SAFE_NAME = /^[\w.+-]+$/;
|
|
853
1185
|
var COMPRESSED_UNSUPPORTED = /\.(?:bz2|xz)$/;
|
|
@@ -866,7 +1198,7 @@ function manDirs(env) {
|
|
|
866
1198
|
const configured = env.MANPATH?.split(":").filter((dir) => dir !== "") ?? [];
|
|
867
1199
|
return [...configured, "/usr/share/man", "/usr/local/share/man", join6(homedir4(), ".local/share/man")];
|
|
868
1200
|
}
|
|
869
|
-
function findPage(name, env =
|
|
1201
|
+
function findPage(name, env = process16.env) {
|
|
870
1202
|
if (!SAFE_NAME.test(name))
|
|
871
1203
|
return;
|
|
872
1204
|
for (const section of SECTIONS) {
|
|
@@ -900,12 +1232,14 @@ function unOverstrike(text) {
|
|
|
900
1232
|
return kept.join("");
|
|
901
1233
|
}
|
|
902
1234
|
function render(source) {
|
|
903
|
-
|
|
1235
|
+
if (Bun.which("nroff") === null)
|
|
1236
|
+
return;
|
|
1237
|
+
const result = Bun.spawnSync(["nroff", "-man", "-Tutf8", "-rLL=200n", "-rLT=200n"], { stdin: source, stdout: "pipe", stderr: "ignore", env: { ...process16.env, GROFF_NO_SGR: "1" } });
|
|
904
1238
|
if (result.exitCode !== 0)
|
|
905
1239
|
return;
|
|
906
1240
|
return stripAnsi(unOverstrike(result.stdout.toString())).replaceAll(UNICODE_HYPHENS, "-");
|
|
907
1241
|
}
|
|
908
|
-
function pageText(name, env =
|
|
1242
|
+
function pageText(name, env = process16.env) {
|
|
909
1243
|
const path = findPage(name, env);
|
|
910
1244
|
const source = path === undefined ? undefined : readSource(path);
|
|
911
1245
|
return source === undefined ? undefined : render(source);
|
|
@@ -986,7 +1320,7 @@ function summaryOf(text) {
|
|
|
986
1320
|
function parsePage(name, text) {
|
|
987
1321
|
return { name, summary: summaryOf(text), options: parseOptions(text) };
|
|
988
1322
|
}
|
|
989
|
-
function loadPage(name, env =
|
|
1323
|
+
function loadPage(name, env = process16.env) {
|
|
990
1324
|
const text = pageText(name, env);
|
|
991
1325
|
return text === undefined ? undefined : parsePage(name, text);
|
|
992
1326
|
}
|
|
@@ -1017,7 +1351,7 @@ function helpOf(path, args, env) {
|
|
|
1017
1351
|
${result.stderr.toString()}`);
|
|
1018
1352
|
return text.trim() === "" ? undefined : text;
|
|
1019
1353
|
}
|
|
1020
|
-
function loadHelp(name, subcommand, env =
|
|
1354
|
+
function loadHelp(name, subcommand, env = process17.env) {
|
|
1021
1355
|
if (!SAFE_NAME2.test(name))
|
|
1022
1356
|
return;
|
|
1023
1357
|
const path = Bun.which(name, { PATH: env.PATH ?? "" });
|
|
@@ -1109,7 +1443,7 @@ function explain(words, options) {
|
|
|
1109
1443
|
|
|
1110
1444
|
// src/shell.ts
|
|
1111
1445
|
var REDIRECT = /&>>?|>&|<&|<<<|<<-?|>>|>\||>|</y;
|
|
1112
|
-
var CONTROL2 =
|
|
1446
|
+
var CONTROL2 = /\|[&|]?|&&|&(?!>)|[;\n]/y;
|
|
1113
1447
|
var ASSIGN = /^[A-Z_]\w*\+?=/i;
|
|
1114
1448
|
var FD = /\d+(?=[<>])/y;
|
|
1115
1449
|
var ESCAPABLE_IN_QUOTES = new Set(['"', "\\", "$", "`"]);
|
|
@@ -1298,8 +1632,9 @@ function analyze(line, settings = {}, depth = 0) {
|
|
|
1298
1632
|
for (const { command, next } of parseLine(line)) {
|
|
1299
1633
|
const [head, second] = command.words;
|
|
1300
1634
|
const name = head?.text ?? "";
|
|
1301
|
-
const
|
|
1302
|
-
const
|
|
1635
|
+
const paged = name.startsWith("/") ? basename(name) : name;
|
|
1636
|
+
const sub = head === undefined ? undefined : describeSubcommand(paged, second, env);
|
|
1637
|
+
const manual = sub?.page ?? (head === undefined ? undefined : loadPage(paged, env));
|
|
1303
1638
|
const page = manual ?? (runHelp && head !== undefined ? loadHelp(name, second?.text, env) : undefined);
|
|
1304
1639
|
const fromHelp = manual === undefined && page !== undefined;
|
|
1305
1640
|
const words = command.words.slice(sub === undefined && !(fromHelp && page?.name.includes(" ")) ? 1 : 2);
|
|
@@ -1410,8 +1745,8 @@ function render2(line, stream = process.stdout, depth = 0) {
|
|
|
1410
1745
|
// src/gloss.ts
|
|
1411
1746
|
var USAGE = `gloss [options] <command line>: explains a shell command line, each option matched to what its man page says
|
|
1412
1747
|
|
|
1413
|
-
Quote the command line or put it after --: gloss -- tar -xzvf a.tgz. Without arguments
|
|
1414
|
-
|
|
1748
|
+
Quote the command line or put it after --: gloss -- tar -xzvf a.tgz. Without arguments it is read from stdin.
|
|
1749
|
+
A command is looked up in the man pages on this machine; one with no man page is listed with its words unexplained, unless --run-help reads its options from '<command> --help', which runs the command (a bare name found on PATH only, 3 seconds), so use it for commands you trust.`;
|
|
1415
1750
|
var EXITS = [[0, "it explained the line"], [2, "a usage error"]];
|
|
1416
1751
|
var OPTIONS = {
|
|
1417
1752
|
"run-help": { type: "boolean", description: "for a command with no man page, run `<command> --help` and read its options (runs the command)" },
|
|
@@ -1424,15 +1759,15 @@ function quote(word) {
|
|
|
1424
1759
|
async function main(args) {
|
|
1425
1760
|
const { values, positionals, rest } = parse(args, USAGE, OPTIONS, { rest: true, exits: EXITS, replaces: "explainshell in a browser, reading man pages for each flag", examples: ["gloss 'tar -xzvf a.tgz -C /tmp'", "gloss -- git commit -am fix"] });
|
|
1426
1761
|
const typed = [...positionals.map(String), ...(rest ?? []).map(quote)].join(" ");
|
|
1427
|
-
const line = typed === "" && !
|
|
1762
|
+
const line = typed === "" && !process18.stdin.isTTY ? (await Bun.stdin.text()).trim() : typed;
|
|
1428
1763
|
if (line === "")
|
|
1429
1764
|
badUsage("give the command line to explain, quoted or after --");
|
|
1430
1765
|
const result = analyze(line, { runHelp: values["run-help"] === true });
|
|
1431
1766
|
if (values.json === true)
|
|
1432
1767
|
printJson(result);
|
|
1433
1768
|
else
|
|
1434
|
-
console.log(render2(result,
|
|
1769
|
+
console.log(render2(result, process18.stdout).join(`
|
|
1435
1770
|
`));
|
|
1436
1771
|
return 0;
|
|
1437
1772
|
}
|
|
1438
|
-
|
|
1773
|
+
process18.exitCode = await runMain({ name: "gloss", run: main });
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-gloss",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.6",
|
|
5
5
|
"description": "gloss: explains a shell command line, each word matched to what its man page says.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"homepage": "https://
|
|
8
|
+
"homepage": "https://github.com/Kayno0o/cli/tree/main/packages/gloss#readme",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://
|
|
11
|
+
"url": "git+https://github.com/Kayno0o/cli.git",
|
|
12
12
|
"directory": "packages/gloss"
|
|
13
13
|
},
|
|
14
|
-
"bugs": "https://
|
|
14
|
+
"bugs": "https://github.com/Kayno0o/cli/issues",
|
|
15
15
|
"keywords": [
|
|
16
16
|
"cli",
|
|
17
17
|
"explainshell",
|
|
@@ -35,6 +35,6 @@
|
|
|
35
35
|
"gloss": "$npm_execpath src/gloss.ts"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@kaynooo/cli-kit": "0.
|
|
38
|
+
"@kaynooo/cli-kit": "0.46.0"
|
|
39
39
|
}
|
|
40
40
|
}
|