@kaynooo/cli-dev 0.3.0 → 0.5.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/README.md +1 -0
- package/dist/cli.js +146 -286
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ bun add -g @kaynooo/cli-dev
|
|
|
16
16
|
| `dev b64 [-d] [--url] [text]` | base64 of the text, or with `-d` the text behind it (either alphabet, padding optional) |
|
|
17
17
|
| `dev url [url]` | the parts of a URL and its decoded query |
|
|
18
18
|
| `dev hash <sha256\|sha1\|md5\|sha512> [file]` | the hex digest of a file or of stdin |
|
|
19
|
+
| `dev ip [-4\|-6]` | the public IP address of this host, over IPv4 or IPv6 only when asked (needs `curl`) |
|
|
19
20
|
|
|
20
21
|
`--json` prints the structured result of every command. `jwt` and `ts` take `--zone <IANA zone>` for the local dates instead of the host's.
|
|
21
22
|
|
package/dist/cli.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#!/usr/bin/env -S bun --no-env-file
|
|
1
|
+
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
2
|
// @bun
|
|
3
3
|
|
|
4
4
|
// src/cli.ts
|
|
5
|
-
import
|
|
5
|
+
import process11 from "process";
|
|
6
6
|
// ../kit/src/args.ts
|
|
7
7
|
import process6 from "process";
|
|
8
8
|
import { parseArgs } from "util";
|
|
@@ -31,268 +31,63 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
31
31
|
// ../kit/src/style.ts
|
|
32
32
|
import process3 from "process";
|
|
33
33
|
|
|
34
|
-
// ../../node_modules/.bun/@kaynooo+utils@
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
35
|
+
var G = /^[a-f0-9]+$/i;
|
|
36
|
+
function b(r) {
|
|
37
|
+
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
38
|
+
if (!G.test(e))
|
|
38
39
|
return [0, 0, 0];
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
let
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
return `#${(r << 24 | t << 16 | n << 8 | Math.round((a ?? 1) * 255)).toString(16).padStart(8, "0").toUpperCase()}`;
|
|
55
|
-
return `#${(r << 16 | t << 8 | n).toString(16).padStart(6, "0").toUpperCase()}`;
|
|
56
|
-
}
|
|
57
|
-
function R(s, r, t) {
|
|
58
|
-
s = (s % 360 + 360) % 360, t /= 100;
|
|
59
|
-
let n = r * Math.min(t, 1 - t) / 100, a = (b) => {
|
|
60
|
-
let o = (b + s / 30) % 12, y = t - n * Math.max(Math.min(o - 3, 9 - o, 1), -1);
|
|
61
|
-
return Math.round(255 * y);
|
|
62
|
-
};
|
|
63
|
-
return [a(0), a(8), a(4)];
|
|
64
|
-
}
|
|
65
|
-
function k(s) {
|
|
66
|
-
let [r, t, n] = s;
|
|
67
|
-
r /= 255, t /= 255, n /= 255;
|
|
68
|
-
let a = Math.max(r, t, n), b = Math.min(r, t, n), o = 0, y = 0, c = (a + b) / 2;
|
|
69
|
-
if (a !== b) {
|
|
70
|
-
let u = a - b;
|
|
71
|
-
if (y = c > 0 && c < 1 ? u / (1 - Math.abs(2 * c - 1)) : 0, a === r)
|
|
72
|
-
o = (t - n) / u + (t < n ? 6 : 0);
|
|
73
|
-
else if (a === t)
|
|
74
|
-
o = (n - r) / u + 2;
|
|
75
|
-
else
|
|
76
|
-
o = (r - t) / u + 4;
|
|
77
|
-
o /= 6;
|
|
78
|
-
}
|
|
79
|
-
return [Math.round(o * 360), Math.round(y * 100), Math.round(c * 100)];
|
|
80
|
-
}
|
|
81
|
-
function H(s, r, t) {
|
|
82
|
-
s = (s % 360 + 360) % 360, r /= 100, t /= 100;
|
|
83
|
-
let n = (a) => {
|
|
84
|
-
let b = (a + s / 60) % 6, o = t - t * r * Math.max(Math.min(b, 4 - b, 1), 0);
|
|
85
|
-
return Math.round(255 * o);
|
|
86
|
-
};
|
|
87
|
-
return [n(5), n(3), n(1)];
|
|
88
|
-
}
|
|
89
|
-
function f(s) {
|
|
90
|
-
let [r, t, n] = s;
|
|
91
|
-
r /= 255, t /= 255, n /= 255;
|
|
92
|
-
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;
|
|
93
|
-
if (o !== 0) {
|
|
94
|
-
if (a === r)
|
|
95
|
-
y = (t - n) / o + (t < n ? 6 : 0);
|
|
96
|
-
else if (a === t)
|
|
97
|
-
y = (n - r) / o + 2;
|
|
98
|
-
else
|
|
99
|
-
y = (r - t) / o + 4;
|
|
100
|
-
y /= 6;
|
|
101
|
-
}
|
|
102
|
-
return [Math.round(y * 360), Math.round(c * 100), Math.round(u * 100)];
|
|
103
|
-
}
|
|
104
|
-
function O(s) {
|
|
105
|
-
let r = s[0] / 255, t = s[1] / 255, n = s[2] / 255, a = 1 - Math.max(r, t, n);
|
|
106
|
-
if (a === 1)
|
|
107
|
-
return [0, 0, 0, 100];
|
|
108
|
-
let b = (1 - r - a) / (1 - a), o = (1 - t - a) / (1 - a), y = (1 - n - a) / (1 - a);
|
|
109
|
-
return [Math.round(b * 100), Math.round(o * 100), Math.round(y * 100), Math.round(a * 100)];
|
|
110
|
-
}
|
|
111
|
-
function v(s, r, t, n) {
|
|
112
|
-
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))];
|
|
113
|
-
}
|
|
114
|
-
var m = (s) => s <= 0.04045 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
|
115
|
-
var p = (s) => s <= 0.0031308 ? 12.92 * s : 1.055 * s ** 0.4166666666666667 - 0.055;
|
|
116
|
-
var i = (s, r) => Math.round(s * 10 ** r) / 10 ** r;
|
|
117
|
-
function T(s) {
|
|
118
|
-
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);
|
|
119
|
-
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)];
|
|
120
|
-
}
|
|
121
|
-
function M(s, r, t) {
|
|
122
|
-
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)));
|
|
123
|
-
return [u(o), u(y), u(c)];
|
|
124
|
-
}
|
|
125
|
-
function d(s) {
|
|
126
|
-
let [r, t, n] = T(s), a = Math.sqrt(t * t + n * n), b = (Math.atan2(n, t) * 180 / Math.PI + 360) % 360;
|
|
127
|
-
return [i(r, 4), i(a, 4), i(b, 2)];
|
|
128
|
-
}
|
|
129
|
-
function C(s, r, t) {
|
|
130
|
-
let n = t * Math.PI / 180;
|
|
131
|
-
return M(s, r * Math.cos(n), r * Math.sin(n));
|
|
132
|
-
}
|
|
133
|
-
function l(s) {
|
|
134
|
-
let r = s / 255;
|
|
135
|
-
return r <= 0.03928 ? r / 12.92 : ((r + 0.055) / 1.055) ** 2.4;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
class e {
|
|
139
|
-
r;
|
|
140
|
-
g;
|
|
141
|
-
b;
|
|
142
|
-
a;
|
|
143
|
-
constructor(s, r, t, n = 1) {
|
|
144
|
-
this.r = s, this.g = r, this.b = t, this.a = n;
|
|
145
|
-
}
|
|
146
|
-
static from(s, r) {
|
|
147
|
-
if (s === "hex") {
|
|
148
|
-
let [t, n, a, b] = x(r);
|
|
149
|
-
return new e(t, n, a, b);
|
|
150
|
-
}
|
|
151
|
-
if (s === "rgb") {
|
|
152
|
-
if (Array.isArray(r)) {
|
|
153
|
-
let [o, y, c, u] = r;
|
|
154
|
-
return new e(o, y, c, u);
|
|
155
|
-
}
|
|
156
|
-
let { r: t, g: n, b: a, a: b } = r;
|
|
157
|
-
return new e(t, n, a, b);
|
|
158
|
-
}
|
|
159
|
-
if (s === "hsl") {
|
|
160
|
-
let t, n, a, b;
|
|
161
|
-
if (Array.isArray(r))
|
|
162
|
-
[t, n, a, b] = r;
|
|
163
|
-
else
|
|
164
|
-
({ h: t, s: n, l: a, a: b } = r);
|
|
165
|
-
let [o, y, c] = R(t, n, a);
|
|
166
|
-
return new e(o, y, c, b);
|
|
167
|
-
}
|
|
168
|
-
if (s === "hsv") {
|
|
169
|
-
let t, n, a, b;
|
|
170
|
-
if (Array.isArray(r))
|
|
171
|
-
[t, n, a, b] = r;
|
|
172
|
-
else
|
|
173
|
-
({ h: t, s: n, v: a, a: b } = r);
|
|
174
|
-
let [o, y, c] = H(t, n, a);
|
|
175
|
-
return new e(o, y, c, b);
|
|
176
|
-
}
|
|
177
|
-
if (s === "cmyk") {
|
|
178
|
-
let t, n, a, b, o;
|
|
179
|
-
if (Array.isArray(r))
|
|
180
|
-
[t, n, a, b, o] = r;
|
|
181
|
-
else
|
|
182
|
-
({ c: t, m: n, y: a, k: b, a: o } = r);
|
|
183
|
-
let [y, c, u] = v(t, n, a, b);
|
|
184
|
-
return new e(y, c, u, o);
|
|
185
|
-
}
|
|
186
|
-
if (s === "oklch") {
|
|
187
|
-
let t, n, a, b;
|
|
188
|
-
if (Array.isArray(r))
|
|
189
|
-
[t, n, a, b] = r;
|
|
190
|
-
else
|
|
191
|
-
({ l: t, c: n, h: a, a: b } = r);
|
|
192
|
-
let [o, y, c] = C(t, n, a);
|
|
193
|
-
return new e(o, y, c, b);
|
|
194
|
-
}
|
|
195
|
-
if (s === "oklab") {
|
|
196
|
-
let t, n, a, b;
|
|
197
|
-
if (Array.isArray(r))
|
|
198
|
-
[t, n, a, b] = r;
|
|
199
|
-
else
|
|
200
|
-
({ l: t, a: n, b: a, alpha: b } = r);
|
|
201
|
-
let [o, y, c] = M(t, n, a);
|
|
202
|
-
return new e(o, y, c, b);
|
|
203
|
-
}
|
|
204
|
-
throw Error("Invalid input");
|
|
205
|
-
}
|
|
206
|
-
to(s) {
|
|
207
|
-
switch (s) {
|
|
208
|
-
case "rgb":
|
|
209
|
-
return [this.r, this.g, this.b];
|
|
210
|
-
case "rgba":
|
|
211
|
-
return [this.r, this.g, this.b, this.a];
|
|
212
|
-
case "hex":
|
|
213
|
-
return A([this.r, this.g, this.b]);
|
|
214
|
-
case "hexa":
|
|
215
|
-
return A([this.r, this.g, this.b, this.a]);
|
|
216
|
-
case "hsl":
|
|
217
|
-
return k([this.r, this.g, this.b]);
|
|
218
|
-
case "hsla":
|
|
219
|
-
return [...k([this.r, this.g, this.b]), this.a];
|
|
220
|
-
case "hsv":
|
|
221
|
-
return f([this.r, this.g, this.b]);
|
|
222
|
-
case "hsva":
|
|
223
|
-
return [...f([this.r, this.g, this.b]), this.a];
|
|
224
|
-
case "cmyk":
|
|
225
|
-
return O([this.r, this.g, this.b]);
|
|
226
|
-
case "cmyka":
|
|
227
|
-
return [...O([this.r, this.g, this.b]), this.a];
|
|
228
|
-
case "oklch":
|
|
229
|
-
return d([this.r, this.g, this.b]);
|
|
230
|
-
case "oklcha":
|
|
231
|
-
return [...d([this.r, this.g, this.b]), this.a];
|
|
232
|
-
case "oklab":
|
|
233
|
-
return T([this.r, this.g, this.b]);
|
|
234
|
-
case "oklaba":
|
|
235
|
-
return [...T([this.r, this.g, this.b]), this.a];
|
|
236
|
-
default:
|
|
237
|
-
return [this.r, this.g, this.b];
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
getLuminance() {
|
|
241
|
-
let s = l(this.r), r = l(this.g), t = l(this.b);
|
|
242
|
-
return 0.2126 * s + 0.7152 * r + 0.0722 * t;
|
|
243
|
-
}
|
|
244
|
-
contrastRatio(s) {
|
|
245
|
-
let r = this.getLuminance(), t = s.getLuminance(), [n, a] = r >= t ? [r, t] : [t, r];
|
|
246
|
-
return (n + 0.05) / (a + 0.05);
|
|
247
|
-
}
|
|
248
|
-
bestContrastForeground() {
|
|
249
|
-
let s = new e(255, 255, 255, 1), r = new e(0, 0, 0, 1), t = this.contrastRatio(s), n = this.contrastRatio(r);
|
|
250
|
-
return t >= n ? s : r;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// ../../node_modules/.bun/@kaynooo+utils@2.31.2+d0769e28dc4dad16/node_modules/@kaynooo/utils/dist/chunk-y1msbssb.js
|
|
255
|
-
var r = 39;
|
|
256
|
-
var o = 49;
|
|
257
|
-
var f2 = "\x1B[";
|
|
258
|
-
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") => {
|
|
259
|
-
let [a, l, s] = e.from("hex", i).to("rgb");
|
|
260
|
-
return [`${n === "fg" ? 38 : 48};2;${a};${l};${s}`, n === "fg" ? r : o];
|
|
261
|
-
}, ansi256: (i, n = "fg") => [`${n === "fg" ? 38 : 48};5;${i}`, n === "fg" ? r : o] };
|
|
262
|
-
var b = new Set(["", "1", "2", "3", "true"]);
|
|
263
|
-
function h(i, n = globalThis.process?.env ?? {}) {
|
|
264
|
-
if (n.FORCE_COLOR !== undefined)
|
|
265
|
-
return b.has(n.FORCE_COLOR);
|
|
266
|
-
if (n.NO_COLOR !== undefined || n.NODE_DISABLE_COLORS !== undefined || n.TERM === "dumb")
|
|
40
|
+
if (e.length === 3 || e.length === 4)
|
|
41
|
+
return [Number.parseInt(e[0] + e[0], 16), Number.parseInt(e[1] + e[1], 16), Number.parseInt(e[2] + e[2], 16)];
|
|
42
|
+
if (e.length !== 6 && e.length !== 8)
|
|
43
|
+
throw Error(`Invalid hex color length: ${e.length}`);
|
|
44
|
+
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
45
|
+
}
|
|
46
|
+
var B = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
47
|
+
let [l, n, c] = b(r);
|
|
48
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
49
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
50
|
+
var h = new Set(["", "1", "2", "3", "true"]);
|
|
51
|
+
function C(r, e = globalThis.process?.env ?? {}) {
|
|
52
|
+
if (e.FORCE_COLOR !== undefined)
|
|
53
|
+
return h.has(e.FORCE_COLOR);
|
|
54
|
+
if (e.NO_COLOR !== undefined || e.NODE_DISABLE_COLORS !== undefined || e.TERM === "dumb")
|
|
267
55
|
return false;
|
|
268
|
-
return
|
|
269
|
-
}
|
|
270
|
-
function
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
if (
|
|
284
|
-
return
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
56
|
+
return r?.isTTY === true;
|
|
57
|
+
}
|
|
58
|
+
function f(r, e = []) {
|
|
59
|
+
let l = "", n = "";
|
|
60
|
+
for (let t = 0, i = e.length;t < i; t++)
|
|
61
|
+
l += `\x1B[${e[t][0]}m`, n = `\x1B[${e[t][1]}m${n}`;
|
|
62
|
+
let c = (t) => C(r.stream ?? globalThis.process?.stdout, r.env) ? l + t + n : t, g = new Map;
|
|
63
|
+
return new Proxy(c, { get(t, i) {
|
|
64
|
+
let a = B[i];
|
|
65
|
+
if (Array.isArray(a)) {
|
|
66
|
+
let s = g.get(i);
|
|
67
|
+
if (s === undefined)
|
|
68
|
+
s = f(r, [...e, a]), g.set(i, s);
|
|
69
|
+
return s;
|
|
70
|
+
}
|
|
71
|
+
if (typeof a === "function")
|
|
72
|
+
return (...s) => {
|
|
73
|
+
let y = `${i}:${s.join(",")}`, u = g.get(y);
|
|
74
|
+
if (u === undefined) {
|
|
75
|
+
if (g.size >= 64)
|
|
76
|
+
g.clear();
|
|
77
|
+
u = f(r, [...e, a(...s)]), g.set(y, u);
|
|
78
|
+
}
|
|
79
|
+
return u;
|
|
80
|
+
};
|
|
81
|
+
throw Error(`Unknown style: ${String(i)}`);
|
|
288
82
|
} });
|
|
289
83
|
}
|
|
290
|
-
function
|
|
291
|
-
return
|
|
84
|
+
function Fe(r = {}) {
|
|
85
|
+
return f(r);
|
|
292
86
|
}
|
|
293
|
-
var
|
|
87
|
+
var o = Fe();
|
|
294
88
|
|
|
295
89
|
// ../kit/src/theme.ts
|
|
90
|
+
var ENDS = new Map;
|
|
296
91
|
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"]);
|
|
297
92
|
var MAX_FILE_BYTES = 64 * 1024;
|
|
298
93
|
var warned = new Set;
|
|
@@ -302,7 +97,7 @@ function takesControlCodes(stream, env = process3.env) {
|
|
|
302
97
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
303
98
|
}
|
|
304
99
|
function paint(stream, env = process3.env) {
|
|
305
|
-
return
|
|
100
|
+
return Fe({ stream: { isTTY: takesControlCodes(stream, env) }, env });
|
|
306
101
|
}
|
|
307
102
|
var STATUS_WORDS = {
|
|
308
103
|
passed: ["passed", "success", "succeeded", "ok"],
|
|
@@ -635,6 +430,30 @@ function nearestOption(message, options, allowNegative) {
|
|
|
635
430
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
636
431
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
637
432
|
}
|
|
433
|
+
// ../kit/src/argv.ts
|
|
434
|
+
import { readFileSync, realpathSync } from "fs";
|
|
435
|
+
import { resolve } from "path";
|
|
436
|
+
import process7 from "process";
|
|
437
|
+
function commandLine() {
|
|
438
|
+
try {
|
|
439
|
+
return readFileSync("/proc/self/cmdline", "utf8").split("\x00").slice(0, -1);
|
|
440
|
+
} catch {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
function realPath(word) {
|
|
445
|
+
try {
|
|
446
|
+
return realpathSync(resolve(word));
|
|
447
|
+
} catch {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
function scriptArgs(argv = process7.argv.slice(2), cmdline = commandLine(), script = process7.argv[1]) {
|
|
452
|
+
const target = script === undefined ? undefined : realPath(script) ?? script;
|
|
453
|
+
const at = cmdline === undefined || target === undefined ? -1 : cmdline.findIndex((word, index) => index > 0 && (resolve(word) === script || realPath(word) === target));
|
|
454
|
+
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
455
|
+
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
456
|
+
}
|
|
638
457
|
// ../kit/src/process.ts
|
|
639
458
|
var CLIPBOARDS = [["wl-copy"], ["xclip", "-selection", "clipboard"], ["xsel", "--clipboard", "--input"], ["pbcopy"], ["clip.exe"]];
|
|
640
459
|
async function copyText(text, which = Bun.which) {
|
|
@@ -660,15 +479,15 @@ var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x
|
|
|
660
479
|
var RESET_STYLE = `${ESC}[0m`;
|
|
661
480
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
662
481
|
// ../kit/src/cli.ts
|
|
663
|
-
import { readFileSync, realpathSync } from "fs";
|
|
482
|
+
import { readFileSync as readFileSync2, realpathSync as realpathSync2 } from "fs";
|
|
664
483
|
import { dirname as dirname2, join as join2 } from "path";
|
|
665
|
-
import
|
|
484
|
+
import process9 from "process";
|
|
666
485
|
|
|
667
486
|
// ../kit/src/usage.ts
|
|
668
487
|
import { appendFileSync, mkdirSync } from "fs";
|
|
669
488
|
import { homedir } from "os";
|
|
670
489
|
import { dirname, isAbsolute, join } from "path";
|
|
671
|
-
import
|
|
490
|
+
import process8 from "process";
|
|
672
491
|
|
|
673
492
|
// ../kit/src/logs.ts
|
|
674
493
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -682,14 +501,14 @@ var usageError;
|
|
|
682
501
|
function noteUsageError(message) {
|
|
683
502
|
usageError = message;
|
|
684
503
|
}
|
|
685
|
-
function stateHome(env =
|
|
504
|
+
function stateHome(env = process8.env) {
|
|
686
505
|
const dir = env.XDG_STATE_HOME;
|
|
687
506
|
return dir !== undefined && isAbsolute(dir) ? dir : join(homedir(), ".local", "state");
|
|
688
507
|
}
|
|
689
|
-
function usagePath(env =
|
|
508
|
+
function usagePath(env = process8.env) {
|
|
690
509
|
return join(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
691
510
|
}
|
|
692
|
-
function usageRecorded(env =
|
|
511
|
+
function usageRecorded(env = process8.env) {
|
|
693
512
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
694
513
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
695
514
|
}
|
|
@@ -703,7 +522,7 @@ function usageEntry(bin, command, argv, code, now = new Date) {
|
|
|
703
522
|
usageError = undefined;
|
|
704
523
|
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
705
524
|
}
|
|
706
|
-
function recordUsage(entry, env =
|
|
525
|
+
function recordUsage(entry, env = process8.env) {
|
|
707
526
|
if (!usageRecorded(env))
|
|
708
527
|
return;
|
|
709
528
|
try {
|
|
@@ -794,8 +613,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
794
613
|
`);
|
|
795
614
|
}
|
|
796
615
|
function printError(prefix, message, hint, cause) {
|
|
797
|
-
const colors = paint(
|
|
798
|
-
const styled = takesControlCodes(
|
|
616
|
+
const colors = paint(process9.stderr);
|
|
617
|
+
const styled = takesControlCodes(process9.stderr);
|
|
799
618
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
800
619
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
801
620
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -838,11 +657,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
838
657
|
}
|
|
839
658
|
}
|
|
840
659
|
if (name === undefined && level.path.length > 1) {
|
|
841
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
660
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process9.stderr));
|
|
842
661
|
return 2;
|
|
843
662
|
}
|
|
844
663
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
845
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
664
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process9.stdout));
|
|
846
665
|
return 0;
|
|
847
666
|
}
|
|
848
667
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -898,24 +717,24 @@ function candidateLine(candidate) {
|
|
|
898
717
|
}
|
|
899
718
|
function positionalBeingTyped(before, { options, positionals }) {
|
|
900
719
|
const takesValue = (word) => !word.includes("=") && Object.entries(options).some(([name, { short, type }]) => type === "string" && (word === `--${name}` || word === `-${short}`));
|
|
901
|
-
|
|
720
|
+
const typed = [];
|
|
902
721
|
let at = 0;
|
|
903
722
|
while (at < before.length) {
|
|
904
723
|
const word = before[at];
|
|
905
724
|
if (word === "--") {
|
|
906
|
-
|
|
725
|
+
typed.push(...before.slice(at + 1));
|
|
907
726
|
break;
|
|
908
727
|
}
|
|
909
728
|
if (!word.startsWith("-"))
|
|
910
|
-
|
|
729
|
+
typed.push(word);
|
|
911
730
|
else if (takesValue(word))
|
|
912
731
|
at++;
|
|
913
732
|
at++;
|
|
914
733
|
}
|
|
915
734
|
const last = positionals.at(-1);
|
|
916
|
-
if (
|
|
917
|
-
return positionals[
|
|
918
|
-
return last?.replace("]", "").endsWith("...") === true ? last : undefined;
|
|
735
|
+
if (typed.length < positionals.length)
|
|
736
|
+
return { name: positionals[typed.length], typed };
|
|
737
|
+
return { name: last?.replace("]", "").endsWith("...") === true ? last : undefined, typed };
|
|
919
738
|
}
|
|
920
739
|
async function leafCandidates(run, words) {
|
|
921
740
|
const completing = await completingOf(run);
|
|
@@ -923,12 +742,12 @@ async function leafCandidates(run, words) {
|
|
|
923
742
|
return Object.entries(completing.options).map(([name, option]) => option.description === undefined ? `--${name}` : `--${name} ${option.description}`);
|
|
924
743
|
const flag = words.at(-2);
|
|
925
744
|
const option = flag?.startsWith("-") === true ? Object.entries(completing.options).find(([name, { short }]) => flag === `--${name}` || flag === `-${short}`)?.[1] : undefined;
|
|
745
|
+
const { name, typed } = positionalBeingTyped(words.slice(0, -1), completing);
|
|
926
746
|
if (option?.type === "string") {
|
|
927
|
-
const values = option.choices === undefined ? await option.candidates?.() : option.choices;
|
|
747
|
+
const values = option.choices === undefined ? await option.candidates?.(typed) : option.choices;
|
|
928
748
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
929
749
|
}
|
|
930
|
-
const
|
|
931
|
-
const values = name === undefined ? undefined : await completing.candidates[name]?.();
|
|
750
|
+
const values = name === undefined ? undefined : await completing.candidates[name]?.(typed);
|
|
932
751
|
return values === undefined ? [FILES] : values.map(candidateLine);
|
|
933
752
|
}
|
|
934
753
|
async function candidates(scope, defaultCommand, words, before = []) {
|
|
@@ -959,9 +778,9 @@ async function printCandidates(found) {
|
|
|
959
778
|
return 0;
|
|
960
779
|
}
|
|
961
780
|
function packageVersion(entry = Bun.main) {
|
|
962
|
-
for (let dir = dirname2(
|
|
781
|
+
for (let dir = dirname2(realpathSync2(entry));; dir = dirname2(dir)) {
|
|
963
782
|
try {
|
|
964
|
-
const { version } = JSON.parse(
|
|
783
|
+
const { version } = JSON.parse(readFileSync2(join2(dir, "package.json"), "utf8"));
|
|
965
784
|
if (typeof version === "string")
|
|
966
785
|
return version;
|
|
967
786
|
} catch {}
|
|
@@ -969,7 +788,7 @@ function packageVersion(entry = Bun.main) {
|
|
|
969
788
|
return "0.0.0";
|
|
970
789
|
}
|
|
971
790
|
}
|
|
972
|
-
async function runCli(cli, argv =
|
|
791
|
+
async function runCli(cli, argv = scriptArgs()) {
|
|
973
792
|
const version = cli.version ?? packageVersion();
|
|
974
793
|
if (argv[0] === COMPLETE)
|
|
975
794
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
@@ -996,6 +815,8 @@ function commandPath(scope, argv) {
|
|
|
996
815
|
}
|
|
997
816
|
return path.length === 0 ? undefined : path.join(" ");
|
|
998
817
|
}
|
|
818
|
+
// ../kit/src/folders.ts
|
|
819
|
+
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
999
820
|
// ../kit/src/secrets.ts
|
|
1000
821
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1001
822
|
// ../kit/src/sessions.ts
|
|
@@ -1050,6 +871,16 @@ function uuidV4() {
|
|
|
1050
871
|
return crypto.randomUUID();
|
|
1051
872
|
}
|
|
1052
873
|
|
|
874
|
+
// src/ip.ts
|
|
875
|
+
var IP_SERVICE = "https://ipecho.net/plain";
|
|
876
|
+
async function publicIp(family, service = IP_SERVICE) {
|
|
877
|
+
const child = Bun.spawn(["curl", "--silent", "--show-error", "--fail", "--max-time", "10", ...family === undefined ? [] : [`-${family}`], service], { stdout: "pipe", stderr: "pipe" });
|
|
878
|
+
const [out, err, code] = await Promise.all([child.stdout.text(), child.stderr.text(), child.exited]);
|
|
879
|
+
if (code !== 0)
|
|
880
|
+
throw new Error(err.trim() === "" ? `curl exited ${code}` : err.trim());
|
|
881
|
+
return out.trim();
|
|
882
|
+
}
|
|
883
|
+
|
|
1053
884
|
// src/time.ts
|
|
1054
885
|
var UNITS = [["d", 86400000], ["h", 3600000], ["m", 60000], ["s", 1000]];
|
|
1055
886
|
var DURATION_UNIT_MS = { ms: 1, s: 1000, m: 60000, h: 3600000, d: 86400000 };
|
|
@@ -1245,7 +1076,7 @@ async function bytesInput(argument, what) {
|
|
|
1245
1076
|
return new Uint8Array(await Bun.stdin.arrayBuffer());
|
|
1246
1077
|
}
|
|
1247
1078
|
function printRows(rows) {
|
|
1248
|
-
const { cyan } = paint(
|
|
1079
|
+
const { cyan } = paint(process11.stdout);
|
|
1249
1080
|
const width = Math.max(...rows.map(([label]) => label.length));
|
|
1250
1081
|
for (const [label, value] of rows)
|
|
1251
1082
|
console.log(`${cyan(label.padEnd(width))} ${value}`);
|
|
@@ -1280,7 +1111,7 @@ async function password(args) {
|
|
|
1280
1111
|
return 0;
|
|
1281
1112
|
}
|
|
1282
1113
|
if (copied)
|
|
1283
|
-
console.error(paint(
|
|
1114
|
+
console.error(paint(process11.stderr).dim("copied to clipboard"));
|
|
1284
1115
|
if (hash !== undefined && given === undefined)
|
|
1285
1116
|
console.error(secret);
|
|
1286
1117
|
console.log(hash ?? secret);
|
|
@@ -1308,7 +1139,7 @@ async function jwt(args) {
|
|
|
1308
1139
|
printJson({ header: decoded.header, payload: decoded.payload, claims, signatureBytes: decoded.signatureBytes });
|
|
1309
1140
|
return 0;
|
|
1310
1141
|
}
|
|
1311
|
-
const { bold } = paint(
|
|
1142
|
+
const { bold } = paint(process11.stdout);
|
|
1312
1143
|
console.log(`${bold("header")}
|
|
1313
1144
|
${JSON.stringify(decoded.header, null, 2)}
|
|
1314
1145
|
|
|
@@ -1461,8 +1292,35 @@ async function hash(args) {
|
|
|
1461
1292
|
console.log(digest);
|
|
1462
1293
|
return 0;
|
|
1463
1294
|
}
|
|
1295
|
+
var IP_USAGE = `dev ip [-4|-6]: the public IP address of this host, as a web service sees it
|
|
1296
|
+
|
|
1297
|
+
-4 or -6 asks over that IP family only, which fails when the host has no route over it.
|
|
1298
|
+
Exits 0 when it printed the address, 1 when the service could not be reached, 2 on a usage error.`;
|
|
1299
|
+
async function ip(args) {
|
|
1300
|
+
const { values } = parse(args, IP_USAGE, { 4: { type: "boolean", short: "4", description: "over IPv4 only" }, 6: { type: "boolean", short: "6", description: "over IPv6 only" }, json: jsonOption("{ip, family?}") }, {
|
|
1301
|
+
replaces: "curl https://ipecho.net/plain typed from memory",
|
|
1302
|
+
examples: ["dev ip", ["dev ip -6", "the IPv6 address"]]
|
|
1303
|
+
});
|
|
1304
|
+
if (values[4] === true && values[6] === true)
|
|
1305
|
+
badUsage("-4 and -6 cannot be combined");
|
|
1306
|
+
let family;
|
|
1307
|
+
if (values[4] === true)
|
|
1308
|
+
family = 4;
|
|
1309
|
+
else if (values[6] === true)
|
|
1310
|
+
family = 6;
|
|
1311
|
+
try {
|
|
1312
|
+
const address = await publicIp(family);
|
|
1313
|
+
if (values.json === true)
|
|
1314
|
+
printJson(family === undefined ? { ip: address } : { ip: address, family });
|
|
1315
|
+
else
|
|
1316
|
+
console.log(address);
|
|
1317
|
+
return 0;
|
|
1318
|
+
} catch (error) {
|
|
1319
|
+
return fail(`could not read the public address: ${error instanceof Error ? error.message : String(error)}`, 1);
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1464
1322
|
if (import.meta.main) {
|
|
1465
|
-
|
|
1323
|
+
process11.exitCode = await runCli({
|
|
1466
1324
|
name: "dev",
|
|
1467
1325
|
about: "small developer utilities: passwords and bcrypt hashes, JWTs, timestamps, UUIDs, base64, URLs and file hashes",
|
|
1468
1326
|
replaces: "openssl rand, htpasswd, jwt.io, date -d, uuidgen, base64, sha256sum and one-off scripts for each",
|
|
@@ -1475,13 +1333,15 @@ if (import.meta.main) {
|
|
|
1475
1333
|
ulid: { summary: "random ULIDs", run: async (args) => Promise.resolve(ulidCommand(args)) },
|
|
1476
1334
|
b64: { summary: "base64 encode or decode, standard or URL-safe", run: b64 },
|
|
1477
1335
|
url: { summary: "the parts of a URL and its decoded query", run: url },
|
|
1478
|
-
hash: { summary: "sha256, sha1, md5 or sha512 of a file or stdin", run: hash }
|
|
1336
|
+
hash: { summary: "sha256, sha1, md5 or sha512 of a file or stdin", run: hash },
|
|
1337
|
+
ip: { summary: "the public IP address of this host, IPv4 or IPv6", run: ip }
|
|
1479
1338
|
}
|
|
1480
1339
|
});
|
|
1481
1340
|
}
|
|
1482
1341
|
export {
|
|
1483
1342
|
b64,
|
|
1484
1343
|
hash,
|
|
1344
|
+
ip,
|
|
1485
1345
|
jwt,
|
|
1486
1346
|
password,
|
|
1487
1347
|
ts,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-dev",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"description": "dev: small developer utilities in one bin: random passwords and bcrypt hashes, JWT decoding, timestamps, UUIDs and ULIDs, base64, URL parts and file hashes.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -36,6 +36,6 @@
|
|
|
36
36
|
"dev": "$npm_execpath src/cli.ts"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@kaynooo/cli-kit": "0.
|
|
39
|
+
"@kaynooo/cli-kit": "0.38.1"
|
|
40
40
|
}
|
|
41
41
|
}
|