@kaynooo/cli-wt 0.1.2 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -10
- package/dist/cli-0gbs87r4.js +313 -0
- package/dist/cli-1nyesy1b.js +674 -0
- package/dist/cli-4g5ehhgn.js +251 -0
- package/dist/cli-6ybxw5sc.js +97 -0
- package/dist/cli-dmkfxdbr.js +153 -0
- package/dist/cli-dmzvmpge.js +106 -0
- package/dist/cli-e2h20nyy.js +36 -0
- package/dist/cli-j82fak6j.js +69 -0
- package/dist/cli-k4471y24.js +779 -0
- package/dist/cli-kek450vq.js +519 -0
- package/dist/cli-n5rt07v7.js +105 -0
- package/dist/cli-pkvw2k4x.js +37 -0
- package/dist/cli-w4w36hng.js +67 -0
- package/dist/cli.js +238 -2592
- package/dist/commands-jtnbchtb.js +222 -0
- package/dist/init-4ynjrztr.js +166 -0
- package/dist/list-js6drtvg.js +88 -0
- package/dist/print-q6qaqg22.js +77 -0
- package/dist/prompt-y71tp3f5.js +436 -0
- package/dist/prune-beweag7w.js +17 -0
- package/dist/run-7eayrqwy.js +18 -0
- package/dist/shell-xrgvqrpp.js +55 -0
- package/dist/stack-h3pgyx1e.js +20 -0
- package/dist/tools-4j56r47a.js +13 -0
- package/package.json +6 -6
- package/src/cli.ts +270 -76
- package/src/commands.ts +58 -42
- package/src/compose.ts +37 -14
- package/src/config.ts +8 -1
- package/src/errors.ts +31 -5
- package/src/files.ts +15 -23
- package/src/git.ts +53 -7
- package/src/index.ts +3 -2
- package/src/init.ts +56 -10
- package/src/jobs.ts +60 -19
- package/src/list.ts +26 -13
- package/src/print.ts +76 -0
- package/src/project.ts +134 -23
- package/src/proxy.ts +9 -9
- package/src/prune.ts +149 -0
- package/src/queue.ts +27 -3
- package/src/run.ts +82 -23
- package/src/shell.ts +34 -7
- package/src/stack.ts +10 -12
- package/src/sync.ts +28 -3
- package/src/tools.ts +91 -0
|
@@ -0,0 +1,779 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// ../kit/src/args.ts
|
|
3
|
+
import process8 from "process";
|
|
4
|
+
import { parseArgs } from "util";
|
|
5
|
+
|
|
6
|
+
// ../kit/src/format.ts
|
|
7
|
+
import process6 from "process";
|
|
8
|
+
|
|
9
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rkhsft4a.js
|
|
10
|
+
var ot = /[.*+?^${}()|[\]\\]/g;
|
|
11
|
+
function U(t) {
|
|
12
|
+
return t.replace(ot, "\\$&");
|
|
13
|
+
}
|
|
14
|
+
var N = new Map;
|
|
15
|
+
var Nt = /\s+\S*$/;
|
|
16
|
+
var Y = /\s/;
|
|
17
|
+
function Ao(t, e, r = "...") {
|
|
18
|
+
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
19
|
+
if (t.length <= e)
|
|
20
|
+
return t;
|
|
21
|
+
let l = Math.max(0, e), c = t.substring(0, Math.max(0, s ? l - n.length : l));
|
|
22
|
+
if (o && !Y.test(t[c.length] ?? " "))
|
|
23
|
+
c = c.replace(Nt, "") || c;
|
|
24
|
+
if (o)
|
|
25
|
+
c = c.trimEnd();
|
|
26
|
+
return s ? (c + n).slice(0, l) : c + n;
|
|
27
|
+
}
|
|
28
|
+
var be = new Map(["\u20AC", "", "\u201A", "\u0192", "\u201E", "\u2026", "\u2020", "\u2021", "\u02C6", "\u2030", "\u0160", "\u2039", "\u0152", "", "\u017D", "", "", "\u2018", "\u2019", "\u201C", "\u201D", "\u2022", "\u2013", "\u2014", "\u02DC", "\u2122", "\u0161", "\u203A", "\u0153", "", "\u017E", "\u0178"].map((t, e) => [t, 128 + e]).filter(([t]) => t));
|
|
29
|
+
var W = new Map;
|
|
30
|
+
|
|
31
|
+
// ../kit/src/mode.ts
|
|
32
|
+
import process from "process";
|
|
33
|
+
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
34
|
+
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
35
|
+
function isSet(value) {
|
|
36
|
+
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
37
|
+
}
|
|
38
|
+
function outputMode(stream = process.stdout, env = process.env) {
|
|
39
|
+
const chosen = env.KIT_MODE;
|
|
40
|
+
if (chosen !== undefined && MODES.has(chosen))
|
|
41
|
+
return chosen;
|
|
42
|
+
if (AGENT_VARIABLES.some((name) => isSet(env[name])))
|
|
43
|
+
return "agent";
|
|
44
|
+
if (stream.isTTY === true)
|
|
45
|
+
return "terminal";
|
|
46
|
+
return isSet(env.CI) ? "ci" : "pipe";
|
|
47
|
+
}
|
|
48
|
+
function isInteractive(streams = process) {
|
|
49
|
+
return streams.stdin?.isTTY === true && streams.stderr?.isTTY === true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ../kit/src/style.ts
|
|
53
|
+
import process5 from "process";
|
|
54
|
+
|
|
55
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
56
|
+
var G2 = /^[a-f0-9]+$/i;
|
|
57
|
+
function b(r) {
|
|
58
|
+
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
59
|
+
if (!G2.test(e))
|
|
60
|
+
return [0, 0, 0];
|
|
61
|
+
if (e.length === 3 || e.length === 4)
|
|
62
|
+
return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
|
|
63
|
+
if (e.length !== 6 && e.length !== 8)
|
|
64
|
+
throw Error(`Invalid hex color length: ${e.length}`);
|
|
65
|
+
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
66
|
+
}
|
|
67
|
+
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") => {
|
|
68
|
+
let [l, n, c] = b(r);
|
|
69
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
70
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
71
|
+
var h = new Set(["", "1", "2", "3", "true"]);
|
|
72
|
+
function C(r, e = globalThis.process?.env ?? {}) {
|
|
73
|
+
if (e.FORCE_COLOR !== undefined)
|
|
74
|
+
return h.has(e.FORCE_COLOR);
|
|
75
|
+
if (e.NO_COLOR !== undefined || e.NODE_DISABLE_COLORS !== undefined || e.TERM === "dumb")
|
|
76
|
+
return false;
|
|
77
|
+
return r?.isTTY === true;
|
|
78
|
+
}
|
|
79
|
+
function f(r, e = []) {
|
|
80
|
+
let l = "", n = "";
|
|
81
|
+
for (let t = 0, i = e.length;t < i; t++)
|
|
82
|
+
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
83
|
+
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
84
|
+
return new Proxy(c, { get(t, i) {
|
|
85
|
+
let a = B[i];
|
|
86
|
+
if (Array.isArray(a)) {
|
|
87
|
+
let s = g.get(i);
|
|
88
|
+
if (s === undefined)
|
|
89
|
+
s = f(r, [...e, a]), g.set(i, s);
|
|
90
|
+
return s;
|
|
91
|
+
}
|
|
92
|
+
if (typeof a === "function")
|
|
93
|
+
return (...s) => {
|
|
94
|
+
let y = `${i}:${s.join(",")}`, u = g.get(y);
|
|
95
|
+
if (u === undefined) {
|
|
96
|
+
if (g.size >= 64)
|
|
97
|
+
g.clear();
|
|
98
|
+
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
99
|
+
}
|
|
100
|
+
return u;
|
|
101
|
+
};
|
|
102
|
+
throw Error(`Unknown style: ${String(i)}`);
|
|
103
|
+
} });
|
|
104
|
+
}
|
|
105
|
+
function Fe(r = {}) {
|
|
106
|
+
return f(r);
|
|
107
|
+
}
|
|
108
|
+
var o = Fe();
|
|
109
|
+
|
|
110
|
+
// ../kit/src/theme.ts
|
|
111
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
112
|
+
import { homedir as homedir2 } from "os";
|
|
113
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
114
|
+
import process4 from "process";
|
|
115
|
+
|
|
116
|
+
// ../kit/src/config.ts
|
|
117
|
+
import { existsSync } from "fs";
|
|
118
|
+
import { dirname, join, resolve } from "path";
|
|
119
|
+
import process2 from "process";
|
|
120
|
+
function findUp(names, from = process2.cwd(), stop = () => false) {
|
|
121
|
+
const wanted = typeof names === "string" ? [names] : names;
|
|
122
|
+
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
123
|
+
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
124
|
+
if (found !== undefined)
|
|
125
|
+
return found;
|
|
126
|
+
if (stop(dir) || dirname(dir) === dir)
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// ../kit/src/user-config.ts
|
|
132
|
+
import { homedir } from "os";
|
|
133
|
+
import { isAbsolute, join as join2 } from "path";
|
|
134
|
+
import process3 from "process";
|
|
135
|
+
function xdgFolder(value, fallback) {
|
|
136
|
+
return value !== undefined && isAbsolute(value) ? value : fallback;
|
|
137
|
+
}
|
|
138
|
+
function configBase(where = {}) {
|
|
139
|
+
const xdg = where.xdg ?? (where.home === undefined ? process3.env.XDG_CONFIG_HOME : undefined);
|
|
140
|
+
return xdgFolder(xdg, join2(where.home ?? homedir(), ".config"));
|
|
141
|
+
}
|
|
142
|
+
function userConfigPath(bin, where = {}) {
|
|
143
|
+
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ../kit/src/theme.ts
|
|
147
|
+
var ENDS = new Map;
|
|
148
|
+
var DEFAULT = {
|
|
149
|
+
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" },
|
|
150
|
+
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" },
|
|
151
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
152
|
+
bins: {},
|
|
153
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
154
|
+
};
|
|
155
|
+
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" };
|
|
156
|
+
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" };
|
|
157
|
+
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
158
|
+
var PRESETS = {
|
|
159
|
+
default: {},
|
|
160
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
161
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
162
|
+
ascii: { glyphs: ASCII }
|
|
163
|
+
};
|
|
164
|
+
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"]);
|
|
165
|
+
var HEX = /^#[0-9a-f]{6}$/i;
|
|
166
|
+
var CONTROL = /\p{Cc}/u;
|
|
167
|
+
var MAX_FILE_BYTES = 64 * 1024;
|
|
168
|
+
var SPACES = /\s+/;
|
|
169
|
+
function isColorSpec(spec) {
|
|
170
|
+
if (typeof spec === "number")
|
|
171
|
+
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
172
|
+
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
173
|
+
}
|
|
174
|
+
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
175
|
+
function cubeLevel(channel) {
|
|
176
|
+
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
177
|
+
}
|
|
178
|
+
function nearest256(hex) {
|
|
179
|
+
const rgb = [1, 3, 5].map((at) => Number.parseInt(hex.slice(at, at + 2), 16));
|
|
180
|
+
const levels = rgb.map(cubeLevel);
|
|
181
|
+
const cube = levels.map((level) => CUBE[level]);
|
|
182
|
+
const grey = Math.min(23, Math.max(0, Math.round((rgb.reduce((sum, channel) => sum + channel, 0) / 3 - 8) / 10)));
|
|
183
|
+
const greyValue = 8 + grey * 10;
|
|
184
|
+
const distance = (colour) => colour.reduce((sum, channel, at) => sum + (channel - rgb[at]) ** 2, 0);
|
|
185
|
+
return distance([greyValue, greyValue, greyValue]) < distance(cube) ? 232 + grey : 16 + 36 * levels[0] + 6 * levels[1] + levels[2];
|
|
186
|
+
}
|
|
187
|
+
function hasTrueColor(env) {
|
|
188
|
+
return env.COLORTERM === "truecolor" || env.COLORTERM === "24bit";
|
|
189
|
+
}
|
|
190
|
+
function tinted(colors, spec, env = process4.env) {
|
|
191
|
+
if (typeof spec === "number")
|
|
192
|
+
return colors.ansi256(spec);
|
|
193
|
+
return spec.trim().split(SPACES).reduce((chain, token) => {
|
|
194
|
+
if (HEX.test(token))
|
|
195
|
+
return hasTrueColor(env) ? chain.hex(token) : chain.ansi256(nearest256(token));
|
|
196
|
+
return chain[token] ?? chain;
|
|
197
|
+
}, colors);
|
|
198
|
+
}
|
|
199
|
+
function isRecord(value) {
|
|
200
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
201
|
+
}
|
|
202
|
+
function readThemeFile(path, warn) {
|
|
203
|
+
try {
|
|
204
|
+
const stat = statSync(path, { throwIfNoEntry: false });
|
|
205
|
+
if (stat === undefined)
|
|
206
|
+
return;
|
|
207
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) {
|
|
208
|
+
warn(`${path} is not a regular file under ${MAX_FILE_BYTES / 1024} KiB, theme ignored`);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
212
|
+
if (isRecord(parsed))
|
|
213
|
+
return parsed;
|
|
214
|
+
warn(`${path} is not a JSON object, theme ignored`);
|
|
215
|
+
} catch (error) {
|
|
216
|
+
warn(`${path} does not parse (${error instanceof Error ? error.message : String(error)}), theme ignored`);
|
|
217
|
+
}
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
function applyPreset(theme, name, warn, where) {
|
|
221
|
+
if (name === undefined)
|
|
222
|
+
return;
|
|
223
|
+
if (typeof name !== "string" || !Object.hasOwn(PRESETS, name)) {
|
|
224
|
+
warn(`${where}: no preset ${String(name)}, one of ${Object.keys(PRESETS).join(", ")}`);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const preset = PRESETS[name];
|
|
228
|
+
Object.assign(theme.colors, preset.colors);
|
|
229
|
+
Object.assign(theme.glyphs, preset.glyphs);
|
|
230
|
+
if (preset.accents !== undefined)
|
|
231
|
+
theme.accents = [...preset.accents];
|
|
232
|
+
if (Object.hasOwn(preset, "gradient"))
|
|
233
|
+
theme.gradient = preset.gradient;
|
|
234
|
+
return name;
|
|
235
|
+
}
|
|
236
|
+
function applyFile(theme, file, where, warn) {
|
|
237
|
+
if (isRecord(file.colors)) {
|
|
238
|
+
for (const [key, value] of Object.entries(file.colors)) {
|
|
239
|
+
if (!Object.hasOwn(DEFAULT.colors, key))
|
|
240
|
+
warn(`${where}: no colour ${key}, one of ${Object.keys(DEFAULT.colors).join(", ")}`);
|
|
241
|
+
else if (!isColorSpec(value))
|
|
242
|
+
warn(`${where}: colour ${key} is not an ANSI name, \`#rrggbb\` or a number up to 255`);
|
|
243
|
+
else
|
|
244
|
+
theme.colors[key] = value;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (isRecord(file.glyphs)) {
|
|
248
|
+
for (const [key, value] of Object.entries(file.glyphs)) {
|
|
249
|
+
if (!Object.hasOwn(DEFAULT.glyphs, key))
|
|
250
|
+
warn(`${where}: no glyph ${key}, one of ${Object.keys(DEFAULT.glyphs).join(", ")}`);
|
|
251
|
+
else if (typeof value !== "string" || CONTROL.test(value) || Bun.stringWidth(value) !== 1)
|
|
252
|
+
warn(`${where}: glyph ${key} must be one visible character wide, with no control character`);
|
|
253
|
+
else
|
|
254
|
+
theme.glyphs[key] = value;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (Array.isArray(file.accents) && file.accents.length > 0 && file.accents.every(isColorSpec))
|
|
258
|
+
theme.accents = [...file.accents];
|
|
259
|
+
else if (file.accents !== undefined)
|
|
260
|
+
warn(`${where}: accents must be a non-empty list of colours`);
|
|
261
|
+
if (file.gradient === null)
|
|
262
|
+
theme.gradient = undefined;
|
|
263
|
+
else if (Array.isArray(file.gradient) && file.gradient.length === 2 && file.gradient.every((end) => typeof end === "string" && HEX.test(end)))
|
|
264
|
+
theme.gradient = [file.gradient[0], file.gradient[1]];
|
|
265
|
+
else if (file.gradient !== undefined)
|
|
266
|
+
warn(`${where}: gradient must be two \`#rrggbb\` colours, or null for none`);
|
|
267
|
+
if (isRecord(file.bins)) {
|
|
268
|
+
for (const [bin, value] of Object.entries(file.bins)) {
|
|
269
|
+
if (isColorSpec(value))
|
|
270
|
+
theme.bins[bin] = value;
|
|
271
|
+
else
|
|
272
|
+
warn(`${where}: bin ${bin} has no valid colour`);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function endsWalk(home) {
|
|
277
|
+
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
278
|
+
}
|
|
279
|
+
var warned = new Set;
|
|
280
|
+
function warnOnce(message) {
|
|
281
|
+
if (warned.has(message))
|
|
282
|
+
return;
|
|
283
|
+
warned.add(message);
|
|
284
|
+
console.error(`warning: theme ${message}`);
|
|
285
|
+
}
|
|
286
|
+
function isPath(chosen) {
|
|
287
|
+
return chosen.includes("/") || chosen.endsWith(".json");
|
|
288
|
+
}
|
|
289
|
+
function loadTheme({ env = process4.env, from = process4.cwd(), home = homedir2(), warn = warnOnce } = {}) {
|
|
290
|
+
const theme = { colors: { ...DEFAULT.colors }, glyphs: { ...DEFAULT.glyphs }, accents: [...DEFAULT.accents], bins: Object.create(null), gradient: DEFAULT.gradient };
|
|
291
|
+
const sources = [];
|
|
292
|
+
const chosen = env.KIT_THEME ?? "";
|
|
293
|
+
const wanted = chosen === "" ? [userConfigPath("theme", { home, xdg: env.XDG_CONFIG_HOME }), findUp(join3(".kaynooo", "theme.json"), from, endsWalk(home))] : [];
|
|
294
|
+
if (isPath(chosen))
|
|
295
|
+
wanted.push(resolve2(from, chosen));
|
|
296
|
+
const files = [];
|
|
297
|
+
for (const path of wanted) {
|
|
298
|
+
const file = path === undefined ? undefined : readThemeFile(path, warn);
|
|
299
|
+
if (path !== undefined && file !== undefined)
|
|
300
|
+
files.push({ path, file });
|
|
301
|
+
}
|
|
302
|
+
let preset = "default";
|
|
303
|
+
if (chosen !== "" && !isPath(chosen)) {
|
|
304
|
+
preset = applyPreset(theme, chosen, warn, "KIT_THEME") ?? preset;
|
|
305
|
+
} else {
|
|
306
|
+
const named = files.findLast(({ file }) => file.preset !== undefined);
|
|
307
|
+
if (named !== undefined)
|
|
308
|
+
preset = applyPreset(theme, named.file.preset, warn, named.path) ?? preset;
|
|
309
|
+
}
|
|
310
|
+
for (const { path, file } of files) {
|
|
311
|
+
applyFile(theme, file, path, warn);
|
|
312
|
+
sources.push(path);
|
|
313
|
+
}
|
|
314
|
+
return { theme, sources, preset };
|
|
315
|
+
}
|
|
316
|
+
var current;
|
|
317
|
+
var currentKey = "";
|
|
318
|
+
function activeTheme() {
|
|
319
|
+
const key = `${process4.cwd()}\x00${process4.env.KIT_THEME ?? ""}\x00${process4.env.XDG_CONFIG_HOME ?? ""}`;
|
|
320
|
+
if (current === undefined || key !== currentKey) {
|
|
321
|
+
current = loadTheme();
|
|
322
|
+
currentKey = key;
|
|
323
|
+
}
|
|
324
|
+
return current;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// ../kit/src/style.ts
|
|
328
|
+
var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
329
|
+
function takesControlCodes(stream, env = process5.env) {
|
|
330
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
331
|
+
}
|
|
332
|
+
function paint(stream, env = process5.env) {
|
|
333
|
+
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
334
|
+
}
|
|
335
|
+
function marked(mark, text, stream, detail, env = process5.env) {
|
|
336
|
+
const colors = paint(stream, env);
|
|
337
|
+
let head = MARK_WORDS[mark];
|
|
338
|
+
if (takesControlCodes(stream, env)) {
|
|
339
|
+
const { theme } = activeTheme();
|
|
340
|
+
head = tinted(colors.bold, theme.colors[mark], env)(theme.glyphs[mark]);
|
|
341
|
+
}
|
|
342
|
+
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
343
|
+
}
|
|
344
|
+
function warn(text, detail) {
|
|
345
|
+
console.error(marked("warn", text, process5.stderr, detail));
|
|
346
|
+
}
|
|
347
|
+
var STATUS_WORDS = {
|
|
348
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
349
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
350
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
351
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
352
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
353
|
+
};
|
|
354
|
+
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
355
|
+
|
|
356
|
+
// ../kit/src/format.ts
|
|
357
|
+
var UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
358
|
+
function formatSeconds(total) {
|
|
359
|
+
let rest = Math.max(0, Math.round(total));
|
|
360
|
+
const amounts = UNITS.map(([unit, size]) => {
|
|
361
|
+
const amount = Math.floor(rest / size);
|
|
362
|
+
rest -= amount * size;
|
|
363
|
+
return `${amount}${unit}`;
|
|
364
|
+
});
|
|
365
|
+
const first = amounts.findIndex((amount) => !amount.startsWith("0"));
|
|
366
|
+
if (first === -1)
|
|
367
|
+
return "0s";
|
|
368
|
+
const next = amounts[first + 1];
|
|
369
|
+
return next === undefined || next.startsWith("0") ? amounts[first] ?? "0s" : `${amounts[first]} ${next}`;
|
|
370
|
+
}
|
|
371
|
+
function formatDuration(ms) {
|
|
372
|
+
return ms < 60000 ? `${(Math.max(0, ms) / 1000).toFixed(1)}s` : formatSeconds(ms / 1000);
|
|
373
|
+
}
|
|
374
|
+
function upTo(text, separator) {
|
|
375
|
+
const end = text.indexOf(separator);
|
|
376
|
+
return end === -1 ? text : text.slice(0, end);
|
|
377
|
+
}
|
|
378
|
+
function formatAge(date, now = Date.now()) {
|
|
379
|
+
const at = typeof date === "number" ? date : Date.parse(date);
|
|
380
|
+
if (Number.isNaN(at))
|
|
381
|
+
return "-";
|
|
382
|
+
const seconds = (now - at) / 1000;
|
|
383
|
+
return seconds < 60 ? "just now" : `${upTo(formatSeconds(seconds), " ")} ago`;
|
|
384
|
+
}
|
|
385
|
+
function truncate(text, width) {
|
|
386
|
+
return Ao(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
387
|
+
}
|
|
388
|
+
var LINE_BREAKS = /\s*\n\s*/g;
|
|
389
|
+
var ESCAPE = String.fromCharCode(27);
|
|
390
|
+
function textWidth(text) {
|
|
391
|
+
return Bun.stringWidth(text);
|
|
392
|
+
}
|
|
393
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process6.stdout, env = process6.env } = {}) {
|
|
394
|
+
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
395
|
+
if (outputMode(stream, env) === "agent")
|
|
396
|
+
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
397
|
+
`);
|
|
398
|
+
const widths = [];
|
|
399
|
+
for (const row of cells) {
|
|
400
|
+
for (const [index, cell] of row.entries())
|
|
401
|
+
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
402
|
+
}
|
|
403
|
+
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
404
|
+
const colors = paint(stream);
|
|
405
|
+
const lines = shown.map((row) => row.map((cell, index) => {
|
|
406
|
+
const width = widths[index] ?? 0;
|
|
407
|
+
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
408
|
+
if (align[index] === "right")
|
|
409
|
+
return `${gap}${cell}`;
|
|
410
|
+
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
411
|
+
}).join(" ").trimEnd());
|
|
412
|
+
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
413
|
+
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
414
|
+
`);
|
|
415
|
+
}
|
|
416
|
+
function narrow(rows, widths, limit) {
|
|
417
|
+
const used = () => widths.reduce((sum, width) => sum + width, 0) + 2 * Math.max(0, widths.length - 1);
|
|
418
|
+
const cuttable = (index) => rows.every((row) => !(row[index] ?? "").includes(ESCAPE));
|
|
419
|
+
const floor = 8;
|
|
420
|
+
while (used() > limit) {
|
|
421
|
+
let widest = -1;
|
|
422
|
+
for (const [index, width] of widths.entries()) {
|
|
423
|
+
if (cuttable(index) && width > floor && width > (widths[widest] ?? 0))
|
|
424
|
+
widest = index;
|
|
425
|
+
}
|
|
426
|
+
if (widest === -1)
|
|
427
|
+
break;
|
|
428
|
+
widths[widest] = Math.max(floor, (widths[widest] ?? 0) - (used() - limit));
|
|
429
|
+
}
|
|
430
|
+
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
431
|
+
}
|
|
432
|
+
function jsonText(value, replacer, { stream = process6.stdout, env = process6.env } = {}) {
|
|
433
|
+
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
434
|
+
}
|
|
435
|
+
function printJson(value) {
|
|
436
|
+
console.log(jsonText(value));
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// ../kit/src/help.ts
|
|
440
|
+
import process7 from "process";
|
|
441
|
+
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
442
|
+
var USAGE_PREFIX = /^usage:\s*/i;
|
|
443
|
+
var FULL_STOP = /\.$/;
|
|
444
|
+
var PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
445
|
+
function usageLine(usage, colors = paint(process7.stdout)) {
|
|
446
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
447
|
+
`);
|
|
448
|
+
const blank = lines.indexOf("");
|
|
449
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
450
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
451
|
+
const colon = synopses[0].indexOf(": ");
|
|
452
|
+
const inline = synopses[0].slice(colon + 2);
|
|
453
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
454
|
+
if (colon !== -1)
|
|
455
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
456
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
457
|
+
`)}`;
|
|
458
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
459
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
460
|
+
return [head, ...lead, ...rest].join(`
|
|
461
|
+
`);
|
|
462
|
+
}
|
|
463
|
+
function prose(line, colors) {
|
|
464
|
+
if (colors.cyan("x") === "x")
|
|
465
|
+
return line;
|
|
466
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
467
|
+
}
|
|
468
|
+
function helpText(usage, options, colors = paint(process7.stdout), { examples = [], exits = [] } = {}) {
|
|
469
|
+
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
470
|
+
`);
|
|
471
|
+
}
|
|
472
|
+
function exitRows(exits, colors = paint(process7.stdout)) {
|
|
473
|
+
if (exits.length === 0)
|
|
474
|
+
return [];
|
|
475
|
+
return ["", `${colors.bold("Exit codes:")} ${exits.map(([code, meaning]) => `${colors.cyan(String(code))} ${meaning}`).join(", ")}`];
|
|
476
|
+
}
|
|
477
|
+
function wantsHelpJson(env = process7.env) {
|
|
478
|
+
return env.KIT_HELP === "json";
|
|
479
|
+
}
|
|
480
|
+
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
481
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
482
|
+
`);
|
|
483
|
+
const first = lines[0];
|
|
484
|
+
const colon = first.indexOf(": ");
|
|
485
|
+
const prose = lines[lines.indexOf("") + 1] ?? "";
|
|
486
|
+
const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
|
|
487
|
+
return {
|
|
488
|
+
synopsis: colon === -1 ? first : first.slice(0, colon),
|
|
489
|
+
summary: colon === -1 ? fallback : first.slice(colon + 2),
|
|
490
|
+
...replaces === undefined ? {} : { replaces },
|
|
491
|
+
examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] }),
|
|
492
|
+
...exits === undefined ? {} : { exits: exits.map(([code, meaning]) => ({ code, meaning })) },
|
|
493
|
+
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
function exampleRows(examples, colors = paint(process7.stdout)) {
|
|
497
|
+
if (examples.length === 0 || outputMode() === "agent")
|
|
498
|
+
return [];
|
|
499
|
+
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
500
|
+
}
|
|
501
|
+
var MAX_INLINE_CHOICES = 24;
|
|
502
|
+
function optionRows(options, colors = paint(process7.stdout)) {
|
|
503
|
+
const rows = Object.entries(options).map(([name, option]) => {
|
|
504
|
+
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
505
|
+
const choices = option.choices?.join("|");
|
|
506
|
+
const inline = choices !== undefined && choices.length <= MAX_INLINE_CHOICES;
|
|
507
|
+
const named = inline ? `<${choices}>` : "<value>";
|
|
508
|
+
const placeholder = option.optional === undefined ? named : `[${named}]`;
|
|
509
|
+
const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
|
|
510
|
+
const described = choices === undefined || inline ? option.description ?? "" : [option.description, `one of ${option.choices.join(", ")}`].filter(Boolean).join("; ");
|
|
511
|
+
return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: described };
|
|
512
|
+
});
|
|
513
|
+
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
514
|
+
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// ../kit/src/text.ts
|
|
518
|
+
function distance(a, b) {
|
|
519
|
+
const left = [...a];
|
|
520
|
+
const right = [...b];
|
|
521
|
+
let before = [];
|
|
522
|
+
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
523
|
+
for (const [i, x] of left.entries()) {
|
|
524
|
+
const current = [i + 1];
|
|
525
|
+
for (const [j, y] of right.entries()) {
|
|
526
|
+
let cost = Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (x === y ? 0 : 1));
|
|
527
|
+
if (i > 0 && j > 0 && x === right[j - 1] && left[i - 1] === y)
|
|
528
|
+
cost = Math.min(cost, (before[j - 1] ?? 0) + 1);
|
|
529
|
+
current.push(cost);
|
|
530
|
+
}
|
|
531
|
+
before = previous;
|
|
532
|
+
previous = current;
|
|
533
|
+
}
|
|
534
|
+
return previous[right.length] ?? 0;
|
|
535
|
+
}
|
|
536
|
+
function closest(name, names) {
|
|
537
|
+
const started = names.find((known) => known.startsWith(name));
|
|
538
|
+
if (started !== undefined)
|
|
539
|
+
return started;
|
|
540
|
+
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
541
|
+
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// ../kit/src/args.ts
|
|
545
|
+
var DASHES = /^-+/;
|
|
546
|
+
function jsonOption(holds) {
|
|
547
|
+
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
548
|
+
}
|
|
549
|
+
var EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
550
|
+
|
|
551
|
+
class Exit extends Error {
|
|
552
|
+
code;
|
|
553
|
+
hint;
|
|
554
|
+
[EXIT] = true;
|
|
555
|
+
constructor(message, code, hint) {
|
|
556
|
+
super(message);
|
|
557
|
+
this.code = code;
|
|
558
|
+
this.hint = hint;
|
|
559
|
+
}
|
|
560
|
+
static [Symbol.hasInstance](value) {
|
|
561
|
+
if (this !== Exit)
|
|
562
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
563
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
function fail(message, code = 2, hint) {
|
|
567
|
+
throw new Exit(message, code, hint);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
class UsageError extends Exit {
|
|
571
|
+
constructor(message, hint) {
|
|
572
|
+
super(message, 2, hint);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
function badUsage(message) {
|
|
576
|
+
throw new UsageError(message);
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
class HelpShown extends Exit {
|
|
580
|
+
constructor() {
|
|
581
|
+
super("help shown", 0);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
class Completing {
|
|
586
|
+
options;
|
|
587
|
+
positionals;
|
|
588
|
+
candidates;
|
|
589
|
+
constructor(options, positionals = [], candidates = {}) {
|
|
590
|
+
this.options = options;
|
|
591
|
+
this.positionals = positionals;
|
|
592
|
+
this.candidates = candidates;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
var completion = { active: false };
|
|
596
|
+
var OUTPUT_OPTIONS = {
|
|
597
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
598
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
599
|
+
};
|
|
600
|
+
function applyOutput(color, plain, env = process8.env) {
|
|
601
|
+
const when = plain === true ? "never" : color ?? "auto";
|
|
602
|
+
if (when === "auto")
|
|
603
|
+
return;
|
|
604
|
+
if (when !== "always" && when !== "never")
|
|
605
|
+
badUsage(`--color takes auto, always or never, not ${when}`);
|
|
606
|
+
if (when === "always") {
|
|
607
|
+
env.FORCE_COLOR = "1";
|
|
608
|
+
delete env.NO_COLOR;
|
|
609
|
+
} else {
|
|
610
|
+
env.NO_COLOR = "1";
|
|
611
|
+
delete env.FORCE_COLOR;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
function parse(args, usage, options, settings = {}) {
|
|
615
|
+
const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
|
|
616
|
+
const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
|
|
617
|
+
const listing = listed(all, settings.allowNegative === true);
|
|
618
|
+
if (completion.active)
|
|
619
|
+
throw new Completing(listing, settings.positionals, settings.candidates);
|
|
620
|
+
const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
|
|
621
|
+
let parsed;
|
|
622
|
+
try {
|
|
623
|
+
parsed = parseArgs({ args: joinDashValues(withBare(withAliases(own, all), all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
|
|
624
|
+
} catch (error) {
|
|
625
|
+
const message = parseError(error);
|
|
626
|
+
throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
|
|
627
|
+
}
|
|
628
|
+
const values = parsed.values;
|
|
629
|
+
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
630
|
+
if (values.help === true) {
|
|
631
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings, listing)) : helpText(usage, listing, undefined, settings));
|
|
632
|
+
throw new HelpShown;
|
|
633
|
+
}
|
|
634
|
+
checkChoices(parsed.values, all);
|
|
635
|
+
checkConflicts(parsed.values, all);
|
|
636
|
+
if (settings.positionals !== undefined)
|
|
637
|
+
checkPositionals(parsed.positionals, settings.positionals);
|
|
638
|
+
return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
|
|
639
|
+
}
|
|
640
|
+
function splitRest(args, passes) {
|
|
641
|
+
const separator = passes ? args.indexOf("--") : -1;
|
|
642
|
+
return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
|
|
643
|
+
}
|
|
644
|
+
function splitTrailing(args, options, count) {
|
|
645
|
+
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
646
|
+
let seen = 0;
|
|
647
|
+
if (count === 0)
|
|
648
|
+
return { own: args, rest: undefined };
|
|
649
|
+
for (let at = 0;at < args.length; at++) {
|
|
650
|
+
const word = args[at];
|
|
651
|
+
if (word === "--")
|
|
652
|
+
break;
|
|
653
|
+
if (word.startsWith("-")) {
|
|
654
|
+
if (takesValue(word))
|
|
655
|
+
at++;
|
|
656
|
+
continue;
|
|
657
|
+
}
|
|
658
|
+
seen++;
|
|
659
|
+
if (seen === count)
|
|
660
|
+
return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
|
|
661
|
+
}
|
|
662
|
+
return { own: args, rest: undefined };
|
|
663
|
+
}
|
|
664
|
+
function listed(options, allowNegative) {
|
|
665
|
+
if (!allowNegative)
|
|
666
|
+
return options;
|
|
667
|
+
return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
|
|
668
|
+
if (option.type !== "boolean" || option.negative === undefined)
|
|
669
|
+
return [[name, option]];
|
|
670
|
+
return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
|
|
671
|
+
}));
|
|
672
|
+
}
|
|
673
|
+
function withAliases(args, options) {
|
|
674
|
+
const named = new Map(Object.entries(options).flatMap(([name, { aliases = [] }]) => aliases.map((alias) => [`--${alias}`, `--${name}`])));
|
|
675
|
+
if (named.size === 0)
|
|
676
|
+
return args;
|
|
677
|
+
const separator = args.indexOf("--");
|
|
678
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
679
|
+
return [...own.map((arg) => {
|
|
680
|
+
const at = arg.indexOf("=");
|
|
681
|
+
const current = named.get(at === -1 ? arg : arg.slice(0, at));
|
|
682
|
+
return current === undefined ? arg : `${current}${at === -1 ? "" : arg.slice(at)}`;
|
|
683
|
+
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
684
|
+
}
|
|
685
|
+
function withBare(args, options) {
|
|
686
|
+
const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
|
|
687
|
+
if (bare.size === 0)
|
|
688
|
+
return args;
|
|
689
|
+
const separator = args.indexOf("--");
|
|
690
|
+
const own = separator === -1 ? args : args.slice(0, separator);
|
|
691
|
+
return [...own.flatMap((arg, index) => {
|
|
692
|
+
const optional = bare.get(arg);
|
|
693
|
+
const next = own[index + 1];
|
|
694
|
+
const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
|
|
695
|
+
return optional === undefined || value ? [arg] : [arg, optional.bare];
|
|
696
|
+
}), ...separator === -1 ? [] : args.slice(separator)];
|
|
697
|
+
}
|
|
698
|
+
function checkConflicts(values, options) {
|
|
699
|
+
const given = (name) => values[name] !== undefined && values[name] !== false;
|
|
700
|
+
for (const [name, { conflicts = [] }] of Object.entries(options)) {
|
|
701
|
+
const other = given(name) ? conflicts.find(given) : undefined;
|
|
702
|
+
if (other !== undefined)
|
|
703
|
+
badUsage(`--${name} cannot be used with --${other}`);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
function checkChoices(values, options) {
|
|
707
|
+
for (const [name, option] of Object.entries(options)) {
|
|
708
|
+
if (option.choices === undefined)
|
|
709
|
+
continue;
|
|
710
|
+
const given = values[name];
|
|
711
|
+
for (const value of Array.isArray(given) ? given : [given]) {
|
|
712
|
+
if (typeof value === "string")
|
|
713
|
+
oneOf(value, name, option.choices);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
function oneOf(value, name, choices) {
|
|
718
|
+
if (!choices.includes(value))
|
|
719
|
+
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
|
|
720
|
+
return value;
|
|
721
|
+
}
|
|
722
|
+
function checkPositionals(given, names) {
|
|
723
|
+
const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
|
|
724
|
+
const required = names.filter((name) => !name.startsWith("[")).length;
|
|
725
|
+
if (given.length < required)
|
|
726
|
+
badUsage(`missing ${names[given.length]}`);
|
|
727
|
+
if (!variadic && given.length > names.length)
|
|
728
|
+
badUsage(`unexpected argument ${given[names.length]}`);
|
|
729
|
+
}
|
|
730
|
+
function joinDashValues(args, options) {
|
|
731
|
+
const longOf = new Map(Object.entries(options).flatMap(([name, option]) => option.short === undefined ? [[`--${name}`, name]] : [[`--${name}`, name], [`-${option.short}`, name]]));
|
|
732
|
+
const isOption = (arg) => arg === "--" || longOf.has(arg.includes("=") ? arg.slice(0, arg.indexOf("=")) : arg);
|
|
733
|
+
const joined = [];
|
|
734
|
+
for (let i = 0;i < args.length; i++) {
|
|
735
|
+
const arg = args[i] ?? "";
|
|
736
|
+
if (arg === "--")
|
|
737
|
+
return [...joined, ...args.slice(i)];
|
|
738
|
+
const name = longOf.get(arg);
|
|
739
|
+
const next = args[i + 1];
|
|
740
|
+
if (name !== undefined && options[name]?.type === "string" && next !== undefined && next.startsWith("-") && next !== "-" && !isOption(next)) {
|
|
741
|
+
joined.push(`--${name}=${next}`);
|
|
742
|
+
i++;
|
|
743
|
+
} else {
|
|
744
|
+
joined.push(arg);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
return joined;
|
|
748
|
+
}
|
|
749
|
+
function parseError(error) {
|
|
750
|
+
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
751
|
+
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
752
|
+
}
|
|
753
|
+
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
754
|
+
function nearestOption(message, options, allowNegative) {
|
|
755
|
+
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
756
|
+
if (typed === undefined)
|
|
757
|
+
return;
|
|
758
|
+
const word = typed.replace(DASHES, "");
|
|
759
|
+
if (word.length < 2 && !typed.startsWith("--"))
|
|
760
|
+
return;
|
|
761
|
+
const known = Object.entries(options).flatMap(([name, option]) => [
|
|
762
|
+
...option.short === undefined ? [] : [`-${option.short}`],
|
|
763
|
+
`--${name}`,
|
|
764
|
+
...allowNegative && option.type === "boolean" ? [`--no-${name}`] : []
|
|
765
|
+
]);
|
|
766
|
+
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
767
|
+
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
// ../kit/src/folders.ts
|
|
771
|
+
import { homedir as homedir3 } from "os";
|
|
772
|
+
import { join as join4 } from "path";
|
|
773
|
+
import process9 from "process";
|
|
774
|
+
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
775
|
+
function cacheFolder({ home = homedir3(), env = process9.env } = {}) {
|
|
776
|
+
return xdgFolder(env.XDG_CACHE_HOME, join4(home, ".cache"));
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
export { U, outputMode, isInteractive, xdgFolder, configBase, takesControlCodes, paint, warn, formatDuration, formatAge, truncate, textWidth, table, printJson, usageLine, wantsHelpJson, description, exampleRows, optionRows, closest, jsonOption, Exit, fail, UsageError, badUsage, HelpShown, Completing, completion, OUTPUT_OPTIONS, applyOutput, parse, cacheFolder };
|