@kaynooo/cli-gloss 0.0.3 → 0.0.5
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 +316 -125
- 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,6 +110,9 @@ 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";
|
|
@@ -118,36 +125,18 @@ function configBase(where = {}) {
|
|
|
118
125
|
function userConfigPath(bin, where = {}) {
|
|
119
126
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
120
127
|
}
|
|
128
|
+
var init_user_config = () => {};
|
|
121
129
|
|
|
122
130
|
// ../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+/;
|
|
131
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
132
|
+
import { homedir as homedir2 } from "os";
|
|
133
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
134
|
+
import process5 from "process";
|
|
145
135
|
function isColorSpec(spec) {
|
|
146
136
|
if (typeof spec === "number")
|
|
147
137
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
148
138
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
149
139
|
}
|
|
150
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
151
140
|
function cubeLevel(channel) {
|
|
152
141
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
153
142
|
}
|
|
@@ -252,7 +241,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
252
241
|
function endsWalk(home) {
|
|
253
242
|
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
254
243
|
}
|
|
255
|
-
var warned = new Set;
|
|
256
244
|
function warnOnce(message) {
|
|
257
245
|
if (warned.has(message))
|
|
258
246
|
return;
|
|
@@ -289,8 +277,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
289
277
|
}
|
|
290
278
|
return { theme, sources, preset };
|
|
291
279
|
}
|
|
292
|
-
var current;
|
|
293
|
-
var currentKey = "";
|
|
294
280
|
function activeTheme() {
|
|
295
281
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
296
282
|
if (current === undefined || key !== currentKey) {
|
|
@@ -299,8 +285,38 @@ function activeTheme() {
|
|
|
299
285
|
}
|
|
300
286
|
return current;
|
|
301
287
|
}
|
|
288
|
+
var ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
|
|
289
|
+
var init_theme = __esm(() => {
|
|
290
|
+
init_config();
|
|
291
|
+
init_user_config();
|
|
292
|
+
ENDS = new Map;
|
|
293
|
+
DEFAULT = {
|
|
294
|
+
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" },
|
|
295
|
+
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" },
|
|
296
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
297
|
+
bins: {},
|
|
298
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
299
|
+
};
|
|
300
|
+
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" };
|
|
301
|
+
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" };
|
|
302
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
303
|
+
PRESETS = {
|
|
304
|
+
default: {},
|
|
305
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
306
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
307
|
+
ascii: { glyphs: ASCII }
|
|
308
|
+
};
|
|
309
|
+
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"]);
|
|
310
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
311
|
+
CONTROL = /\p{Cc}/u;
|
|
312
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
313
|
+
SPACES = /\s+/;
|
|
314
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
315
|
+
warned = new Set;
|
|
316
|
+
});
|
|
302
317
|
|
|
303
318
|
// ../kit/src/style.ts
|
|
319
|
+
import process6 from "process";
|
|
304
320
|
function takesControlCodes(stream, env = process6.env) {
|
|
305
321
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
306
322
|
}
|
|
@@ -311,17 +327,23 @@ function role(name, stream, env = process6.env) {
|
|
|
311
327
|
const colors = paint(stream, env);
|
|
312
328
|
return takesControlCodes(stream, env) ? tinted(colors, activeTheme().theme.colors[name], env) : colors;
|
|
313
329
|
}
|
|
314
|
-
var STATUS_WORDS
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
330
|
+
var STATUS_WORDS, STATUS_OF;
|
|
331
|
+
var init_style = __esm(() => {
|
|
332
|
+
init_colors();
|
|
333
|
+
init_mode();
|
|
334
|
+
init_theme();
|
|
335
|
+
STATUS_WORDS = {
|
|
336
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
337
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
338
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
339
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
340
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
341
|
+
};
|
|
342
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
343
|
+
});
|
|
322
344
|
|
|
323
345
|
// ../kit/src/format.ts
|
|
324
|
-
|
|
346
|
+
import process7 from "process";
|
|
325
347
|
function formatSeconds(total) {
|
|
326
348
|
let rest = Math.max(0, Math.round(total));
|
|
327
349
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -342,21 +364,44 @@ function upTo(text, separator) {
|
|
|
342
364
|
const end = text.indexOf(separator);
|
|
343
365
|
return end === -1 ? text : text.slice(0, end);
|
|
344
366
|
}
|
|
345
|
-
var ESCAPE = String.fromCharCode(27);
|
|
346
367
|
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
347
368
|
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
348
369
|
}
|
|
349
370
|
function printJson(value) {
|
|
350
371
|
console.log(jsonText(value));
|
|
351
372
|
}
|
|
373
|
+
var UNITS, ESCAPE;
|
|
374
|
+
var init_format = __esm(() => {
|
|
375
|
+
init_mode();
|
|
376
|
+
init_style();
|
|
377
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
378
|
+
ESCAPE = String.fromCharCode(27);
|
|
379
|
+
});
|
|
352
380
|
|
|
353
381
|
// ../kit/src/help.ts
|
|
354
382
|
import process8 from "process";
|
|
355
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
356
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
357
|
-
var FULL_STOP = /\.$/;
|
|
358
383
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
359
|
-
|
|
384
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
385
|
+
`);
|
|
386
|
+
const blank = lines.indexOf("");
|
|
387
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
388
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
389
|
+
const colon = synopses[0].indexOf(": ");
|
|
390
|
+
const inline = synopses[0].slice(colon + 2);
|
|
391
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
392
|
+
if (colon !== -1)
|
|
393
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
394
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
395
|
+
`)}`;
|
|
396
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
397
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
398
|
+
return [head, ...lead, ...rest].join(`
|
|
399
|
+
`);
|
|
400
|
+
}
|
|
401
|
+
function prose(line, colors) {
|
|
402
|
+
if (colors.cyan("x") === "x")
|
|
403
|
+
return line;
|
|
404
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
360
405
|
}
|
|
361
406
|
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
362
407
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -391,7 +436,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
391
436
|
return [];
|
|
392
437
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
393
438
|
}
|
|
394
|
-
var MAX_INLINE_CHOICES = 24;
|
|
395
439
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
396
440
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
397
441
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -406,9 +450,17 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
406
450
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
407
451
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
408
452
|
}
|
|
453
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
454
|
+
var init_help = __esm(() => {
|
|
455
|
+
init_mode();
|
|
456
|
+
init_style();
|
|
457
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
458
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
459
|
+
FULL_STOP = /\.$/;
|
|
460
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
461
|
+
});
|
|
409
462
|
|
|
410
463
|
// ../kit/src/text.ts
|
|
411
|
-
var ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
412
464
|
function stripAnsi(text) {
|
|
413
465
|
return text.replace(ANSI, "");
|
|
414
466
|
}
|
|
@@ -437,36 +489,26 @@ function closest(name, names) {
|
|
|
437
489
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
438
490
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
439
491
|
}
|
|
492
|
+
var ANSI;
|
|
493
|
+
var init_text = __esm(() => {
|
|
494
|
+
ANSI = /\x1B(?:\[[\x30-\x3F]*[\x20-\x2F]*[\x40-\x7E]|\][^\x07\x1B]*(?:\x07|\x1B\\)|[\x40-\x5A\x5C-\x5F])/g;
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
// ../kit/src/input.ts
|
|
498
|
+
var init_input = __esm(() => {
|
|
499
|
+
init_args();
|
|
500
|
+
});
|
|
440
501
|
|
|
441
502
|
// ../kit/src/args.ts
|
|
442
|
-
|
|
503
|
+
import process9 from "process";
|
|
504
|
+
import { parseArgs } from "util";
|
|
443
505
|
function jsonOption(holds) {
|
|
444
506
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
445
507
|
}
|
|
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
508
|
function badUsage(message) {
|
|
461
509
|
throw new UsageError(message);
|
|
462
510
|
}
|
|
463
511
|
|
|
464
|
-
class HelpShown extends Exit {
|
|
465
|
-
constructor() {
|
|
466
|
-
super("help shown", 0);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
512
|
class Completing {
|
|
471
513
|
options;
|
|
472
514
|
positionals;
|
|
@@ -477,11 +519,6 @@ class Completing {
|
|
|
477
519
|
this.candidates = candidates;
|
|
478
520
|
}
|
|
479
521
|
}
|
|
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
522
|
function applyOutput(color, plain, env = process9.env) {
|
|
486
523
|
const when = plain === true ? "never" : color ?? "auto";
|
|
487
524
|
if (when === "auto")
|
|
@@ -635,7 +672,6 @@ function parseError(error) {
|
|
|
635
672
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
636
673
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
637
674
|
}
|
|
638
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
639
675
|
function nearestOption(message, options, allowNegative) {
|
|
640
676
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
641
677
|
if (typed === undefined)
|
|
@@ -651,6 +687,61 @@ function nearestOption(message, options, allowNegative) {
|
|
|
651
687
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
652
688
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
653
689
|
}
|
|
690
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
691
|
+
var init_args = __esm(() => {
|
|
692
|
+
init_format();
|
|
693
|
+
init_help();
|
|
694
|
+
init_text();
|
|
695
|
+
init_help();
|
|
696
|
+
init_input();
|
|
697
|
+
DASHES = /^-+/;
|
|
698
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
699
|
+
Exit = class Exit extends Error {
|
|
700
|
+
code;
|
|
701
|
+
hint;
|
|
702
|
+
[EXIT] = true;
|
|
703
|
+
constructor(message, code, hint) {
|
|
704
|
+
super(message);
|
|
705
|
+
this.code = code;
|
|
706
|
+
this.hint = hint;
|
|
707
|
+
}
|
|
708
|
+
static [Symbol.hasInstance](value) {
|
|
709
|
+
if (this !== Exit)
|
|
710
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
711
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
UsageError = class UsageError extends Exit {
|
|
715
|
+
constructor(message, hint) {
|
|
716
|
+
super(message, 2, hint);
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
HelpShown = class HelpShown extends Exit {
|
|
720
|
+
constructor() {
|
|
721
|
+
super("help shown", 0);
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
completion = { active: false };
|
|
725
|
+
OUTPUT_OPTIONS = {
|
|
726
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
727
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
728
|
+
};
|
|
729
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
730
|
+
});
|
|
731
|
+
|
|
732
|
+
// ../kit/src/folders.ts
|
|
733
|
+
var SKIPPED_FOLDERS;
|
|
734
|
+
var init_folders = __esm(() => {
|
|
735
|
+
init_user_config();
|
|
736
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
737
|
+
});
|
|
738
|
+
|
|
739
|
+
// src/gloss.ts
|
|
740
|
+
import process18 from "process";
|
|
741
|
+
|
|
742
|
+
// ../kit/src/index.ts
|
|
743
|
+
init_args();
|
|
744
|
+
|
|
654
745
|
// ../kit/src/argv.ts
|
|
655
746
|
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
656
747
|
import { resolve as resolve3 } from "path";
|
|
@@ -675,15 +766,73 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
|
|
|
675
766
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
676
767
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
677
768
|
}
|
|
769
|
+
// ../kit/src/chart.ts
|
|
770
|
+
init_format();
|
|
771
|
+
init_mode();
|
|
772
|
+
init_style();
|
|
773
|
+
init_theme();
|
|
774
|
+
// ../kit/src/ci.ts
|
|
775
|
+
init_args();
|
|
776
|
+
init_format();
|
|
777
|
+
|
|
678
778
|
// ../kit/src/progress.ts
|
|
779
|
+
init_format();
|
|
780
|
+
init_style();
|
|
781
|
+
init_theme();
|
|
679
782
|
var ESC = String.fromCharCode(27);
|
|
680
783
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
681
784
|
var RESET_STYLE = `${ESC}[0m`;
|
|
682
785
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
786
|
+
|
|
787
|
+
// ../kit/src/ci.ts
|
|
788
|
+
init_style();
|
|
789
|
+
|
|
790
|
+
// ../kit/src/tool.ts
|
|
791
|
+
init_format();
|
|
683
792
|
// ../kit/src/cli.ts
|
|
793
|
+
init_args();
|
|
684
794
|
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
685
795
|
import { dirname as dirname3, join as join5 } from "path";
|
|
686
|
-
import
|
|
796
|
+
import process14 from "process";
|
|
797
|
+
|
|
798
|
+
// ../kit/src/askpass.ts
|
|
799
|
+
import process11 from "process";
|
|
800
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
801
|
+
async function askpassClient(argv) {
|
|
802
|
+
const socketPath = process11.env[SOCKET_VARIABLE];
|
|
803
|
+
if (socketPath === undefined)
|
|
804
|
+
return;
|
|
805
|
+
const request = { prompt: argv[0] ?? "", ...process11.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
806
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
807
|
+
let received = "";
|
|
808
|
+
try {
|
|
809
|
+
await Bun.connect({
|
|
810
|
+
unix: socketPath,
|
|
811
|
+
socket: {
|
|
812
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
813
|
+
`),
|
|
814
|
+
data: (_, chunk) => {
|
|
815
|
+
received += chunk.toString();
|
|
816
|
+
},
|
|
817
|
+
close: () => resolve(received),
|
|
818
|
+
error: () => resolve("")
|
|
819
|
+
}
|
|
820
|
+
});
|
|
821
|
+
} catch {
|
|
822
|
+
return 1;
|
|
823
|
+
}
|
|
824
|
+
const reply = await promise;
|
|
825
|
+
if (reply === "")
|
|
826
|
+
return 1;
|
|
827
|
+
const { answer } = JSON.parse(reply);
|
|
828
|
+
if (request.notice === true)
|
|
829
|
+
return 0;
|
|
830
|
+
if (answer === undefined)
|
|
831
|
+
return 1;
|
|
832
|
+
process11.stdout.write(`${answer}
|
|
833
|
+
`);
|
|
834
|
+
return 0;
|
|
835
|
+
}
|
|
687
836
|
|
|
688
837
|
// ../kit/src/completions.ts
|
|
689
838
|
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
@@ -746,28 +895,34 @@ compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
|
746
895
|
}
|
|
747
896
|
|
|
748
897
|
// ../kit/src/notify.ts
|
|
749
|
-
|
|
898
|
+
init_format();
|
|
899
|
+
init_mode();
|
|
900
|
+
import process12 from "process";
|
|
750
901
|
var NOTIFY_AFTER_MS = 1e4;
|
|
751
902
|
var CANCELLED = 130;
|
|
752
903
|
function base64(text) {
|
|
753
904
|
return Buffer.from(text).toString("base64");
|
|
754
905
|
}
|
|
755
|
-
function notification(title, body, env =
|
|
756
|
-
const id = `kit${
|
|
906
|
+
function notification(title, body, env = process12.env) {
|
|
907
|
+
const id = `kit${process12.pid}`;
|
|
757
908
|
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
909
|
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
759
910
|
}
|
|
760
|
-
function notifyEnd(command, code, ms, { stream =
|
|
911
|
+
function notifyEnd(command, code, ms, { stream = process12.stderr, env = process12.env } = {}) {
|
|
761
912
|
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
762
913
|
return;
|
|
763
914
|
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
764
915
|
}
|
|
765
916
|
|
|
917
|
+
// ../kit/src/cli.ts
|
|
918
|
+
init_style();
|
|
919
|
+
init_text();
|
|
920
|
+
|
|
766
921
|
// ../kit/src/usage.ts
|
|
767
922
|
import { appendFileSync, mkdirSync } from "fs";
|
|
768
923
|
import { homedir as homedir3 } from "os";
|
|
769
924
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
770
|
-
import
|
|
925
|
+
import process13 from "process";
|
|
771
926
|
|
|
772
927
|
// ../kit/src/logs.ts
|
|
773
928
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -781,14 +936,14 @@ var usageError;
|
|
|
781
936
|
function noteUsageError(message) {
|
|
782
937
|
usageError = message;
|
|
783
938
|
}
|
|
784
|
-
function stateHome(env =
|
|
939
|
+
function stateHome(env = process13.env) {
|
|
785
940
|
const dir = env.XDG_STATE_HOME;
|
|
786
941
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
787
942
|
}
|
|
788
|
-
function usagePath(env =
|
|
943
|
+
function usagePath(env = process13.env) {
|
|
789
944
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
790
945
|
}
|
|
791
|
-
function usageRecorded(env =
|
|
946
|
+
function usageRecorded(env = process13.env) {
|
|
792
947
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
793
948
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
794
949
|
}
|
|
@@ -797,12 +952,12 @@ function flagNames(argv) {
|
|
|
797
952
|
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
953
|
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
799
954
|
}
|
|
800
|
-
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
955
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
801
956
|
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
802
957
|
usageError = undefined;
|
|
803
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
958
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
804
959
|
}
|
|
805
|
-
function recordUsage(entry, env =
|
|
960
|
+
function recordUsage(entry, env = process13.env) {
|
|
806
961
|
if (!usageRecorded(env))
|
|
807
962
|
return;
|
|
808
963
|
try {
|
|
@@ -824,8 +979,8 @@ var TOP_OPTIONS = {
|
|
|
824
979
|
completions: { type: "string", choices: COMPLETION_SHELLS, description: "print the shell completion script" }
|
|
825
980
|
};
|
|
826
981
|
function printError(prefix, message, hint, cause) {
|
|
827
|
-
const colors = paint(
|
|
828
|
-
const styled = takesControlCodes(
|
|
982
|
+
const colors = paint(process14.stderr);
|
|
983
|
+
const styled = takesControlCodes(process14.stderr);
|
|
829
984
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
830
985
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
831
986
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -936,6 +1091,9 @@ function packageVersion(entry = Bun.main) {
|
|
|
936
1091
|
}
|
|
937
1092
|
}
|
|
938
1093
|
async function runMain({ name, version, run, redact, usage }, argv = scriptArgs()) {
|
|
1094
|
+
const answered = await askpassClient(argv);
|
|
1095
|
+
if (answered !== undefined)
|
|
1096
|
+
return answered;
|
|
939
1097
|
if (argv[0] === COMPLETE)
|
|
940
1098
|
return printCandidates(leafCandidates(run, argv.slice(1)));
|
|
941
1099
|
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
@@ -954,28 +1112,61 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
954
1112
|
notifyEnd(name, code, performance.now() - started);
|
|
955
1113
|
if (usage !== false) {
|
|
956
1114
|
try {
|
|
957
|
-
recordUsage(usageEntry(name, undefined, argv, code));
|
|
1115
|
+
recordUsage(usageEntry(name, undefined, argv, code, { ms: performance.now() - started }));
|
|
958
1116
|
} catch {}
|
|
959
1117
|
}
|
|
960
1118
|
return code;
|
|
961
1119
|
}
|
|
962
|
-
|
|
963
|
-
|
|
1120
|
+
|
|
1121
|
+
// ../kit/src/index.ts
|
|
1122
|
+
init_config();
|
|
1123
|
+
|
|
1124
|
+
// ../kit/src/excerpt.ts
|
|
1125
|
+
init_text();
|
|
1126
|
+
|
|
1127
|
+
// ../kit/src/index.ts
|
|
1128
|
+
init_folders();
|
|
1129
|
+
init_format();
|
|
1130
|
+
|
|
1131
|
+
// ../kit/src/git.ts
|
|
1132
|
+
init_args();
|
|
1133
|
+
// ../kit/src/limit.ts
|
|
1134
|
+
init_args();
|
|
1135
|
+
|
|
1136
|
+
// ../kit/src/index.ts
|
|
1137
|
+
init_mode();
|
|
1138
|
+
|
|
1139
|
+
// ../kit/src/report.ts
|
|
1140
|
+
init_style();
|
|
1141
|
+
init_text();
|
|
964
1142
|
// ../kit/src/secrets.ts
|
|
965
1143
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
966
1144
|
// ../kit/src/sessions.ts
|
|
967
1145
|
var {Glob } = globalThis.Bun;
|
|
968
1146
|
var SESSION_FILES = new Glob("*.json");
|
|
969
1147
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1148
|
+
|
|
1149
|
+
// ../kit/src/index.ts
|
|
1150
|
+
init_style();
|
|
1151
|
+
init_text();
|
|
1152
|
+
init_theme();
|
|
1153
|
+
init_user_config();
|
|
1154
|
+
|
|
1155
|
+
// ../kit/src/watch.ts
|
|
1156
|
+
init_args();
|
|
1157
|
+
init_input();
|
|
1158
|
+
init_style();
|
|
1159
|
+
// ../kit/src/workspace-root.ts
|
|
1160
|
+
init_user_config();
|
|
970
1161
|
// src/help.ts
|
|
971
1162
|
import { tmpdir } from "os";
|
|
972
|
-
import
|
|
1163
|
+
import process17 from "process";
|
|
973
1164
|
|
|
974
1165
|
// src/man.ts
|
|
975
1166
|
import { existsSync as existsSync3, readdirSync, readFileSync as readFileSync4 } from "fs";
|
|
976
1167
|
import { homedir as homedir4 } from "os";
|
|
977
1168
|
import { join as join6 } from "path";
|
|
978
|
-
import
|
|
1169
|
+
import process16 from "process";
|
|
979
1170
|
var SECTIONS = ["1", "8", "6"];
|
|
980
1171
|
var SAFE_NAME = /^[\w.+-]+$/;
|
|
981
1172
|
var COMPRESSED_UNSUPPORTED = /\.(?:bz2|xz)$/;
|
|
@@ -994,7 +1185,7 @@ function manDirs(env) {
|
|
|
994
1185
|
const configured = env.MANPATH?.split(":").filter((dir) => dir !== "") ?? [];
|
|
995
1186
|
return [...configured, "/usr/share/man", "/usr/local/share/man", join6(homedir4(), ".local/share/man")];
|
|
996
1187
|
}
|
|
997
|
-
function findPage(name, env =
|
|
1188
|
+
function findPage(name, env = process16.env) {
|
|
998
1189
|
if (!SAFE_NAME.test(name))
|
|
999
1190
|
return;
|
|
1000
1191
|
for (const section of SECTIONS) {
|
|
@@ -1028,12 +1219,12 @@ function unOverstrike(text) {
|
|
|
1028
1219
|
return kept.join("");
|
|
1029
1220
|
}
|
|
1030
1221
|
function render(source) {
|
|
1031
|
-
const result = Bun.spawnSync(["nroff", "-man", "-Tutf8", "-rLL=200n", "-rLT=200n"], { stdin: source, stdout: "pipe", stderr: "ignore", env: { ...
|
|
1222
|
+
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
1223
|
if (result.exitCode !== 0)
|
|
1033
1224
|
return;
|
|
1034
1225
|
return stripAnsi(unOverstrike(result.stdout.toString())).replaceAll(UNICODE_HYPHENS, "-");
|
|
1035
1226
|
}
|
|
1036
|
-
function pageText(name, env =
|
|
1227
|
+
function pageText(name, env = process16.env) {
|
|
1037
1228
|
const path = findPage(name, env);
|
|
1038
1229
|
const source = path === undefined ? undefined : readSource(path);
|
|
1039
1230
|
return source === undefined ? undefined : render(source);
|
|
@@ -1114,7 +1305,7 @@ function summaryOf(text) {
|
|
|
1114
1305
|
function parsePage(name, text) {
|
|
1115
1306
|
return { name, summary: summaryOf(text), options: parseOptions(text) };
|
|
1116
1307
|
}
|
|
1117
|
-
function loadPage(name, env =
|
|
1308
|
+
function loadPage(name, env = process16.env) {
|
|
1118
1309
|
const text = pageText(name, env);
|
|
1119
1310
|
return text === undefined ? undefined : parsePage(name, text);
|
|
1120
1311
|
}
|
|
@@ -1145,7 +1336,7 @@ function helpOf(path, args, env) {
|
|
|
1145
1336
|
${result.stderr.toString()}`);
|
|
1146
1337
|
return text.trim() === "" ? undefined : text;
|
|
1147
1338
|
}
|
|
1148
|
-
function loadHelp(name, subcommand, env =
|
|
1339
|
+
function loadHelp(name, subcommand, env = process17.env) {
|
|
1149
1340
|
if (!SAFE_NAME2.test(name))
|
|
1150
1341
|
return;
|
|
1151
1342
|
const path = Bun.which(name, { PATH: env.PATH ?? "" });
|
|
@@ -1538,8 +1729,8 @@ function render2(line, stream = process.stdout, depth = 0) {
|
|
|
1538
1729
|
// src/gloss.ts
|
|
1539
1730
|
var USAGE = `gloss [options] <command line>: explains a shell command line, each option matched to what its man page says
|
|
1540
1731
|
|
|
1541
|
-
Quote the command line or put it after --: gloss -- tar -xzvf a.tgz. Without arguments
|
|
1542
|
-
|
|
1732
|
+
Quote the command line or put it after --: gloss -- tar -xzvf a.tgz. Without arguments it is read from stdin.
|
|
1733
|
+
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
1734
|
var EXITS = [[0, "it explained the line"], [2, "a usage error"]];
|
|
1544
1735
|
var OPTIONS = {
|
|
1545
1736
|
"run-help": { type: "boolean", description: "for a command with no man page, run `<command> --help` and read its options (runs the command)" },
|
|
@@ -1552,15 +1743,15 @@ function quote(word) {
|
|
|
1552
1743
|
async function main(args) {
|
|
1553
1744
|
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
1745
|
const typed = [...positionals.map(String), ...(rest ?? []).map(quote)].join(" ");
|
|
1555
|
-
const line = typed === "" && !
|
|
1746
|
+
const line = typed === "" && !process18.stdin.isTTY ? (await Bun.stdin.text()).trim() : typed;
|
|
1556
1747
|
if (line === "")
|
|
1557
1748
|
badUsage("give the command line to explain, quoted or after --");
|
|
1558
1749
|
const result = analyze(line, { runHelp: values["run-help"] === true });
|
|
1559
1750
|
if (values.json === true)
|
|
1560
1751
|
printJson(result);
|
|
1561
1752
|
else
|
|
1562
|
-
console.log(render2(result,
|
|
1753
|
+
console.log(render2(result, process18.stdout).join(`
|
|
1563
1754
|
`));
|
|
1564
1755
|
return 0;
|
|
1565
1756
|
}
|
|
1566
|
-
|
|
1757
|
+
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.5",
|
|
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.45.1"
|
|
39
39
|
}
|
|
40
40
|
}
|