@kaynooo/cli-docker 0.0.0-stage → 0.1.0

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/dc-cli.js ADDED
@@ -0,0 +1,953 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+
4
+ // src/dc-cli.ts
5
+ import process9 from "process";
6
+
7
+ // ../kit/src/args.ts
8
+ import process4 from "process";
9
+ import { parseArgs } from "util";
10
+
11
+ // ../kit/src/style.ts
12
+ import process2 from "process";
13
+
14
+ // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-mtetydvc.js
15
+ function x(s) {
16
+ let r = s.startsWith("#") ? s.slice(1).toLowerCase() : s.toLowerCase();
17
+ if (!/^[a-f0-9]+$/.test(r))
18
+ return [0, 0, 0];
19
+ let t = r.length, n = (c) => Number.parseInt(c, 16);
20
+ if (t === 3 || t === 4) {
21
+ let c = n(r[0] + r[0]), u = n(r[1] + r[1]), h = n(r[2] + r[2]), g = t === 4 ? n(r[3] + r[3]) : undefined;
22
+ return g !== undefined ? [c, u, h, g] : [c, u, h];
23
+ }
24
+ if (t !== 6 && t !== 8)
25
+ throw Error(`Invalid hex color length: ${t}`);
26
+ let a = n(r.slice(0, 2)), b = n(r.slice(2, 4)), o = n(r.slice(4, 6)), y = t === 8 ? n(r.slice(6, 8)) : undefined;
27
+ if ([a, b, o].some(Number.isNaN) || y !== undefined && Number.isNaN(y))
28
+ throw Error(`Invalid hex color value: ${s}`);
29
+ return y !== undefined ? [a, b, o, y] : [a, b, o];
30
+ }
31
+ function A(s) {
32
+ let [r, t, n, a] = s;
33
+ if (a)
34
+ return `#${(r << 24 | t << 16 | n << 8 | Math.round((a ?? 1) * 255)).toString(16).padStart(8, "0").toUpperCase()}`;
35
+ return `#${(r << 16 | t << 8 | n).toString(16).padStart(6, "0").toUpperCase()}`;
36
+ }
37
+ function R(s, r, t) {
38
+ s = (s % 360 + 360) % 360, t /= 100;
39
+ let n = r * Math.min(t, 1 - t) / 100, a = (b) => {
40
+ let o = (b + s / 30) % 12, y = t - n * Math.max(Math.min(o - 3, 9 - o, 1), -1);
41
+ return Math.round(255 * y);
42
+ };
43
+ return [a(0), a(8), a(4)];
44
+ }
45
+ function k(s) {
46
+ let [r, t, n] = s;
47
+ r /= 255, t /= 255, n /= 255;
48
+ let a = Math.max(r, t, n), b = Math.min(r, t, n), o = 0, y = 0, c = (a + b) / 2;
49
+ if (a !== b) {
50
+ let u = a - b;
51
+ if (y = c > 0 && c < 1 ? u / (1 - Math.abs(2 * c - 1)) : 0, a === r)
52
+ o = (t - n) / u + (t < n ? 6 : 0);
53
+ else if (a === t)
54
+ o = (n - r) / u + 2;
55
+ else
56
+ o = (r - t) / u + 4;
57
+ o /= 6;
58
+ }
59
+ return [Math.round(o * 360), Math.round(y * 100), Math.round(c * 100)];
60
+ }
61
+ function H(s, r, t) {
62
+ s = (s % 360 + 360) % 360, r /= 100, t /= 100;
63
+ let n = (a) => {
64
+ let b = (a + s / 60) % 6, o = t - t * r * Math.max(Math.min(b, 4 - b, 1), 0);
65
+ return Math.round(255 * o);
66
+ };
67
+ return [n(5), n(3), n(1)];
68
+ }
69
+ function f(s) {
70
+ let [r, t, n] = s;
71
+ r /= 255, t /= 255, n /= 255;
72
+ let a = Math.max(r, t, n), b = Math.min(r, t, n), o = a - b, y = 0, c = a === 0 ? 0 : o / a, u = a;
73
+ if (o !== 0) {
74
+ if (a === r)
75
+ y = (t - n) / o + (t < n ? 6 : 0);
76
+ else if (a === t)
77
+ y = (n - r) / o + 2;
78
+ else
79
+ y = (r - t) / o + 4;
80
+ y /= 6;
81
+ }
82
+ return [Math.round(y * 360), Math.round(c * 100), Math.round(u * 100)];
83
+ }
84
+ function O(s) {
85
+ let r = s[0] / 255, t = s[1] / 255, n = s[2] / 255, a = 1 - Math.max(r, t, n);
86
+ if (a === 1)
87
+ return [0, 0, 0, 100];
88
+ let b = (1 - r - a) / (1 - a), o = (1 - t - a) / (1 - a), y = (1 - n - a) / (1 - a);
89
+ return [Math.round(b * 100), Math.round(o * 100), Math.round(y * 100), Math.round(a * 100)];
90
+ }
91
+ function v(s, r, t, n) {
92
+ return s /= 100, r /= 100, t /= 100, n /= 100, [Math.round(255 * (1 - s) * (1 - n)), Math.round(255 * (1 - r) * (1 - n)), Math.round(255 * (1 - t) * (1 - n))];
93
+ }
94
+ var m = (s) => s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
95
+ var p = (s) => s <= 0.0031308 ? 12.92 * s : 1.055 * s ** 0.4166666666666667 - 0.055;
96
+ var i = (s, r) => Math.round(s * 10 ** r) / 10 ** r;
97
+ function T(s) {
98
+ let r = m(s[0] / 255), t = m(s[1] / 255), n = m(s[2] / 255), a = Math.cbrt(0.4122214708 * r + 0.5363325363 * t + 0.0514459929 * n), b = Math.cbrt(0.2119034982 * r + 0.6806995451 * t + 0.1073969566 * n), o = Math.cbrt(0.0883024619 * r + 0.2817188376 * t + 0.6299787005 * n);
99
+ return [i(0.2104542553 * a + 0.793617785 * b - 0.0040720468 * o, 4), i(1.9779984951 * a - 2.428592205 * b + 0.4505937099 * o, 4), i(0.0259040371 * a + 0.7827717662 * b - 0.808675766 * o, 4)];
100
+ }
101
+ function M(s, r, t) {
102
+ let n = (s + 0.3963377774 * r + 0.2158037573 * t) ** 3, a = (s - 0.1055613458 * r - 0.0638541728 * t) ** 3, b = (s - 0.0894841775 * r - 1.291485548 * t) ** 3, o = p(4.0767416621 * n - 3.3077115913 * a + 0.2309699292 * b), y = p(-1.2684380046 * n + 2.6097574011 * a - 0.3413193965 * b), c = p(-0.0041960863 * n - 0.7034186147 * a + 1.707614701 * b), u = (h) => Math.min(255, Math.max(0, Math.round(h * 255)));
103
+ return [u(o), u(y), u(c)];
104
+ }
105
+ function d(s) {
106
+ let [r, t, n] = T(s), a = Math.sqrt(t * t + n * n), b = (Math.atan2(n, t) * 180 / Math.PI + 360) % 360;
107
+ return [i(r, 4), i(a, 4), i(b, 2)];
108
+ }
109
+ function C(s, r, t) {
110
+ let n = t * Math.PI / 180;
111
+ return M(s, r * Math.cos(n), r * Math.sin(n));
112
+ }
113
+ function l(s) {
114
+ let r = s / 255;
115
+ return r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4;
116
+ }
117
+
118
+ class e {
119
+ r;
120
+ g;
121
+ b;
122
+ a;
123
+ constructor(s, r, t, n = 1) {
124
+ this.r = s, this.g = r, this.b = t, this.a = n;
125
+ }
126
+ static from(s, r) {
127
+ if (s === "hex") {
128
+ let [t, n, a, b] = x(r);
129
+ return new e(t, n, a, b);
130
+ }
131
+ if (s === "rgb") {
132
+ if (Array.isArray(r)) {
133
+ let [o, y, c, u] = r;
134
+ return new e(o, y, c, u);
135
+ }
136
+ let { r: t, g: n, b: a, a: b } = r;
137
+ return new e(t, n, a, b);
138
+ }
139
+ if (s === "hsl") {
140
+ let t, n, a, b;
141
+ if (Array.isArray(r))
142
+ [t, n, a, b] = r;
143
+ else
144
+ ({ h: t, s: n, l: a, a: b } = r);
145
+ let [o, y, c] = R(t, n, a);
146
+ return new e(o, y, c, b);
147
+ }
148
+ if (s === "hsv") {
149
+ let t, n, a, b;
150
+ if (Array.isArray(r))
151
+ [t, n, a, b] = r;
152
+ else
153
+ ({ h: t, s: n, v: a, a: b } = r);
154
+ let [o, y, c] = H(t, n, a);
155
+ return new e(o, y, c, b);
156
+ }
157
+ if (s === "cmyk") {
158
+ let t, n, a, b, o;
159
+ if (Array.isArray(r))
160
+ [t, n, a, b, o] = r;
161
+ else
162
+ ({ c: t, m: n, y: a, k: b, a: o } = r);
163
+ let [y, c, u] = v(t, n, a, b);
164
+ return new e(y, c, u, o);
165
+ }
166
+ if (s === "oklch") {
167
+ let t, n, a, b;
168
+ if (Array.isArray(r))
169
+ [t, n, a, b] = r;
170
+ else
171
+ ({ l: t, c: n, h: a, a: b } = r);
172
+ let [o, y, c] = C(t, n, a);
173
+ return new e(o, y, c, b);
174
+ }
175
+ if (s === "oklab") {
176
+ let t, n, a, b;
177
+ if (Array.isArray(r))
178
+ [t, n, a, b] = r;
179
+ else
180
+ ({ l: t, a: n, b: a, alpha: b } = r);
181
+ let [o, y, c] = M(t, n, a);
182
+ return new e(o, y, c, b);
183
+ }
184
+ throw Error("Invalid input");
185
+ }
186
+ to(s) {
187
+ switch (s) {
188
+ case "rgb":
189
+ return [this.r, this.g, this.b];
190
+ case "rgba":
191
+ return [this.r, this.g, this.b, this.a];
192
+ case "hex":
193
+ return A([this.r, this.g, this.b]);
194
+ case "hexa":
195
+ return A([this.r, this.g, this.b, this.a]);
196
+ case "hsl":
197
+ return k([this.r, this.g, this.b]);
198
+ case "hsla":
199
+ return [...k([this.r, this.g, this.b]), this.a];
200
+ case "hsv":
201
+ return f([this.r, this.g, this.b]);
202
+ case "hsva":
203
+ return [...f([this.r, this.g, this.b]), this.a];
204
+ case "cmyk":
205
+ return O([this.r, this.g, this.b]);
206
+ case "cmyka":
207
+ return [...O([this.r, this.g, this.b]), this.a];
208
+ case "oklch":
209
+ return d([this.r, this.g, this.b]);
210
+ case "oklcha":
211
+ return [...d([this.r, this.g, this.b]), this.a];
212
+ case "oklab":
213
+ return T([this.r, this.g, this.b]);
214
+ case "oklaba":
215
+ return [...T([this.r, this.g, this.b]), this.a];
216
+ default:
217
+ return [this.r, this.g, this.b];
218
+ }
219
+ }
220
+ getLuminance() {
221
+ let s = l(this.r), r = l(this.g), t = l(this.b);
222
+ return 0.2126 * s + 0.7152 * r + 0.0722 * t;
223
+ }
224
+ contrastRatio(s) {
225
+ let r = this.getLuminance(), t = s.getLuminance(), [n, a] = r >= t ? [r, t] : [t, r];
226
+ return (n + 0.05) / (a + 0.05);
227
+ }
228
+ bestContrastForeground() {
229
+ let s = new e(255, 255, 255, 1), r = new e(0, 0, 0, 1), t = this.contrastRatio(s), n = this.contrastRatio(r);
230
+ return t >= n ? s : r;
231
+ }
232
+ }
233
+
234
+ // ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
235
+ var r = 39;
236
+ var o = 49;
237
+ var f2 = "\x1B[";
238
+ var C2 = { 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, r], red: [31, r], green: [32, r], yellow: [33, r], blue: [34, r], magenta: [35, r], cyan: [36, r], white: [37, r], gray: [90, r], grey: [90, r], blackBright: [90, r], redBright: [91, r], greenBright: [92, r], yellowBright: [93, r], blueBright: [94, r], magentaBright: [95, r], cyanBright: [96, r], whiteBright: [97, r], bgBlack: [40, o], bgRed: [41, o], bgGreen: [42, o], bgYellow: [43, o], bgBlue: [44, o], bgMagenta: [45, o], bgCyan: [46, o], bgWhite: [47, o], bgBlackBright: [100, o], bgRedBright: [101, o], bgGreenBright: [102, o], bgYellowBright: [103, o], bgBlueBright: [104, o], bgMagentaBright: [105, o], bgCyanBright: [106, o], bgWhiteBright: [107, o], rgb: (i, n, a, l = "fg") => [`${l === "fg" ? 38 : 48};2;${i};${n};${a}`, l === "fg" ? r : o], hex: (i, n = "fg") => {
239
+ let [a, l, s] = e.from("hex", i).to("rgb");
240
+ return [`${n === "fg" ? 38 : 48};2;${a};${l};${s}`, n === "fg" ? r : o];
241
+ }, ansi256: (i, n = "fg") => [`${n === "fg" ? 38 : 48};5;${i}`, n === "fg" ? r : o] };
242
+ var b = new Set(["", "1", "2", "3", "true"]);
243
+ function h(i, n = globalThis.process?.env ?? {}) {
244
+ if (n.FORCE_COLOR !== undefined)
245
+ return b.has(n.FORCE_COLOR);
246
+ if (n.NO_COLOR !== undefined || n.NODE_DISABLE_COLORS !== undefined || n.TERM === "dumb")
247
+ return false;
248
+ return i?.isTTY === true;
249
+ }
250
+ function d2(i, n, a) {
251
+ if (!h(a.stream ?? globalThis.process?.stdout, a.env))
252
+ return n;
253
+ let l = "", s = "";
254
+ for (let g = 0, y = i.length;g < y; g++) {
255
+ let [c, p] = i[g];
256
+ l += `${f2}${c}m`, s = `${f2}${p}m${s}`;
257
+ }
258
+ return l + n + s;
259
+ }
260
+ function u(i, n = []) {
261
+ return new Proxy((l) => d2(n, l, i), { get(l, s) {
262
+ let g = C2[s];
263
+ if (Array.isArray(g))
264
+ return u(i, [...n, g]);
265
+ if (typeof g === "function")
266
+ return (...y) => u(i, [...n, g(...y)]);
267
+ throw Error(`Unknown style: ${String(s)}`);
268
+ } });
269
+ }
270
+ function le(i = {}) {
271
+ return u(i);
272
+ }
273
+ var t = le();
274
+
275
+ // ../kit/src/style.ts
276
+ function takesControlCodes(stream, env = process2.env) {
277
+ return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
278
+ }
279
+ function paint(stream, env = process2.env) {
280
+ return le({ stream: { isTTY: takesControlCodes(stream, env) }, env });
281
+ }
282
+ var STATUSES = {
283
+ passed: { symbol: "\u2713", words: ["passed", "success", "succeeded", "ok"], paint: (colors) => colors.green },
284
+ failed: { symbol: "\u2717", words: ["failed", "failure", "error", "errored"], paint: (colors) => colors.red },
285
+ running: { symbol: "\u25CF", words: ["running", "in_progress", "started"], paint: (colors) => colors.cyan },
286
+ queued: { symbol: "\u25CB", words: ["queued", "waiting", "pending", "created", "blocked", "scheduled"], paint: (colors) => colors.yellow },
287
+ skipped: { symbol: "-", words: ["skipped", "cancelled", "canceled", "manual"], paint: (colors) => colors.dim }
288
+ };
289
+ var STATUS_OF = new Map(Object.entries(STATUSES).flatMap(([status, { words }]) => words.map((word) => [word, status])));
290
+
291
+ // ../kit/src/format.ts
292
+ function upTo(text, separator) {
293
+ const end = text.indexOf(separator);
294
+ return end === -1 ? text : text.slice(0, end);
295
+ }
296
+ var ESCAPE = String.fromCharCode(27);
297
+ function printJson(value) {
298
+ console.log(JSON.stringify(value, undefined, 2));
299
+ }
300
+
301
+ // ../kit/src/help.ts
302
+ import process3 from "process";
303
+ var OPTIONAL = /\[[^\]]+\]/g;
304
+ var USAGE_PREFIX = /^usage:\s*/i;
305
+ var FULL_STOP = /\.$/;
306
+ function usageLine(usage, colors = paint(process3.stdout)) {
307
+ return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
308
+ }
309
+ function helpText(usage, options, colors = paint(process3.stdout), { examples = [], replaces } = {}) {
310
+ return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exampleRows(examples, colors)].join(`
311
+ `);
312
+ }
313
+ function replacesRows(replaces, colors = paint(process3.stdout)) {
314
+ return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
315
+ }
316
+ function wantsHelpJson(env = process3.env) {
317
+ return env.KIT_HELP === "json";
318
+ }
319
+ function description(usage, { examples = [], replaces } = {}) {
320
+ const lines = usage.replace(USAGE_PREFIX, "").split(`
321
+ `);
322
+ const first = lines[0];
323
+ const colon = first.indexOf(": ");
324
+ const prose = lines[lines.indexOf("") + 1] ?? "";
325
+ const fallback = lines.includes("") ? `${prose.charAt(0).toLowerCase()}${prose.slice(1)}`.replace(FULL_STOP, "") : "";
326
+ return {
327
+ synopsis: colon === -1 ? first : first.slice(0, colon),
328
+ summary: colon === -1 ? fallback : first.slice(colon + 2),
329
+ ...replaces === undefined ? {} : { replaces },
330
+ examples: examples.map((example) => typeof example === "string" ? { line: example } : { line: example[0], note: example[1] })
331
+ };
332
+ }
333
+ function exampleRows(examples, colors = paint(process3.stdout)) {
334
+ if (examples.length === 0)
335
+ return [];
336
+ return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
337
+ }
338
+ function optionRows(options, colors = paint(process3.stdout)) {
339
+ const rows = Object.entries(options).map(([name, option]) => {
340
+ const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
341
+ const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
342
+ const placeholder = option.optional === undefined ? named : `[${named}]`;
343
+ const value = option.type === "string" ? ` ${colors.dim(placeholder)}` : "";
344
+ return { flag: `${short}${colors.cyan(`--${name}`)}${value}`, width: `-x, --${name}`.length + (option.type === "string" ? placeholder.length + 1 : 0), description: option.description ?? "" };
345
+ });
346
+ const width = Math.max(0, ...rows.map((row) => row.width));
347
+ return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
348
+ }
349
+
350
+ // ../kit/src/text.ts
351
+ var ANSI = new RegExp(`${String.fromCharCode(27)}\\[[\\d;?]*[a-z]`, "gi");
352
+ function distance(a, b) {
353
+ let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
354
+ for (const [i, left] of [...a].entries()) {
355
+ const current = [i + 1];
356
+ for (const [j, right] of [...b].entries())
357
+ current.push(Math.min((previous[j + 1] ?? 0) + 1, (current[j] ?? 0) + 1, (previous[j] ?? 0) + (left === right ? 0 : 1)));
358
+ previous = current;
359
+ }
360
+ return previous[b.length] ?? 0;
361
+ }
362
+ function closest(name, names) {
363
+ const started = names.find((known) => known.startsWith(name));
364
+ if (started !== undefined)
365
+ return started;
366
+ const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
367
+ return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
368
+ }
369
+
370
+ // ../kit/src/args.ts
371
+ var DASHES = /^-+/;
372
+ function jsonOption(holds) {
373
+ return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
374
+ }
375
+
376
+ class Exit extends Error {
377
+ code;
378
+ hint;
379
+ constructor(message, code, hint) {
380
+ super(message);
381
+ this.code = code;
382
+ this.hint = hint;
383
+ }
384
+ }
385
+ function fail(message, code = 2, hint) {
386
+ throw new Exit(message, code, hint);
387
+ }
388
+
389
+ class UsageError extends Exit {
390
+ constructor(message, hint) {
391
+ super(message, 2, hint);
392
+ }
393
+ }
394
+ function badUsage(message) {
395
+ throw new UsageError(message);
396
+ }
397
+
398
+ class HelpShown extends Exit {
399
+ constructor() {
400
+ super("help shown", 0);
401
+ }
402
+ }
403
+
404
+ class Completing {
405
+ options;
406
+ positionals;
407
+ candidates;
408
+ constructor(options, positionals = [], candidates = {}) {
409
+ this.options = options;
410
+ this.positionals = positionals;
411
+ this.candidates = candidates;
412
+ }
413
+ }
414
+ var completion = { active: false };
415
+ var OUTPUT_OPTIONS = {
416
+ color: { type: "string", description: "auto (on a terminal alone), always or never" },
417
+ plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
418
+ };
419
+ function applyOutput(color, plain, env = process4.env) {
420
+ const when = plain === true ? "never" : color ?? "auto";
421
+ if (when === "auto")
422
+ return;
423
+ if (when !== "always" && when !== "never")
424
+ badUsage(`--color takes auto, always or never, not ${when}`);
425
+ if (when === "always") {
426
+ env.FORCE_COLOR = "1";
427
+ delete env.NO_COLOR;
428
+ } else {
429
+ env.NO_COLOR = "1";
430
+ delete env.FORCE_COLOR;
431
+ }
432
+ }
433
+ function parse(args, usage, options, settings = {}) {
434
+ const output = Object.fromEntries(Object.entries(OUTPUT_OPTIONS).filter(([name]) => !(name in options)));
435
+ const all = { ...options, ...output, help: { type: "boolean", short: "h", description: "show this help" } };
436
+ const listing = listed(all, settings.allowNegative === true);
437
+ if (completion.active)
438
+ throw new Completing(listing, settings.positionals, settings.candidates);
439
+ const { own, rest } = settings.trailing === true ? splitTrailing(args, all, settings.positionals?.length ?? 0) : splitRest(args, settings.rest === true);
440
+ let parsed;
441
+ try {
442
+ parsed = parseArgs({ args: joinDashValues(withBare(own, all), all), options: all, allowPositionals: true, allowNegative: settings.allowNegative === true, strict: true });
443
+ } catch (error) {
444
+ const message = parseError(error);
445
+ throw new UsageError(message, nearestOption(message, all, settings.allowNegative === true));
446
+ }
447
+ const values = parsed.values;
448
+ applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
449
+ if (values.help === true) {
450
+ console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings)) : helpText(usage, listing, undefined, settings));
451
+ throw new HelpShown;
452
+ }
453
+ checkChoices(parsed.values, all);
454
+ checkConflicts(parsed.values, all);
455
+ if (settings.positionals !== undefined)
456
+ checkPositionals(parsed.positionals, settings.positionals);
457
+ return { ...parsed, values: parsed.values, positionals: parsed.positionals, rest };
458
+ }
459
+ function splitRest(args, passes) {
460
+ const separator = passes ? args.indexOf("--") : -1;
461
+ return { own: separator === -1 ? args : args.slice(0, separator), rest: separator === -1 ? undefined : args.slice(separator + 1) };
462
+ }
463
+ function splitTrailing(args, options, count) {
464
+ const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
465
+ let seen = 0;
466
+ if (count === 0)
467
+ return { own: args, rest: undefined };
468
+ for (let at = 0;at < args.length; at++) {
469
+ const word = args[at];
470
+ if (word === "--")
471
+ break;
472
+ if (word.startsWith("-")) {
473
+ if (takesValue(word))
474
+ at++;
475
+ continue;
476
+ }
477
+ seen++;
478
+ if (seen === count)
479
+ return { own: args.slice(0, at + 1), rest: args.slice(at + 1) };
480
+ }
481
+ return { own: args, rest: undefined };
482
+ }
483
+ function listed(options, allowNegative) {
484
+ if (!allowNegative)
485
+ return options;
486
+ return Object.fromEntries(Object.entries(options).flatMap(([name, option]) => {
487
+ if (option.type !== "boolean" || option.negative === undefined)
488
+ return [[name, option]];
489
+ return [...option.description === undefined ? [] : [[name, option]], [`no-${name}`, { type: "boolean", description: option.negative }]];
490
+ }));
491
+ }
492
+ function withBare(args, options) {
493
+ const bare = new Map(Object.entries(options).flatMap(([name, { short, optional }]) => optional === undefined ? [] : [[`--${name}`, optional], ...short === undefined ? [] : [[`-${short}`, optional]]]));
494
+ if (bare.size === 0)
495
+ return args;
496
+ const separator = args.indexOf("--");
497
+ const own = separator === -1 ? args : args.slice(0, separator);
498
+ return [...own.flatMap((arg, index) => {
499
+ const optional = bare.get(arg);
500
+ const next = own[index + 1];
501
+ const value = next !== undefined && (optional?.accepts === undefined ? !next.startsWith("-") : optional.accepts.test(next));
502
+ return optional === undefined || value ? [arg] : [arg, optional.bare];
503
+ }), ...separator === -1 ? [] : args.slice(separator)];
504
+ }
505
+ function checkConflicts(values, options) {
506
+ const given = (name) => values[name] !== undefined && values[name] !== false;
507
+ for (const [name, { conflicts = [] }] of Object.entries(options)) {
508
+ const other = given(name) ? conflicts.find(given) : undefined;
509
+ if (other !== undefined)
510
+ badUsage(`--${name} cannot be used with --${other}`);
511
+ }
512
+ }
513
+ function checkChoices(values, options) {
514
+ for (const [name, option] of Object.entries(options)) {
515
+ if (option.choices === undefined)
516
+ continue;
517
+ const given = values[name];
518
+ for (const value of Array.isArray(given) ? given : [given]) {
519
+ if (typeof value === "string")
520
+ oneOf(value, name, option.choices);
521
+ }
522
+ }
523
+ }
524
+ function oneOf(value, name, choices) {
525
+ if (!choices.includes(value))
526
+ badUsage(`${name.startsWith("<") ? name : `--${name}`} takes one of ${choices.join(", ")}, not ${value}`);
527
+ return value;
528
+ }
529
+ function checkPositionals(given, names) {
530
+ const variadic = names.at(-1)?.replace("]", "").endsWith("...") === true;
531
+ const required = names.filter((name) => !name.startsWith("[")).length;
532
+ if (given.length < required)
533
+ badUsage(`missing ${names[given.length]}`);
534
+ if (!variadic && given.length > names.length)
535
+ badUsage(`unexpected argument ${given[names.length]}`);
536
+ }
537
+ function joinDashValues(args, options) {
538
+ const longOf = new Map(Object.entries(options).flatMap(([name, option]) => option.short === undefined ? [[`--${name}`, name]] : [[`--${name}`, name], [`-${option.short}`, name]]));
539
+ const isOption = (arg) => arg === "--" || longOf.has(arg.includes("=") ? arg.slice(0, arg.indexOf("=")) : arg);
540
+ const joined = [];
541
+ for (let i = 0;i < args.length; i++) {
542
+ const arg = args[i] ?? "";
543
+ if (arg === "--")
544
+ return [...joined, ...args.slice(i)];
545
+ const name = longOf.get(arg);
546
+ const next = args[i + 1];
547
+ if (name !== undefined && options[name]?.type === "string" && next !== undefined && next.startsWith("-") && next !== "-" && !isOption(next)) {
548
+ joined.push(`--${name}=${next}`);
549
+ i++;
550
+ } else {
551
+ joined.push(arg);
552
+ }
553
+ }
554
+ return joined;
555
+ }
556
+ function parseError(error) {
557
+ const message = upTo(error instanceof Error ? error.message : String(error), ". ");
558
+ return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
559
+ }
560
+ var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
561
+ function nearestOption(message, options, allowNegative) {
562
+ const typed = UNKNOWN_OPTION.exec(message)?.[1];
563
+ if (typed === undefined)
564
+ return;
565
+ const word = typed.replace(DASHES, "");
566
+ if (word.length < 2 && !typed.startsWith("--"))
567
+ return;
568
+ const known = Object.entries(options).flatMap(([name, option]) => [
569
+ ...option.short === undefined ? [] : [`-${option.short}`],
570
+ `--${name}`,
571
+ ...allowNegative && option.type === "boolean" ? [`--no-${name}`] : []
572
+ ]);
573
+ const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
574
+ return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
575
+ }
576
+ // ../kit/src/progress.ts
577
+ var ESC = String.fromCharCode(27);
578
+ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
579
+ var RESET_STYLE = `${ESC}[0m`;
580
+ var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
581
+ // ../kit/src/cli.ts
582
+ import process6 from "process";
583
+
584
+ // ../kit/src/usage.ts
585
+ import { appendFileSync, mkdirSync } from "fs";
586
+ import { homedir } from "os";
587
+ import { dirname, isAbsolute, join } from "path";
588
+ import process5 from "process";
589
+
590
+ // ../kit/src/logs.ts
591
+ var DAY_MS = 24 * 60 * 60 * 1000;
592
+ var CLI_FOLDER = "kaynooo-cli";
593
+
594
+ // ../kit/src/usage.ts
595
+ var UNKNOWN_OPTION2 = /unknown option '(--[a-z][a-z0-9-]*)[=']/;
596
+ var FLAG_NAME = /^(?:--[a-z][a-z0-9-]*|-[a-zA-Z])$/;
597
+ var LONGEST_NAME = 40;
598
+ var usageError;
599
+ function noteUsageError(message) {
600
+ usageError = message;
601
+ }
602
+ function stateHome(env = process5.env) {
603
+ const dir = env.XDG_STATE_HOME;
604
+ return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
605
+ }
606
+ function usagePath(env = process5.env) {
607
+ return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
608
+ }
609
+ function usageRecorded(env = process5.env) {
610
+ const off = env.KAYNOOO_CLI_NO_USAGE;
611
+ return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
612
+ }
613
+ function flagNames(argv) {
614
+ const end = argv.indexOf("--");
615
+ const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
616
+ return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
617
+ }
618
+ function usageEntry(bin, command, argv, code, now = new Date) {
619
+ const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
620
+ usageError = undefined;
621
+ return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
622
+ }
623
+ function recordUsage(entry, env = process5.env) {
624
+ if (!usageRecorded(env))
625
+ return;
626
+ try {
627
+ const path = usagePath(env);
628
+ mkdirSync(dirname(path), { recursive: true, mode: 448 });
629
+ appendFileSync(path, `${JSON.stringify(entry)}
630
+ `, { mode: 384 });
631
+ } catch {}
632
+ }
633
+
634
+ // ../kit/src/cli.ts
635
+ var LEVEL_OPTIONS = {
636
+ ...OUTPUT_OPTIONS,
637
+ help: { type: "boolean", short: "h", description: "show this help" }
638
+ };
639
+ var TOP_OPTIONS = { ...LEVEL_OPTIONS, version: { type: "boolean", short: "v", description: "print the version" } };
640
+ function printError(prefix, message, hint, cause) {
641
+ const colors = paint(process6.stderr);
642
+ const styled = takesControlCodes(process6.stderr);
643
+ const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
644
+ const under = (label, text, tint) => text === undefined ? "" : `
645
+ ${styled ? tint(label) : `${label}:`} ${text}`;
646
+ console.error(`${head} ${message}${under("cause", cause, colors.dim)}${under("hint", hint, colors.yellow)}`);
647
+ }
648
+ function printJsonError(message, hint, cause) {
649
+ console.error(JSON.stringify({ error: message, ...hint === undefined ? {} : { hint }, ...cause === undefined ? {} : { cause } }));
650
+ }
651
+ function wantsJson(argv) {
652
+ const end = argv.indexOf("--");
653
+ return (end === -1 ? argv : argv.slice(0, end)).includes("--json");
654
+ }
655
+ function reportThrown(prefix, error, redact = (text) => text, json = false) {
656
+ if (error instanceof HelpShown)
657
+ return 0;
658
+ const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
659
+ const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
660
+ const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
661
+ if (error instanceof UsageError)
662
+ noteUsageError(error.message);
663
+ const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
664
+ report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
665
+ return error instanceof Exit ? error.code : 1;
666
+ }
667
+ var COMPLETE = "__complete";
668
+ var FILES = "__files__";
669
+ async function completingOf(run) {
670
+ completion.active = true;
671
+ try {
672
+ await run([]);
673
+ } catch (error) {
674
+ if (error instanceof Completing)
675
+ return error;
676
+ } finally {
677
+ completion.active = false;
678
+ }
679
+ return new Completing({});
680
+ }
681
+ function candidateLine(candidate) {
682
+ return typeof candidate === "string" ? candidate : candidate.join("\t");
683
+ }
684
+ function positionalBeingTyped(before, { options, positionals }) {
685
+ const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
686
+ let index = 0;
687
+ let at = 0;
688
+ while (at < before.length) {
689
+ const word = before[at];
690
+ if (word === "--") {
691
+ index += before.length - at - 1;
692
+ break;
693
+ }
694
+ if (!word.startsWith("-"))
695
+ index++;
696
+ else if (takesValue(word))
697
+ at++;
698
+ at++;
699
+ }
700
+ const last = positionals.at(-1);
701
+ if (index < positionals.length)
702
+ return positionals[index];
703
+ return last?.replace("]", "").endsWith("...") === true ? last : undefined;
704
+ }
705
+ async function leafCandidates(run, words) {
706
+ const completing = await completingOf(run);
707
+ if ((words.at(-1) ?? "").startsWith("-"))
708
+ return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
709
+ const flag = words.at(-2);
710
+ const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
711
+ if (option?.type === "string") {
712
+ const values = option.choices === undefined ? await option.candidates?.() : option.choices;
713
+ return values === undefined ? [FILES] : values.map(candidateLine);
714
+ }
715
+ const name = positionalBeingTyped(words.slice(0, -1), completing);
716
+ const values = name === undefined ? undefined : await completing.candidates[name]?.();
717
+ return values === undefined ? [FILES] : values.map(candidateLine);
718
+ }
719
+ async function printCandidates(found) {
720
+ for (const line of await found)
721
+ console.log(line);
722
+ return 0;
723
+ }
724
+ async function runMain({ name, version, run, redact, usage }, argv = process6.argv.slice(2)) {
725
+ if (argv[0] === COMPLETE)
726
+ return printCandidates(leafCandidates(run, argv.slice(1)));
727
+ if (argv.length === 1 && (argv[0] === "--version" || argv[0] === "-v")) {
728
+ console.log(version);
729
+ return 0;
730
+ }
731
+ let code;
732
+ try {
733
+ code = await run(argv);
734
+ } catch (error) {
735
+ code = reportThrown(name, error, redact, wantsJson(argv));
736
+ }
737
+ if (usage !== false)
738
+ recordUsage(usageEntry(name, undefined, argv, code));
739
+ return code;
740
+ }
741
+ // ../kit/src/secrets.ts
742
+ var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
743
+ // ../kit/src/sessions.ts
744
+ var {Glob } = globalThis.Bun;
745
+ var SESSION_FILES = new Glob("*.json");
746
+ var ACCOUNT_DIRS = new Glob("*/sessions");
747
+ // package.json
748
+ var version = "0.1.0";
749
+
750
+ // src/dc.ts
751
+ import process8 from "process";
752
+
753
+ // src/stack.ts
754
+ import { existsSync, readdirSync, readFileSync } from "fs";
755
+ import { dirname as dirname2, join as join2, relative, resolve } from "path";
756
+ var LABEL_FORMAT = ["project", "project.config_files", "project.environment_file", "project.working_dir"].map((label) => `{{.Label "com.docker.compose.${label}"}}`).join("\t");
757
+ var COMPOSE_FILE_VAR = /^\s*(?:export\s+)?COMPOSE_FILE\s*=\s*\S/m;
758
+ var COMPOSE_FILES = ["compose.yaml", "compose.yml", "docker-compose.yaml", "docker-compose.yml"];
759
+ var SKIPPED = new Set(["node_modules", "vendor", "dist", "build", "target", "venv", "__pycache__"]);
760
+ var ACTIONS = ["shell", "logs", "restart", "up", "stop", "build"];
761
+ function from(dir, command) {
762
+ return dir === "." ? command : ["env", "-C", dir, ...command];
763
+ }
764
+ function children(dir = ".") {
765
+ return readdirSync(dir, { withFileTypes: true }).filter((child) => child.isDirectory() && !child.name.startsWith(".") && !SKIPPED.has(child.name)).map((child) => child.name).sort();
766
+ }
767
+ function up(dir) {
768
+ const dirs = [];
769
+ for (let current = dir;; current = join2(current, "..")) {
770
+ dirs.push(current);
771
+ const absolute = resolve(current);
772
+ if (existsSync(join2(current, ".git")) || dirname2(absolute) === absolute)
773
+ return dirs;
774
+ }
775
+ }
776
+ function stackAt(dir) {
777
+ return { dir, run: from(dir, ["docker", "compose"]), list: { argv: ["docker", "compose"], cwd: resolve(dir), env: process.env } };
778
+ }
779
+ function holdsStack(dir) {
780
+ if (COMPOSE_FILES.some((name) => existsSync(join2(dir, name))))
781
+ return true;
782
+ try {
783
+ return COMPOSE_FILE_VAR.test(readFileSync(join2(dir, ".env"), "utf-8"));
784
+ } catch {
785
+ return false;
786
+ }
787
+ }
788
+ function nearestStack(dir) {
789
+ const found = up(dir).find(holdsStack);
790
+ return found === undefined ? undefined : stackAt(found);
791
+ }
792
+ function stacks() {
793
+ const here = nearestStack(".");
794
+ const below = children().filter(holdsStack);
795
+ return [...here ? [here] : [], ...below.filter((dir) => dir !== here?.dir).map(stackAt)];
796
+ }
797
+ function labelled(text) {
798
+ const projects = new Map;
799
+ for (const line of text.split(`
800
+ `)) {
801
+ const [project, files, envFiles = "", workdir = ""] = line.split("\t");
802
+ if (project !== undefined && project !== "" && files !== undefined && files !== "" && workdir !== "" && !projects.has(project))
803
+ projects.set(project, { project, files: files.split(","), envFiles: envFiles.split(",").filter(Boolean), workdir });
804
+ }
805
+ return [...projects.values()];
806
+ }
807
+ async function labels(project) {
808
+ const filter = project === undefined ? [] : ["--filter", `label=com.docker.compose.project=${project}`];
809
+ const proc = Bun.spawn(["docker", "ps", "--all", ...filter, "--format", LABEL_FORMAT], { stdout: "pipe", stderr: "ignore" });
810
+ if (await proc.exited !== 0)
811
+ return [];
812
+ return labelled(await new Response(proc.stdout).text()).filter((stack) => [...stack.files, ...stack.envFiles].every((file) => existsSync(file)));
813
+ }
814
+ function labelledStack(dir, { project, files, envFiles, workdir }) {
815
+ const options = (paths) => ["-p", project, ...files.flatMap((file) => ["-f", paths(file)]), ...envFiles.flatMap((file) => ["--env-file", paths(file)])];
816
+ return {
817
+ dir,
818
+ project,
819
+ run: from(dir, ["docker", "compose", ...options((file) => relative(workdir, file))]),
820
+ list: { argv: ["docker", "compose", ...options((file) => file)], cwd: workdir, env: process.env }
821
+ };
822
+ }
823
+ function stackOf(recorded) {
824
+ return labelledStack(relative(".", recorded.workdir) || ".", recorded);
825
+ }
826
+ async function recordedNearby() {
827
+ const dirs = new Set([...up("."), ...children()].map((dir) => resolve(dir)));
828
+ return (await labels()).filter((stack) => dirs.has(stack.workdir));
829
+ }
830
+ async function output(stack, args) {
831
+ const proc = Bun.spawn([...stack.list.argv, ...args], { cwd: stack.list.cwd, env: stack.list.env, stdout: "pipe", stderr: "pipe" });
832
+ return await proc.exited === 0 ? new Response(proc.stdout).text() : "";
833
+ }
834
+ function containers(text) {
835
+ const trimmed = text.trim();
836
+ if (!trimmed)
837
+ return [];
838
+ return trimmed.startsWith("[") ? JSON.parse(trimmed) : trimmed.split(`
839
+ `).map((line) => JSON.parse(line));
840
+ }
841
+ async function services(stack) {
842
+ const [config, ps] = await Promise.all([output(stack, ["config", "--format", "json"]), output(stack, ["ps", "--all", "--format", "json"])]);
843
+ const parsed = config ? JSON.parse(config) : {};
844
+ const declared = parsed.services ?? {};
845
+ const project = stack.project ?? parsed.name ?? "";
846
+ const running = new Map(containers(ps).map((container) => [container.Service, container]));
847
+ return Object.entries(declared).map(([name, service]) => ({
848
+ stack,
849
+ project,
850
+ name,
851
+ state: running.get(name)?.State ?? "none",
852
+ status: running.get(name)?.Status ?? "",
853
+ ports: (service.ports ?? []).filter((port) => (port.published ?? "") !== "").map((port) => `${port.published}->${port.target}`).join(" "),
854
+ image: service.image ?? "built"
855
+ }));
856
+ }
857
+ async function allServices() {
858
+ const [listed, recorded] = await Promise.all([Promise.all(stacks().map(services)), recordedNearby()]);
859
+ const found = listed.flat();
860
+ const known = new Set(found.map((service) => service.project));
861
+ const others = recorded.filter((stack) => !known.has(stack.project));
862
+ return [...found, ...(await Promise.all(others.map(async (stack) => services(stackOf(stack))))).flat()];
863
+ }
864
+ function named(service) {
865
+ return service.stack.project === undefined ? service.name : `${service.stack.project}:${service.name}`;
866
+ }
867
+ function key(service) {
868
+ return service.stack.dir === "." ? named(service) : `${service.stack.dir}/${named(service)}`;
869
+ }
870
+ async function shellOf(service) {
871
+ return await output(service.stack, ["exec", "-T", service.name, "sh", "-c", "command -v bash"]) ? "bash" : "sh";
872
+ }
873
+ async function commandFor(service, action) {
874
+ const run = service.stack.run;
875
+ switch (action) {
876
+ case "shell":
877
+ return [...run, "exec", service.name, await shellOf(service)];
878
+ case "logs":
879
+ return [...run, "logs", "-f", "--tail=200", service.name];
880
+ case "restart":
881
+ return [...run, "restart", service.name];
882
+ case "up":
883
+ return [...run, "up", "-d", service.name];
884
+ case "stop":
885
+ return [...run, "stop", service.name];
886
+ case "build":
887
+ return [...run, "up", "-d", "--build", service.name];
888
+ }
889
+ }
890
+ function defaultAction(service) {
891
+ return service.state === "running" ? "shell" : "up";
892
+ }
893
+
894
+ // src/dc.ts
895
+ var COMMANDS = new Set(["alpha", "attach", "bridge", "build", "commit", "config", "cp", "create", "down", "events", "exec", "export", "help", "images", "kill", "logs", "ls", "pause", "port", "ps", "publish", "pull", "push", "restart", "rm", "run", "scale", "start", "stats", "stop", "top", "unpause", "up", "version", "volumes", "wait", "watch"]);
896
+ async function target(args) {
897
+ const [first = "", ...rest] = args;
898
+ const recorded = first.startsWith("-") || COMMANDS.has(first) ? undefined : await recordedNearby();
899
+ const chosen = recorded?.find((stack) => stack.project === first);
900
+ if (chosen)
901
+ return { kind: "stack", stack: stackOf(chosen), args: rest, announce: true };
902
+ const nearest = nearestStack(".");
903
+ if (nearest)
904
+ return { kind: "stack", stack: nearest, args, announce: false };
905
+ const withContainers = recorded ?? await recordedNearby();
906
+ if (withContainers.length === 1)
907
+ return { kind: "stack", stack: stackOf(withContainers[0]), args, announce: true };
908
+ if (withContainers.length > 1)
909
+ return { kind: "choose", recorded: withContainers, args };
910
+ return { kind: "stack", stack: stackAt("."), args, announce: false };
911
+ }
912
+ async function choose(recorded) {
913
+ const picker = Bun.which("pick");
914
+ if (picker === null || !process8.stdin.isTTY)
915
+ return;
916
+ const proc = Bun.spawn([picker, "--prompt", "dc> "], { stdin: new Blob([recorded.map((stack) => stack.project).join(`
917
+ `)]), stdout: "pipe", stderr: "inherit" });
918
+ const picked = (await new Response(proc.stdout).text()).trim();
919
+ return recorded.find((stack) => stack.project === picked);
920
+ }
921
+ async function run(stack, args, announce) {
922
+ if (announce && process8.stderr.isTTY)
923
+ console.error(paint(process8.stderr).dim([...stack.run, ...args].join(" ")));
924
+ return Bun.spawn([...stack.list.argv, ...args], { cwd: stack.list.cwd, env: stack.list.env, stdio: ["inherit", "inherit", "inherit"] }).exited;
925
+ }
926
+ async function dc(args) {
927
+ const found = await target(args);
928
+ if (found.kind === "stack")
929
+ return run(found.stack, found.args, found.announce);
930
+ const recorded = await choose(found.recorded);
931
+ if (!recorded) {
932
+ console.error(`several stacks here, name one first: ${found.recorded.map((stack) => stack.project).join(", ")}`);
933
+ return 1;
934
+ }
935
+ return run(stackOf(recorded), found.args, true);
936
+ }
937
+
938
+ // src/dc-cli.ts
939
+ var usage2 = `dc [project] <compose args>
940
+
941
+ Runs docker compose on the stack found here: the nearest compose file or .env setting COMPOSE_FILE up to the repository root, else the only stack with containers here.
942
+ A first word naming a compose project with containers here runs on that project, with the files and env file it came up with (\`dc dash logs\`); the command it stands for is shown on stderr.
943
+ Takes no option of its own: every word reaches compose as typed, \`dc --help\` alone excepted.
944
+
945
+ Exits with the code of compose, 1 when several stacks have containers here and none is named.`;
946
+ async function main(args) {
947
+ if (completion.active || args.length === 1 && (args[0] === "--help" || args[0] === "-h")) {
948
+ parse(args, usage2, {}, { replaces: "docker compose -f docker-compose.prod.yaml --env-file .env.prod, typed again for each stack", examples: ["dc up -d", ["dc dash logs -f", "a stack that came up from other files"]] });
949
+ return 0;
950
+ }
951
+ return dc(args);
952
+ }
953
+ process9.exitCode = await runMain({ name: "dc", version, run: main });