@kaynooo/cli-db 0.10.0 → 0.12.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/cli.js +371 -334
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -1,309 +1,357 @@
|
|
|
1
|
-
#!/usr/bin/env bun
|
|
1
|
+
#!/usr/bin/env -S bun --config=/dev/null
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process16 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
|
-
import
|
|
7
|
+
import process10 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
9
9
|
|
|
10
10
|
// ../kit/src/format.ts
|
|
11
|
-
import
|
|
11
|
+
import process7 from "process";
|
|
12
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-rxztfxgv.js
|
|
13
|
+
var N = new Map;
|
|
14
|
+
var Nt = /\s+\S*$/;
|
|
15
|
+
var Y = /\s/;
|
|
16
|
+
function ko(t, e, r = "...") {
|
|
17
|
+
let { suffix: n = "...", includeSuffix: s = false, wordBoundary: o = false } = typeof r === "string" ? { suffix: r } : r;
|
|
18
|
+
if (t.length <= e)
|
|
19
|
+
return t;
|
|
20
|
+
let l = Math.max(0, e), c = t.substring(0, Math.max(0, s ? l - n.length : l));
|
|
21
|
+
if (o && !Y.test(t[c.length] ?? " "))
|
|
22
|
+
c = c.replace(Nt, "") || c;
|
|
23
|
+
if (o)
|
|
24
|
+
c = c.trimEnd();
|
|
25
|
+
return s ? (c + n).slice(0, l) : c + n;
|
|
26
|
+
}
|
|
27
|
+
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));
|
|
28
|
+
var z = new Map;
|
|
29
|
+
// ../kit/src/mode.ts
|
|
30
|
+
import process2 from "process";
|
|
31
|
+
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
32
|
+
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
33
|
+
function isSet(value) {
|
|
34
|
+
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
35
|
+
}
|
|
36
|
+
function outputMode(stream = process2.stdout, env = process2.env) {
|
|
37
|
+
const chosen = env.KIT_MODE;
|
|
38
|
+
if (chosen !== undefined && MODES.has(chosen))
|
|
39
|
+
return chosen;
|
|
40
|
+
if (AGENT_VARIABLES.some((name) => isSet(env[name])))
|
|
41
|
+
return "agent";
|
|
42
|
+
if (stream.isTTY === true)
|
|
43
|
+
return "terminal";
|
|
44
|
+
return isSet(env.CI) ? "ci" : "pipe";
|
|
45
|
+
}
|
|
12
46
|
|
|
13
47
|
// ../kit/src/style.ts
|
|
14
|
-
import
|
|
48
|
+
import process6 from "process";
|
|
15
49
|
|
|
16
|
-
// ../../node_modules/.bun/@kaynooo+utils@
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
50
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
51
|
+
var G2 = /^[a-f0-9]+$/i;
|
|
52
|
+
function b(r) {
|
|
53
|
+
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
54
|
+
if (!G2.test(e))
|
|
20
55
|
return [0, 0, 0];
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
let
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (
|
|
36
|
-
return
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
function
|
|
40
|
-
|
|
41
|
-
let
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
s = (s % 360 + 360) % 360, r /= 100, t /= 100;
|
|
65
|
-
let n = (a) => {
|
|
66
|
-
let b = (a + s / 60) % 6, o = t - t * r * Math.max(Math.min(b, 4 - b, 1), 0);
|
|
67
|
-
return Math.round(255 * o);
|
|
68
|
-
};
|
|
69
|
-
return [n(5), n(3), n(1)];
|
|
70
|
-
}
|
|
71
|
-
function f(s) {
|
|
72
|
-
let [r, t, n] = s;
|
|
73
|
-
r /= 255, t /= 255, n /= 255;
|
|
74
|
-
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;
|
|
75
|
-
if (o !== 0) {
|
|
76
|
-
if (a === r)
|
|
77
|
-
y = (t - n) / o + (t < n ? 6 : 0);
|
|
78
|
-
else if (a === t)
|
|
79
|
-
y = (n - r) / o + 2;
|
|
80
|
-
else
|
|
81
|
-
y = (r - t) / o + 4;
|
|
82
|
-
y /= 6;
|
|
83
|
-
}
|
|
84
|
-
return [Math.round(y * 360), Math.round(c * 100), Math.round(u * 100)];
|
|
85
|
-
}
|
|
86
|
-
function O(s) {
|
|
87
|
-
let r = s[0] / 255, t = s[1] / 255, n = s[2] / 255, a = 1 - Math.max(r, t, n);
|
|
88
|
-
if (a === 1)
|
|
89
|
-
return [0, 0, 0, 100];
|
|
90
|
-
let b = (1 - r - a) / (1 - a), o = (1 - t - a) / (1 - a), y = (1 - n - a) / (1 - a);
|
|
91
|
-
return [Math.round(b * 100), Math.round(o * 100), Math.round(y * 100), Math.round(a * 100)];
|
|
92
|
-
}
|
|
93
|
-
function v(s, r, t, n) {
|
|
94
|
-
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))];
|
|
56
|
+
if (e.length === 3 || e.length === 4)
|
|
57
|
+
return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
|
|
58
|
+
if (e.length !== 6 && e.length !== 8)
|
|
59
|
+
throw Error(`Invalid hex color length: ${e.length}`);
|
|
60
|
+
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
61
|
+
}
|
|
62
|
+
var B2 = { 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") => {
|
|
63
|
+
let [l, n, c] = b(r);
|
|
64
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
65
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
66
|
+
var h = new Set(["", "1", "2", "3", "true"]);
|
|
67
|
+
function C(r, e = globalThis.process?.env ?? {}) {
|
|
68
|
+
if (e.FORCE_COLOR !== undefined)
|
|
69
|
+
return h.has(e.FORCE_COLOR);
|
|
70
|
+
if (e.NO_COLOR !== undefined || e.NODE_DISABLE_COLORS !== undefined || e.TERM === "dumb")
|
|
71
|
+
return false;
|
|
72
|
+
return r?.isTTY === true;
|
|
73
|
+
}
|
|
74
|
+
function f2(r, e = []) {
|
|
75
|
+
let l = "", n = "";
|
|
76
|
+
for (let t = 0, i = e.length;t < i; t++)
|
|
77
|
+
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
78
|
+
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
79
|
+
return new Proxy(c, { get(t, i) {
|
|
80
|
+
let a = B2[i];
|
|
81
|
+
if (Array.isArray(a)) {
|
|
82
|
+
let s = g.get(i);
|
|
83
|
+
if (s === undefined)
|
|
84
|
+
s = f2(r, [...e, a]), g.set(i, s);
|
|
85
|
+
return s;
|
|
86
|
+
}
|
|
87
|
+
if (typeof a === "function")
|
|
88
|
+
return (...s) => {
|
|
89
|
+
let y = `${i}:${s.join(",")}`, u = g.get(y);
|
|
90
|
+
if (u === undefined) {
|
|
91
|
+
if (g.size >= 64)
|
|
92
|
+
g.clear();
|
|
93
|
+
u = f2(r, [...e, a(...s)]), g.set(y, u);
|
|
94
|
+
}
|
|
95
|
+
return u;
|
|
96
|
+
};
|
|
97
|
+
throw Error(`Unknown style: ${String(i)}`);
|
|
98
|
+
} });
|
|
95
99
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
var i = (s, r) => Math.round(s * 10 ** r) / 10 ** r;
|
|
99
|
-
function T(s) {
|
|
100
|
-
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);
|
|
101
|
-
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
|
+
function Fe2(r = {}) {
|
|
101
|
+
return f2(r);
|
|
102
102
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
var o2 = Fe2();
|
|
104
|
+
|
|
105
|
+
// ../kit/src/theme.ts
|
|
106
|
+
import { existsSync as existsSync3, readFileSync, statSync } from "fs";
|
|
107
|
+
import { homedir as homedir2 } from "os";
|
|
108
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
109
|
+
import process5 from "process";
|
|
110
|
+
|
|
111
|
+
// ../kit/src/config.ts
|
|
112
|
+
import { existsSync } from "fs";
|
|
113
|
+
import { dirname, join, resolve } from "path";
|
|
114
|
+
import process3 from "process";
|
|
115
|
+
function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
116
|
+
const wanted = typeof names === "string" ? [names] : names;
|
|
117
|
+
for (let dir = resolve(from);; dir = dirname(dir)) {
|
|
118
|
+
const found = wanted.map((name) => join(dir, name)).find((path) => existsSync(path));
|
|
119
|
+
if (found !== undefined)
|
|
120
|
+
return found;
|
|
121
|
+
if (stop(dir) || dirname(dir) === dir)
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
106
124
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
125
|
+
|
|
126
|
+
// ../kit/src/user-config.ts
|
|
127
|
+
import { existsSync as existsSync2 } from "fs";
|
|
128
|
+
import { homedir } from "os";
|
|
129
|
+
import { join as join2 } from "path";
|
|
130
|
+
import process4 from "process";
|
|
131
|
+
function configBase(where = {}) {
|
|
132
|
+
const xdg = where.xdg ?? (where.home === undefined ? process4.env.XDG_CONFIG_HOME : undefined);
|
|
133
|
+
return xdg !== undefined && xdg !== "" ? xdg : join2(where.home ?? homedir(), ".config");
|
|
110
134
|
}
|
|
111
|
-
function
|
|
112
|
-
|
|
113
|
-
return M(s, r * Math.cos(n), r * Math.sin(n));
|
|
135
|
+
function userConfigPath(bin, where = {}) {
|
|
136
|
+
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
114
137
|
}
|
|
115
|
-
function
|
|
116
|
-
|
|
117
|
-
|
|
138
|
+
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
139
|
+
const current = userConfigPath(bin, where);
|
|
140
|
+
if (existsSync2(current))
|
|
141
|
+
return current;
|
|
142
|
+
const base = configBase(where);
|
|
143
|
+
return legacy.map((parts) => join2(base, ...parts)).find((path) => existsSync2(path)) ?? current;
|
|
118
144
|
}
|
|
119
145
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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 = process5.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;
|
|
158
210
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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`);
|
|
163
243
|
else
|
|
164
|
-
|
|
165
|
-
let [y, c, u] = v(t, n, a, b);
|
|
166
|
-
return new e(y, c, u, o);
|
|
244
|
+
theme.colors[key] = value;
|
|
167
245
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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`);
|
|
172
253
|
else
|
|
173
|
-
|
|
174
|
-
let [o, y, c] = C(t, n, a);
|
|
175
|
-
return new e(o, y, c, b);
|
|
254
|
+
theme.glyphs[key] = value;
|
|
176
255
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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;
|
|
181
271
|
else
|
|
182
|
-
({
|
|
183
|
-
let [o, y, c] = M(t, n, a);
|
|
184
|
-
return new e(o, y, c, b);
|
|
185
|
-
}
|
|
186
|
-
throw Error("Invalid input");
|
|
187
|
-
}
|
|
188
|
-
to(s) {
|
|
189
|
-
switch (s) {
|
|
190
|
-
case "rgb":
|
|
191
|
-
return [this.r, this.g, this.b];
|
|
192
|
-
case "rgba":
|
|
193
|
-
return [this.r, this.g, this.b, this.a];
|
|
194
|
-
case "hex":
|
|
195
|
-
return A([this.r, this.g, this.b]);
|
|
196
|
-
case "hexa":
|
|
197
|
-
return A([this.r, this.g, this.b, this.a]);
|
|
198
|
-
case "hsl":
|
|
199
|
-
return k([this.r, this.g, this.b]);
|
|
200
|
-
case "hsla":
|
|
201
|
-
return [...k([this.r, this.g, this.b]), this.a];
|
|
202
|
-
case "hsv":
|
|
203
|
-
return f([this.r, this.g, this.b]);
|
|
204
|
-
case "hsva":
|
|
205
|
-
return [...f([this.r, this.g, this.b]), this.a];
|
|
206
|
-
case "cmyk":
|
|
207
|
-
return O([this.r, this.g, this.b]);
|
|
208
|
-
case "cmyka":
|
|
209
|
-
return [...O([this.r, this.g, this.b]), this.a];
|
|
210
|
-
case "oklch":
|
|
211
|
-
return d([this.r, this.g, this.b]);
|
|
212
|
-
case "oklcha":
|
|
213
|
-
return [...d([this.r, this.g, this.b]), this.a];
|
|
214
|
-
case "oklab":
|
|
215
|
-
return T([this.r, this.g, this.b]);
|
|
216
|
-
case "oklaba":
|
|
217
|
-
return [...T([this.r, this.g, this.b]), this.a];
|
|
218
|
-
default:
|
|
219
|
-
return [this.r, this.g, this.b];
|
|
272
|
+
warn(`${where}: bin ${bin} has no valid colour`);
|
|
220
273
|
}
|
|
221
274
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
275
|
+
}
|
|
276
|
+
function endsWalk(home) {
|
|
277
|
+
return (dir) => dir === resolve2(home) || existsSync3(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 = process5.env, from = process5.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;
|
|
229
309
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
310
|
+
for (const { path, file } of files) {
|
|
311
|
+
applyFile(theme, file, path, warn);
|
|
312
|
+
sources.push(path);
|
|
233
313
|
}
|
|
314
|
+
return { theme, sources, preset };
|
|
234
315
|
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
var b = new Set(["", "1", "2", "3", "true"]);
|
|
245
|
-
function h(i, n = globalThis.process?.env ?? {}) {
|
|
246
|
-
if (n.FORCE_COLOR !== undefined)
|
|
247
|
-
return b.has(n.FORCE_COLOR);
|
|
248
|
-
if (n.NO_COLOR !== undefined || n.NODE_DISABLE_COLORS !== undefined || n.TERM === "dumb")
|
|
249
|
-
return false;
|
|
250
|
-
return i?.isTTY === true;
|
|
251
|
-
}
|
|
252
|
-
function d2(i, n, a) {
|
|
253
|
-
if (!h(a.stream ?? globalThis.process?.stdout, a.env))
|
|
254
|
-
return n;
|
|
255
|
-
let l = "", s = "";
|
|
256
|
-
for (let g = 0, y = i.length;g < y; g++) {
|
|
257
|
-
let [c, p] = i[g];
|
|
258
|
-
l += `${f2}${c}m`, s = `${f2}${p}m${s}`;
|
|
259
|
-
}
|
|
260
|
-
return l + n + s;
|
|
261
|
-
}
|
|
262
|
-
function u(i, n = []) {
|
|
263
|
-
return new Proxy((l) => d2(n, l, i), { get(l, s) {
|
|
264
|
-
let g = C2[s];
|
|
265
|
-
if (Array.isArray(g))
|
|
266
|
-
return u(i, [...n, g]);
|
|
267
|
-
if (typeof g === "function")
|
|
268
|
-
return (...y) => u(i, [...n, g(...y)]);
|
|
269
|
-
throw Error(`Unknown style: ${String(s)}`);
|
|
270
|
-
} });
|
|
271
|
-
}
|
|
272
|
-
function le(i = {}) {
|
|
273
|
-
return u(i);
|
|
316
|
+
var current;
|
|
317
|
+
var currentKey = "";
|
|
318
|
+
function activeTheme() {
|
|
319
|
+
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
320
|
+
if (current === undefined || key !== currentKey) {
|
|
321
|
+
current = loadTheme();
|
|
322
|
+
currentKey = key;
|
|
323
|
+
}
|
|
324
|
+
return current;
|
|
274
325
|
}
|
|
275
|
-
var t = le();
|
|
276
326
|
|
|
277
327
|
// ../kit/src/style.ts
|
|
278
|
-
var
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
problem: { symbol: "\u2717", word: "error:", paint: (colors) => colors.red },
|
|
282
|
-
note: { symbol: "\xB7", word: "note:", paint: (colors) => colors.dim }
|
|
283
|
-
};
|
|
284
|
-
function takesControlCodes(stream, env = process2.env) {
|
|
285
|
-
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb";
|
|
328
|
+
var MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
329
|
+
function takesControlCodes(stream, env = process6.env) {
|
|
330
|
+
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
286
331
|
}
|
|
287
|
-
function paint(stream, env =
|
|
288
|
-
return
|
|
332
|
+
function paint(stream, env = process6.env) {
|
|
333
|
+
return Fe2({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
289
334
|
}
|
|
290
|
-
function marked(mark, text, stream, detail, env =
|
|
335
|
+
function marked(mark, text, stream, detail, env = process6.env) {
|
|
291
336
|
const colors = paint(stream, env);
|
|
292
|
-
|
|
293
|
-
|
|
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
|
+
}
|
|
294
342
|
return `${head} ${text}${detail === undefined ? "" : ` ${colors.dim(detail)}`}`;
|
|
295
343
|
}
|
|
296
344
|
function warn(text, detail) {
|
|
297
|
-
console.error(marked("warn", text,
|
|
298
|
-
}
|
|
299
|
-
var
|
|
300
|
-
passed:
|
|
301
|
-
failed:
|
|
302
|
-
running:
|
|
303
|
-
queued:
|
|
304
|
-
skipped:
|
|
345
|
+
console.error(marked("warn", text, process6.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"]
|
|
305
353
|
};
|
|
306
|
-
var STATUS_OF = new Map(Object.entries(
|
|
354
|
+
var STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
307
355
|
|
|
308
356
|
// ../kit/src/format.ts
|
|
309
357
|
function upTo(text, separator) {
|
|
@@ -311,22 +359,25 @@ function upTo(text, separator) {
|
|
|
311
359
|
return end === -1 ? text : text.slice(0, end);
|
|
312
360
|
}
|
|
313
361
|
function truncate(text, width) {
|
|
314
|
-
return text
|
|
362
|
+
return ko(text, width, { suffix: "\u2026", includeSuffix: true });
|
|
315
363
|
}
|
|
316
364
|
var LINE_BREAKS = /\s*\n\s*/g;
|
|
317
365
|
var ESCAPE = String.fromCharCode(27);
|
|
318
366
|
function textWidth(text) {
|
|
319
367
|
return Bun.stringWidth(text);
|
|
320
368
|
}
|
|
321
|
-
function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
369
|
+
function table(rows, { cellWidth, header = false, align = [], fit, stream = process7.stdout, env = process7.env } = {}) {
|
|
322
370
|
const cells = cellWidth === undefined ? rows : rows.map((row) => row.map((cell) => truncate(cell.replaceAll(LINE_BREAKS, " "), cellWidth)));
|
|
371
|
+
if (outputMode(stream, env) === "agent")
|
|
372
|
+
return cells.map((row) => row.map((cell) => Bun.stripANSI(cell).replaceAll(/[\t\r\n]+/g, " ")).join("\t")).join(`
|
|
373
|
+
`);
|
|
323
374
|
const widths = [];
|
|
324
375
|
for (const row of cells) {
|
|
325
376
|
for (const [index, cell] of row.entries())
|
|
326
377
|
widths[index] = Math.max(widths[index] ?? 0, textWidth(cell));
|
|
327
378
|
}
|
|
328
379
|
const shown = fit === undefined ? cells : narrow(cells, widths, fit);
|
|
329
|
-
const colors = paint(
|
|
380
|
+
const colors = paint(stream);
|
|
330
381
|
const lines = shown.map((row) => row.map((cell, index) => {
|
|
331
382
|
const width = widths[index] ?? 0;
|
|
332
383
|
const gap = " ".repeat(Math.max(0, width - textWidth(cell)));
|
|
@@ -334,7 +385,8 @@ function table(rows, { cellWidth, header = false, align = [], fit } = {}) {
|
|
|
334
385
|
return `${gap}${cell}`;
|
|
335
386
|
return index === row.length - 1 ? cell : `${cell}${gap}`;
|
|
336
387
|
}).join(" ").trimEnd());
|
|
337
|
-
|
|
388
|
+
const rule = header && takesControlCodes(stream) && lines.length > 1 ? [colors.dim("\u2500".repeat(Math.max(...lines.map(textWidth))))] : [];
|
|
389
|
+
return lines.flatMap((line, index) => header && index === 0 ? [colors.bold(line), ...rule] : [line]).join(`
|
|
338
390
|
`);
|
|
339
391
|
}
|
|
340
392
|
function narrow(rows, widths, limit) {
|
|
@@ -353,29 +405,32 @@ function narrow(rows, widths, limit) {
|
|
|
353
405
|
}
|
|
354
406
|
return rows.map((row) => row.map((cell, index) => textWidth(cell) > (widths[index] ?? 0) ? truncate(cell, widths[index] ?? 0) : cell));
|
|
355
407
|
}
|
|
408
|
+
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
409
|
+
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
410
|
+
}
|
|
356
411
|
|
|
357
412
|
// ../kit/src/help.ts
|
|
358
|
-
import
|
|
413
|
+
import process8 from "process";
|
|
359
414
|
var OPTIONAL = /\[[^\]]+\]/g;
|
|
360
415
|
var USAGE_PREFIX = /^usage:\s*/i;
|
|
361
416
|
var FULL_STOP = /\.$/;
|
|
362
|
-
function usageLine(usage, colors = paint(
|
|
417
|
+
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
363
418
|
return `${colors.bold("Usage:")} ${usage.replace(USAGE_PREFIX, "").replaceAll(OPTIONAL, (part) => colors.dim(part))}`;
|
|
364
419
|
}
|
|
365
|
-
function helpText(usage, options, colors = paint(
|
|
420
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], replaces, exits = [] } = {}) {
|
|
366
421
|
return [usageLine(usage, colors), ...replacesRows(replaces, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
367
422
|
`);
|
|
368
423
|
}
|
|
369
|
-
function exitRows(exits, colors = paint(
|
|
424
|
+
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
370
425
|
if (exits.length === 0)
|
|
371
426
|
return [];
|
|
372
427
|
const width = Math.max(...exits.map(([code]) => String(code).length));
|
|
373
428
|
return ["", colors.bold("Exits:"), ...exits.map(([code, meaning]) => ` ${colors.cyan(String(code).padEnd(width))} ${meaning}`)];
|
|
374
429
|
}
|
|
375
|
-
function replacesRows(replaces, colors = paint(
|
|
376
|
-
return replaces === undefined ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
430
|
+
function replacesRows(replaces, colors = paint(process8.stdout)) {
|
|
431
|
+
return replaces === undefined || outputMode() === "agent" ? [] : ["", `${colors.bold("Instead of:")} ${replaces}`];
|
|
377
432
|
}
|
|
378
|
-
function wantsHelpJson(env =
|
|
433
|
+
function wantsHelpJson(env = process8.env) {
|
|
379
434
|
return env.KIT_HELP === "json";
|
|
380
435
|
}
|
|
381
436
|
function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
@@ -394,12 +449,12 @@ function description(usage, { examples = [], replaces, exits } = {}, options) {
|
|
|
394
449
|
...options === undefined ? {} : { options: Object.entries(options).map(([name, { short, description }]) => ({ name, ...short === undefined ? {} : { short }, ...description === undefined ? {} : { description } })) }
|
|
395
450
|
};
|
|
396
451
|
}
|
|
397
|
-
function exampleRows(examples, colors = paint(
|
|
398
|
-
if (examples.length === 0)
|
|
452
|
+
function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
453
|
+
if (examples.length === 0 || outputMode() === "agent")
|
|
399
454
|
return [];
|
|
400
455
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
401
456
|
}
|
|
402
|
-
function optionRows(options, colors = paint(
|
|
457
|
+
function optionRows(options, colors = paint(process8.stdout)) {
|
|
403
458
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
404
459
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
405
460
|
const named = option.choices === undefined ? "<value>" : `<${option.choices.join("|")}>`;
|
|
@@ -431,7 +486,7 @@ function closest(name, names) {
|
|
|
431
486
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
432
487
|
}
|
|
433
488
|
// ../kit/src/input.ts
|
|
434
|
-
import
|
|
489
|
+
import process9 from "process";
|
|
435
490
|
var WHOLE = /^\d+$/;
|
|
436
491
|
function wholeNumber(value, name, fallback, min = 1) {
|
|
437
492
|
if (value === undefined)
|
|
@@ -443,7 +498,7 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
443
498
|
}
|
|
444
499
|
async function readInput(path, { noStdin = "nothing is piped on stdin" } = {}) {
|
|
445
500
|
if (path === "-") {
|
|
446
|
-
if (
|
|
501
|
+
if (process9.stdin.isTTY)
|
|
447
502
|
fail(noStdin);
|
|
448
503
|
return Bun.stdin.text();
|
|
449
504
|
}
|
|
@@ -458,7 +513,6 @@ var DASHES = /^-+/;
|
|
|
458
513
|
function jsonOption(holds) {
|
|
459
514
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
460
515
|
}
|
|
461
|
-
|
|
462
516
|
class Exit extends Error {
|
|
463
517
|
code;
|
|
464
518
|
hint;
|
|
@@ -502,7 +556,7 @@ var OUTPUT_OPTIONS = {
|
|
|
502
556
|
color: { type: "string", description: "auto (on a terminal alone), always or never" },
|
|
503
557
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
504
558
|
};
|
|
505
|
-
function applyOutput(color, plain, env =
|
|
559
|
+
function applyOutput(color, plain, env = process10.env) {
|
|
506
560
|
const when = plain === true ? "never" : color ?? "auto";
|
|
507
561
|
if (when === "auto")
|
|
508
562
|
return;
|
|
@@ -673,7 +727,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
673
727
|
}
|
|
674
728
|
// ../kit/src/process.ts
|
|
675
729
|
import { constants } from "os";
|
|
676
|
-
import
|
|
730
|
+
import process11 from "process";
|
|
677
731
|
var KILL_GRACE_MS = 2000;
|
|
678
732
|
function exitCodeOf(code, signal) {
|
|
679
733
|
if (code !== null)
|
|
@@ -693,7 +747,7 @@ async function runCommand(argv, { cwd, env, stdin = "ignore", timeoutMs, signal,
|
|
|
693
747
|
return;
|
|
694
748
|
try {
|
|
695
749
|
if (grouped)
|
|
696
|
-
|
|
750
|
+
process11.kill(-proc.pid, killing);
|
|
697
751
|
else
|
|
698
752
|
proc.kill(killing);
|
|
699
753
|
} catch {}
|
|
@@ -767,15 +821,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
767
821
|
var RESET_STYLE = `${ESC}[0m`;
|
|
768
822
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
769
823
|
// ../kit/src/cli.ts
|
|
770
|
-
import { readFileSync, realpathSync } from "fs";
|
|
771
|
-
import { dirname as
|
|
772
|
-
import
|
|
824
|
+
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
825
|
+
import { dirname as dirname3, join as join5 } from "path";
|
|
826
|
+
import process13 from "process";
|
|
773
827
|
|
|
774
828
|
// ../kit/src/usage.ts
|
|
775
829
|
import { appendFileSync, mkdirSync } from "fs";
|
|
776
|
-
import { homedir } from "os";
|
|
777
|
-
import { dirname, isAbsolute, join } from "path";
|
|
778
|
-
import
|
|
830
|
+
import { homedir as homedir3 } from "os";
|
|
831
|
+
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
832
|
+
import process12 from "process";
|
|
779
833
|
|
|
780
834
|
// ../kit/src/logs.ts
|
|
781
835
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -789,14 +843,14 @@ var usageError;
|
|
|
789
843
|
function noteUsageError(message) {
|
|
790
844
|
usageError = message;
|
|
791
845
|
}
|
|
792
|
-
function stateHome(env =
|
|
846
|
+
function stateHome(env = process12.env) {
|
|
793
847
|
const dir = env.XDG_STATE_HOME;
|
|
794
|
-
return dir !== undefined && isAbsolute(dir) ? dir :
|
|
848
|
+
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
795
849
|
}
|
|
796
|
-
function usagePath(env =
|
|
797
|
-
return
|
|
850
|
+
function usagePath(env = process12.env) {
|
|
851
|
+
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
798
852
|
}
|
|
799
|
-
function usageRecorded(env =
|
|
853
|
+
function usageRecorded(env = process12.env) {
|
|
800
854
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
801
855
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
802
856
|
}
|
|
@@ -810,12 +864,12 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
810
864
|
usageError = undefined;
|
|
811
865
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
812
866
|
}
|
|
813
|
-
function recordUsage(entry, env =
|
|
867
|
+
function recordUsage(entry, env = process12.env) {
|
|
814
868
|
if (!usageRecorded(env))
|
|
815
869
|
return;
|
|
816
870
|
try {
|
|
817
871
|
const path = usagePath(env);
|
|
818
|
-
mkdirSync(
|
|
872
|
+
mkdirSync(dirname2(path), { recursive: true, mode: 448 });
|
|
819
873
|
appendFileSync(path, `${JSON.stringify(entry)}
|
|
820
874
|
`, { mode: 384 });
|
|
821
875
|
} catch {}
|
|
@@ -901,8 +955,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
901
955
|
`);
|
|
902
956
|
}
|
|
903
957
|
function printError(prefix, message, hint, cause) {
|
|
904
|
-
const colors = paint(
|
|
905
|
-
const styled = takesControlCodes(
|
|
958
|
+
const colors = paint(process13.stderr);
|
|
959
|
+
const styled = takesControlCodes(process13.stderr);
|
|
906
960
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
907
961
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
908
962
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -921,7 +975,7 @@ function reportThrown(prefix, error, redact = (text) => text, json = false) {
|
|
|
921
975
|
const help = error instanceof UsageError ? `run ${prefix} --help for its options` : undefined;
|
|
922
976
|
const named = error instanceof Error && !(error instanceof Exit) && error.name !== "Error" ? `${error.name}: ${error.message}` : undefined;
|
|
923
977
|
const cause = error instanceof Error && error.cause instanceof Error ? redact(error.cause.message) : undefined;
|
|
924
|
-
if (error instanceof
|
|
978
|
+
if (error instanceof Exit && error.code === 2)
|
|
925
979
|
noteUsageError(error.message);
|
|
926
980
|
const report = json ? printJsonError : (message, hint, causeText) => printError(prefix, message, hint, causeText);
|
|
927
981
|
report(redact(named ?? (error instanceof Error ? error.message : String(error))), error instanceof Exit ? error.hint ?? help : undefined, cause);
|
|
@@ -945,11 +999,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
945
999
|
}
|
|
946
1000
|
}
|
|
947
1001
|
if (name === undefined && level.path.length > 1) {
|
|
948
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1002
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stderr));
|
|
949
1003
|
return 2;
|
|
950
1004
|
}
|
|
951
1005
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
952
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1006
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process13.stdout));
|
|
953
1007
|
return 0;
|
|
954
1008
|
}
|
|
955
1009
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1066,17 +1120,17 @@ async function printCandidates(found) {
|
|
|
1066
1120
|
return 0;
|
|
1067
1121
|
}
|
|
1068
1122
|
function packageVersion(entry = Bun.main) {
|
|
1069
|
-
for (let dir =
|
|
1123
|
+
for (let dir = dirname3(realpathSync(entry));; dir = dirname3(dir)) {
|
|
1070
1124
|
try {
|
|
1071
|
-
const { version } = JSON.parse(
|
|
1125
|
+
const { version } = JSON.parse(readFileSync2(join5(dir, "package.json"), "utf8"));
|
|
1072
1126
|
if (typeof version === "string")
|
|
1073
1127
|
return version;
|
|
1074
1128
|
} catch {}
|
|
1075
|
-
if (
|
|
1129
|
+
if (dirname3(dir) === dir)
|
|
1076
1130
|
return "0.0.0";
|
|
1077
1131
|
}
|
|
1078
1132
|
}
|
|
1079
|
-
async function runCli(cli, argv =
|
|
1133
|
+
async function runCli(cli, argv = process13.argv.slice(2)) {
|
|
1080
1134
|
const version = cli.version ?? packageVersion();
|
|
1081
1135
|
if (argv[0] === COMPLETE)
|
|
1082
1136
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -1119,6 +1173,8 @@ function jsonLines(text) {
|
|
|
1119
1173
|
return trimmed.startsWith("[") ? JSON.parse(trimmed) : trimmed.split(`
|
|
1120
1174
|
`).map((line) => JSON.parse(line));
|
|
1121
1175
|
}
|
|
1176
|
+
// ../kit/src/folders.ts
|
|
1177
|
+
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1122
1178
|
// ../kit/src/secrets.ts
|
|
1123
1179
|
var SECRET_PART = /token|secret|passw|credential|private|dsn|apikey|accesskey|key$/i;
|
|
1124
1180
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
@@ -1130,25 +1186,6 @@ function isSecretName(name) {
|
|
|
1130
1186
|
var {Glob } = globalThis.Bun;
|
|
1131
1187
|
var SESSION_FILES = new Glob("*.json");
|
|
1132
1188
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1133
|
-
// ../kit/src/user-config.ts
|
|
1134
|
-
import { existsSync } from "fs";
|
|
1135
|
-
import { homedir as homedir2 } from "os";
|
|
1136
|
-
import { join as join3 } from "path";
|
|
1137
|
-
import process10 from "process";
|
|
1138
|
-
function configBase(where = {}) {
|
|
1139
|
-
const xdg = where.xdg ?? (where.home === undefined ? process10.env.XDG_CONFIG_HOME : undefined);
|
|
1140
|
-
return xdg !== undefined && xdg !== "" ? xdg : join3(where.home ?? homedir2(), ".config");
|
|
1141
|
-
}
|
|
1142
|
-
function userConfigPath(bin, where = {}) {
|
|
1143
|
-
return join3(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
1144
|
-
}
|
|
1145
|
-
function userConfigReadPath(bin, legacy = [], where = {}) {
|
|
1146
|
-
const current = userConfigPath(bin, where);
|
|
1147
|
-
if (existsSync(current))
|
|
1148
|
-
return current;
|
|
1149
|
-
const base = configBase(where);
|
|
1150
|
-
return legacy.map((parts) => join3(base, ...parts)).find((path) => existsSync(path)) ?? current;
|
|
1151
|
-
}
|
|
1152
1189
|
// src/args.ts
|
|
1153
1190
|
var DEFAULT_ENV = "DATABASE_URL";
|
|
1154
1191
|
var DEFAULT_LIMIT = 20;
|
|
@@ -1515,7 +1552,7 @@ function shape(rows, limit, raw, exact = true) {
|
|
|
1515
1552
|
}
|
|
1516
1553
|
function render(shown, json) {
|
|
1517
1554
|
if (json)
|
|
1518
|
-
return
|
|
1555
|
+
return jsonText({ columns: shown.columns, rows: shown.rows, ...shown.exact ? { total: shown.total, omitted: shown.omitted } : {}, truncated: shown.truncated, masked: shown.masked }, jsonValue);
|
|
1519
1556
|
if (shown.total === 0)
|
|
1520
1557
|
return "no rows";
|
|
1521
1558
|
const lines = [table([
|
|
@@ -1534,7 +1571,7 @@ function render(shown, json) {
|
|
|
1534
1571
|
|
|
1535
1572
|
// src/run.ts
|
|
1536
1573
|
import { isIP } from "net";
|
|
1537
|
-
import
|
|
1574
|
+
import process15 from "process";
|
|
1538
1575
|
var {SQL } = globalThis.Bun;
|
|
1539
1576
|
|
|
1540
1577
|
// src/compose.ts
|
|
@@ -1789,7 +1826,7 @@ async function connectionUrl({ env, service, container, database }, home) {
|
|
|
1789
1826
|
if (service !== undefined && container !== undefined)
|
|
1790
1827
|
fail("--service and --container name two databases: pick one");
|
|
1791
1828
|
const isNamed = service !== undefined || container !== undefined;
|
|
1792
|
-
const value = isNamed ? undefined :
|
|
1829
|
+
const value = isNamed ? undefined : process15.env[env ?? DEFAULT_ENV];
|
|
1793
1830
|
let url;
|
|
1794
1831
|
if (value !== undefined && value !== "")
|
|
1795
1832
|
url = await reachable(value, home);
|
|
@@ -1985,7 +2022,7 @@ async function query(args) {
|
|
|
1985
2022
|
return handBack(sql, verdict.reasons, databaseOfUrl(url).endsWith(TEST_SUFFIX) ? `; not run on this ${TEST_SUFFIX} database either: ${written.reasons.join("; ")}` : "");
|
|
1986
2023
|
const shown = shape(written.rows, limit, values.raw === true, false);
|
|
1987
2024
|
if (values.json === true)
|
|
1988
|
-
console.log(
|
|
2025
|
+
console.log(jsonText({ database: written.database, affected: written.affected, columns: shown.columns, rows: shown.rows, truncated: shown.truncated, masked: shown.masked }, jsonValue));
|
|
1989
2026
|
else
|
|
1990
2027
|
console.log(`ran on ${written.database}, ${written.affected} ${written.affected === 1 ? "row" : "rows"} affected${written.rows.length === 0 ? "" : `
|
|
1991
2028
|
${render(shown, false)}`}`);
|
|
@@ -2190,7 +2227,7 @@ ${HOSTS_NOTE}`;
|
|
|
2190
2227
|
const indexes = await ask(plans.indexes);
|
|
2191
2228
|
const foreignKeys = await ask(plans.foreignKeys);
|
|
2192
2229
|
if (values.json === true)
|
|
2193
|
-
console.log(
|
|
2230
|
+
console.log(jsonText({ columns: columns.columns, rows: columns.rows, truncated: columns.truncated, masked: columns.masked, indexes, foreignKeys }, jsonValue));
|
|
2194
2231
|
else
|
|
2195
2232
|
console.log(`${render(columns, false)}
|
|
2196
2233
|
|
|
@@ -2253,7 +2290,7 @@ ${HOSTS_NOTE}`, countOptions, (target, dialect, { where }) => countSql(target, d
|
|
|
2253
2290
|
}
|
|
2254
2291
|
|
|
2255
2292
|
// src/cli.ts
|
|
2256
|
-
|
|
2293
|
+
process16.exitCode = await runCli({
|
|
2257
2294
|
name: "db",
|
|
2258
2295
|
about: "read-only SQL against Postgres, MySQL and MariaDB, credentials never shown, writes only on a _test database",
|
|
2259
2296
|
replaces: "psql or mysql with the connection string on the command line, docker exec <container> psql -U ...",
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-db",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.12.0",
|
|
5
5
|
"description": "db: run read-only SQL against Postgres, MySQL and MariaDB from the terminal without ever showing the connection credentials.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"db": "$npm_execpath src/cli.ts"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@kaynooo/cli-kit": "0.
|
|
31
|
+
"@kaynooo/cli-kit": "0.35.0"
|
|
32
32
|
}
|
|
33
33
|
}
|