@kaynooo/cli-gloss 0.0.3 → 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 +340 -133
- 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,17 +330,23 @@ 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
|
|
324
|
-
|
|
349
|
+
import process7 from "process";
|
|
325
350
|
function formatSeconds(total) {
|
|
326
351
|
let rest = Math.max(0, Math.round(total));
|
|
327
352
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -342,21 +367,44 @@ function upTo(text, separator) {
|
|
|
342
367
|
const end = text.indexOf(separator);
|
|
343
368
|
return end === -1 ? text : text.slice(0, end);
|
|
344
369
|
}
|
|
345
|
-
var ESCAPE = String.fromCharCode(27);
|
|
346
370
|
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
347
371
|
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
348
372
|
}
|
|
349
373
|
function printJson(value) {
|
|
350
374
|
console.log(jsonText(value));
|
|
351
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
|
+
});
|
|
352
383
|
|
|
353
384
|
// ../kit/src/help.ts
|
|
354
385
|
import process8 from "process";
|
|
355
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
356
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
357
|
-
var FULL_STOP = /\.$/;
|
|
358
386
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
359
|
-
|
|
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));
|
|
360
408
|
}
|
|
361
409
|
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
362
410
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -391,7 +439,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
391
439
|
return [];
|
|
392
440
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
393
441
|
}
|
|
394
|
-
var MAX_INLINE_CHOICES = 24;
|
|
395
442
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
396
443
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
397
444
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -406,9 +453,17 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
406
453
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
407
454
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
408
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
|
+
});
|
|
409
465
|
|
|
410
466
|
// ../kit/src/text.ts
|
|
411
|
-
var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
412
467
|
function stripAnsi(text) {
|
|
413
468
|
return text.replace(ANSI, "");
|
|
414
469
|
}
|
|
@@ -437,36 +492,26 @@ function closest(name, names) {
|
|
|
437
492
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
438
493
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
439
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
|
+
});
|
|
440
504
|
|
|
441
505
|
// ../kit/src/args.ts
|
|
442
|
-
|
|
506
|
+
import process9 from "process";
|
|
507
|
+
import { parseArgs } from "util";
|
|
443
508
|
function jsonOption(holds) {
|
|
444
509
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
445
510
|
}
|
|
446
|
-
class Exit extends Error {
|
|
447
|
-
code;
|
|
448
|
-
hint;
|
|
449
|
-
constructor(message, code, hint) {
|
|
450
|
-
super(message);
|
|
451
|
-
this.code = code;
|
|
452
|
-
this.hint = hint;
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
class UsageError extends Exit {
|
|
456
|
-
constructor(message, hint) {
|
|
457
|
-
super(message, 2, hint);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
511
|
function badUsage(message) {
|
|
461
512
|
throw new UsageError(message);
|
|
462
513
|
}
|
|
463
514
|
|
|
464
|
-
class HelpShown extends Exit {
|
|
465
|
-
constructor() {
|
|
466
|
-
super("help shown", 0);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
515
|
class Completing {
|
|
471
516
|
options;
|
|
472
517
|
positionals;
|
|
@@ -477,11 +522,6 @@ class Completing {
|
|
|
477
522
|
this.candidates = candidates;
|
|
478
523
|
}
|
|
479
524
|
}
|
|
480
|
-
var completion = { active: false };
|
|
481
|
-
var OUTPUT_OPTIONS = {
|
|
482
|
-
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
483
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
484
|
-
};
|
|
485
525
|
function applyOutput(color, plain, env = process9.env) {
|
|
486
526
|
const when = plain === true ? "never" : color ?? "auto";
|
|
487
527
|
if (when === "auto")
|
|
@@ -635,7 +675,6 @@ function parseError(error) {
|
|
|
635
675
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
636
676
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
637
677
|
}
|
|
638
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
639
678
|
function nearestOption(message, options, allowNegative) {
|
|
640
679
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
641
680
|
if (typed === undefined)
|
|
@@ -651,6 +690,61 @@ function nearestOption(message, options, allowNegative) {
|
|
|
651
690
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
652
691
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
653
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
|
+
|
|
654
748
|
// ../kit/src/argv.ts
|
|
655
749
|
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
656
750
|
import { resolve as resolve3 } from "path";
|
|
@@ -675,15 +769,78 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
|
|
|
675
769
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
676
770
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
677
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
|
+
|
|
678
787
|
// ../kit/src/progress.ts
|
|
788
|
+
init_style();
|
|
789
|
+
init_theme();
|
|
679
790
|
var ESC = String.fromCharCode(27);
|
|
680
791
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
681
792
|
var RESET_STYLE = `${ESC}[0m`;
|
|
682
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();
|
|
683
800
|
// ../kit/src/cli.ts
|
|
801
|
+
init_args();
|
|
684
802
|
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
685
803
|
import { dirname as dirname3, join as join5 } from "path";
|
|
686
|
-
import
|
|
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
|
+
}
|
|
687
844
|
|
|
688
845
|
// ../kit/src/completions.ts
|
|
689
846
|
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
@@ -746,34 +903,42 @@ compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
|
746
903
|
}
|
|
747
904
|
|
|
748
905
|
// ../kit/src/notify.ts
|
|
749
|
-
|
|
906
|
+
init_format();
|
|
907
|
+
init_mode();
|
|
908
|
+
import process12 from "process";
|
|
750
909
|
var NOTIFY_AFTER_MS = 1e4;
|
|
751
910
|
var CANCELLED = 130;
|
|
752
911
|
function base64(text) {
|
|
753
912
|
return Buffer.from(text).toString("base64");
|
|
754
913
|
}
|
|
755
|
-
function notification(title, body, env =
|
|
756
|
-
const id = `kit${
|
|
914
|
+
function notification(title, body, env = process12.env) {
|
|
915
|
+
const id = `kit${process12.pid}`;
|
|
757
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\\`];
|
|
758
917
|
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
759
918
|
}
|
|
760
|
-
function notifyEnd(command, code, ms, { stream =
|
|
919
|
+
function notifyEnd(command, code, ms, { stream = process12.stderr, env = process12.env } = {}) {
|
|
761
920
|
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
762
921
|
return;
|
|
763
922
|
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
764
923
|
}
|
|
765
924
|
|
|
925
|
+
// ../kit/src/cli.ts
|
|
926
|
+
init_style();
|
|
927
|
+
init_text();
|
|
928
|
+
|
|
766
929
|
// ../kit/src/usage.ts
|
|
767
930
|
import { appendFileSync, mkdirSync } from "fs";
|
|
768
931
|
import { homedir as homedir3 } from "os";
|
|
769
|
-
import { dirname as dirname2,
|
|
770
|
-
import
|
|
932
|
+
import { dirname as dirname2, join as join4 } from "path";
|
|
933
|
+
import process13 from "process";
|
|
771
934
|
|
|
772
935
|
// ../kit/src/logs.ts
|
|
936
|
+
init_user_config();
|
|
773
937
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
774
938
|
var CLI_FOLDER = "kaynooo-cli";
|
|
775
939
|
|
|
776
940
|
// ../kit/src/usage.ts
|
|
941
|
+
init_user_config();
|
|
777
942
|
var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
|
|
778
943
|
var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
|
|
779
944
|
var LONGEST_NAME = 40;
|
|
@@ -781,14 +946,13 @@ var usageError;
|
|
|
781
946
|
function noteUsageError(message) {
|
|
782
947
|
usageError = message;
|
|
783
948
|
}
|
|
784
|
-
function stateHome(env =
|
|
785
|
-
|
|
786
|
-
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"));
|
|
787
951
|
}
|
|
788
|
-
function usagePath(env =
|
|
952
|
+
function usagePath(env = process13.env) {
|
|
789
953
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
790
954
|
}
|
|
791
|
-
function usageRecorded(env =
|
|
955
|
+
function usageRecorded(env = process13.env) {
|
|
792
956
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
793
957
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
794
958
|
}
|
|
@@ -797,12 +961,12 @@ function flagNames(argv) {
|
|
|
797
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);
|
|
798
962
|
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
799
963
|
}
|
|
800
|
-
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
964
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
801
965
|
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
802
966
|
usageError = undefined;
|
|
803
|
-
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) } };
|
|
804
968
|
}
|
|
805
|
-
function recordUsage(entry, env =
|
|
969
|
+
function recordUsage(entry, env = process13.env) {
|
|
806
970
|
if (!usageRecorded(env))
|
|
807
971
|
return;
|
|
808
972
|
try {
|
|
@@ -824,8 +988,8 @@ var TOP_OPTIONS = {
|
|
|
824
988
|
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
825
989
|
};
|
|
826
990
|
function printError(prefix, message, hint, cause) {
|
|
827
|
-
const colors = paint(
|
|
828
|
-
const styled = takesControlCodes(
|
|
991
|
+
const colors = paint(process14.stderr);
|
|
992
|
+
const styled = takesControlCodes(process14.stderr);
|
|
829
993
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
830
994
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
831
995
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -936,6 +1100,9 @@ function packageVersion(entry = Bun.main) {
|
|
|
936
1100
|
}
|
|
937
1101
|
}
|
|
938
1102
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1103
|
+
const answered = await askpassClient(argv);
|
|
1104
|
+
if (answered !== undefined)
|
|
1105
|
+
return answered;
|
|
939
1106
|
if (argv[0] === COMPLETE)
|
|
940
1107
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
941
1108
|
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
@@ -954,28 +1121,65 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
954
1121
|
notifyEnd(name, code, performance.now() - started);
|
|
955
1122
|
if (usage !== false) {
|
|
956
1123
|
try {
|
|
957
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1124
|
+
recordUsage(usageEntry(name, undefined, argv, code, { ms: performance.now() - started }));
|
|
958
1125
|
} catch {}
|
|
959
1126
|
}
|
|
960
1127
|
return code;
|
|
961
1128
|
}
|
|
962
|
-
|
|
963
|
-
|
|
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();
|
|
964
1151
|
// ../kit/src/secrets.ts
|
|
965
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"]);
|
|
966
1154
|
// ../kit/src/sessions.ts
|
|
967
1155
|
var {Glob } = globalThis.Bun;
|
|
968
1156
|
var SESSION_FILES = new Glob("*.json");
|
|
969
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
|
+
|
|
970
1174
|
// src/help.ts
|
|
971
1175
|
import { tmpdir } from "os";
|
|
972
|
-
import
|
|
1176
|
+
import process17 from "process";
|
|
973
1177
|
|
|
974
1178
|
// src/man.ts
|
|
975
1179
|
import { existsSync as existsSync3, readdirSync, readFileSync as readFileSync4 } from "fs";
|
|
976
1180
|
import { homedir as homedir4 } from "os";
|
|
977
1181
|
import { join as join6 } from "path";
|
|
978
|
-
import
|
|
1182
|
+
import process16 from "process";
|
|
979
1183
|
var SECTIONS = ["1", "8", "6"];
|
|
980
1184
|
var SAFE_NAME = /^[\w.+-]+$/;
|
|
981
1185
|
var COMPRESSED_UNSUPPORTED = /\.(?:bz2|xz)$/;
|
|
@@ -994,7 +1198,7 @@ function manDirs(env) {
|
|
|
994
1198
|
const configured = env.MANPATH?.split(":").filter((dir) => dir !== "") ?? [];
|
|
995
1199
|
return [...configured, "/usr/share/man", "/usr/local/share/man", join6(homedir4(), ".local/share/man")];
|
|
996
1200
|
}
|
|
997
|
-
function findPage(name, env =
|
|
1201
|
+
function findPage(name, env = process16.env) {
|
|
998
1202
|
if (!SAFE_NAME.test(name))
|
|
999
1203
|
return;
|
|
1000
1204
|
for (const section of SECTIONS) {
|
|
@@ -1028,12 +1232,14 @@ function unOverstrike(text) {
|
|
|
1028
1232
|
return kept.join("");
|
|
1029
1233
|
}
|
|
1030
1234
|
function render(source) {
|
|
1031
|
-
|
|
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" } });
|
|
1032
1238
|
if (result.exitCode !== 0)
|
|
1033
1239
|
return;
|
|
1034
1240
|
return stripAnsi(unOverstrike(result.stdout.toString())).replaceAll(UNICODE_HYPHENS, "-");
|
|
1035
1241
|
}
|
|
1036
|
-
function pageText(name, env =
|
|
1242
|
+
function pageText(name, env = process16.env) {
|
|
1037
1243
|
const path = findPage(name, env);
|
|
1038
1244
|
const source = path === undefined ? undefined : readSource(path);
|
|
1039
1245
|
return source === undefined ? undefined : render(source);
|
|
@@ -1114,7 +1320,7 @@ function summaryOf(text) {
|
|
|
1114
1320
|
function parsePage(name, text) {
|
|
1115
1321
|
return { name, summary: summaryOf(text), options: parseOptions(text) };
|
|
1116
1322
|
}
|
|
1117
|
-
function loadPage(name, env =
|
|
1323
|
+
function loadPage(name, env = process16.env) {
|
|
1118
1324
|
const text = pageText(name, env);
|
|
1119
1325
|
return text === undefined ? undefined : parsePage(name, text);
|
|
1120
1326
|
}
|
|
@@ -1145,7 +1351,7 @@ function helpOf(path, args, env) {
|
|
|
1145
1351
|
${result.stderr.toString()}`);
|
|
1146
1352
|
return text.trim() === "" ? undefined : text;
|
|
1147
1353
|
}
|
|
1148
|
-
function loadHelp(name, subcommand, env =
|
|
1354
|
+
function loadHelp(name, subcommand, env = process17.env) {
|
|
1149
1355
|
if (!SAFE_NAME2.test(name))
|
|
1150
1356
|
return;
|
|
1151
1357
|
const path = Bun.which(name, { PATH: env.PATH ?? "" });
|
|
@@ -1237,7 +1443,7 @@ function explain(words, options) {
|
|
|
1237
1443
|
|
|
1238
1444
|
// src/shell.ts
|
|
1239
1445
|
var REDIRECT = /&>>?|>&|<&|<<<|<<-?|>>|>\||>|</y;
|
|
1240
|
-
var CONTROL2 =
|
|
1446
|
+
var CONTROL2 = /\|[&|]?|&&|&(?!>)|[;\n]/y;
|
|
1241
1447
|
var ASSIGN = /^[A-Z_]\w*\+?=/i;
|
|
1242
1448
|
var FD = /\d+(?=[<>])/y;
|
|
1243
1449
|
var ESCAPABLE_IN_QUOTES = new Set(['"', "\\", "$", "`"]);
|
|
@@ -1426,8 +1632,9 @@ function analyze(line, settings = {}, depth = 0) {
|
|
|
1426
1632
|
for (const { command, next } of parseLine(line)) {
|
|
1427
1633
|
const [head, second] = command.words;
|
|
1428
1634
|
const name = head?.text ?? "";
|
|
1429
|
-
const
|
|
1430
|
-
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));
|
|
1431
1638
|
const page = manual ?? (runHelp && head !== undefined ? loadHelp(name, second?.text, env) : undefined);
|
|
1432
1639
|
const fromHelp = manual === undefined && page !== undefined;
|
|
1433
1640
|
const words = command.words.slice(sub === undefined && !(fromHelp && page?.name.includes(" ")) ? 1 : 2);
|
|
@@ -1538,8 +1745,8 @@ function render2(line, stream = process.stdout, depth = 0) {
|
|
|
1538
1745
|
// src/gloss.ts
|
|
1539
1746
|
var USAGE = `gloss [options] <command line>: explains a shell command line, each option matched to what its man page says
|
|
1540
1747
|
|
|
1541
|
-
Quote the command line or put it after --: gloss -- tar -xzvf a.tgz. Without arguments
|
|
1542
|
-
|
|
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.`;
|
|
1543
1750
|
var EXITS = [[0, "it explained the line"], [2, "a usage error"]];
|
|
1544
1751
|
var OPTIONS = {
|
|
1545
1752
|
"run-help": { type: "boolean", description: "for a command with no man page, run `<command> --help` and read its options (runs the command)" },
|
|
@@ -1552,15 +1759,15 @@ function quote(word) {
|
|
|
1552
1759
|
async function main(args) {
|
|
1553
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"] });
|
|
1554
1761
|
const typed = [...positionals.map(String), ...(rest ?? []).map(quote)].join(" ");
|
|
1555
|
-
const line = typed === "" && !
|
|
1762
|
+
const line = typed === "" && !process18.stdin.isTTY ? (await Bun.stdin.text()).trim() : typed;
|
|
1556
1763
|
if (line === "")
|
|
1557
1764
|
badUsage("give the command line to explain, quoted or after --");
|
|
1558
1765
|
const result = analyze(line, { runHelp: values["run-help"] === true });
|
|
1559
1766
|
if (values.json === true)
|
|
1560
1767
|
printJson(result);
|
|
1561
1768
|
else
|
|
1562
|
-
console.log(render2(result,
|
|
1769
|
+
console.log(render2(result, process18.stdout).join(`
|
|
1563
1770
|
`));
|
|
1564
1771
|
return 0;
|
|
1565
1772
|
}
|
|
1566
|
-
|
|
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
|
}
|