@kaynooo/cli-probe 0.4.5 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/probe.js +30 -13
- package/package.json +3 -3
package/dist/probe.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
#!/
|
|
2
|
-
// @bun
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
// @bun 2>/dev/null; exec bun --no-env-file --config=/dev/null "$0" "$@"
|
|
3
3
|
var __esm = (fn, res, err) => () => {
|
|
4
4
|
if (fn)
|
|
5
5
|
try {
|
|
@@ -466,7 +466,7 @@ var init_format = __esm(() => {
|
|
|
466
466
|
|
|
467
467
|
// ../kit/src/help.ts
|
|
468
468
|
import process8 from "process";
|
|
469
|
-
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
469
|
+
function usageLine(usage, colors = paint(process8.stdout), { summary: withSummary = true } = {}) {
|
|
470
470
|
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
471
471
|
`);
|
|
472
472
|
const blank = lines.indexOf("");
|
|
@@ -479,7 +479,7 @@ function usageLine(usage, colors = paint(process8.stdout)) {
|
|
|
479
479
|
synopses[0] = synopses[0].slice(0, colon);
|
|
480
480
|
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
481
481
|
`)}`;
|
|
482
|
-
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
482
|
+
const lead = summary === undefined || !withSummary ? [] : ["", colors.bold(prose(summary, colors))];
|
|
483
483
|
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
484
484
|
return [head, ...lead, ...rest].join(`
|
|
485
485
|
`);
|
|
@@ -489,8 +489,10 @@ function prose(line, colors) {
|
|
|
489
489
|
return line;
|
|
490
490
|
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
491
491
|
}
|
|
492
|
-
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
493
|
-
|
|
492
|
+
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [], bin } = {}) {
|
|
493
|
+
const { summary } = description(usage);
|
|
494
|
+
const head = bin === undefined ? [usageLine(usage, colors)] : [`${colors.bold(bin.name)} ${colors.dim(bin.version())}${summary === "" ? "" : ` ${summary}`}`, "", usageLine(usage, colors, { summary: false })];
|
|
495
|
+
return [...head, "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
494
496
|
`);
|
|
495
497
|
}
|
|
496
498
|
function exitRows(exits, colors = paint(process8.stdout)) {
|
|
@@ -575,20 +577,31 @@ function closest(name, names) {
|
|
|
575
577
|
var init_text2 = () => {};
|
|
576
578
|
|
|
577
579
|
// ../kit/src/input.ts
|
|
580
|
+
function durationMs(text, unit) {
|
|
581
|
+
if (BARE_DURATION.test(text))
|
|
582
|
+
return Number(text) * UNIT_MS[unit];
|
|
583
|
+
if (!DURATION.test(text))
|
|
584
|
+
return 0;
|
|
585
|
+
let ms = 0;
|
|
586
|
+
for (const [, amount, part] of text.matchAll(DURATION_PART))
|
|
587
|
+
ms += Number(amount) * UNIT_MS[part];
|
|
588
|
+
return ms;
|
|
589
|
+
}
|
|
578
590
|
function duration(value, name, fallback, unit = "s") {
|
|
579
591
|
if (value === undefined)
|
|
580
592
|
return fallback;
|
|
581
|
-
const
|
|
582
|
-
const ms = match === null ? 0 : Number(match[1]) * UNIT_MS[match[2] ?? unit];
|
|
593
|
+
const ms = durationMs(value.trim(), unit);
|
|
583
594
|
if (ms < 1)
|
|
584
595
|
badUsage(`--${name} takes a duration such as 30s, 5m, 1h or 7d, not ${value}`);
|
|
585
596
|
return ms;
|
|
586
597
|
}
|
|
587
|
-
var DURATION, UNIT_MS;
|
|
598
|
+
var BARE_DURATION, DURATION, DURATION_PART, UNIT_MS;
|
|
588
599
|
var init_input = __esm(() => {
|
|
589
600
|
init_args();
|
|
590
|
-
|
|
591
|
-
|
|
601
|
+
BARE_DURATION = /^\d+(?:\.\d+)?$/;
|
|
602
|
+
DURATION = /^(?:\d+(?:\.\d+)?(?:ms|min|[smhd]))+$/;
|
|
603
|
+
DURATION_PART = /(\d+(?:\.\d+)?)(ms|min|[smhd])/g;
|
|
604
|
+
UNIT_MS = { ms: 1, s: 1000, m: 60000, min: 60000, h: 3600000, d: 86400000 };
|
|
592
605
|
});
|
|
593
606
|
|
|
594
607
|
// ../kit/src/args.ts
|
|
@@ -645,7 +658,7 @@ function parse(args, usage, options, settings = {}) {
|
|
|
645
658
|
const values = parsed.values;
|
|
646
659
|
applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
|
|
647
660
|
if (values.help === true) {
|
|
648
|
-
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings, listing)) : helpText(usage, listing, undefined, settings));
|
|
661
|
+
console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings, listing)) : helpText(usage, listing, undefined, { ...settings, bin: heading.bin }));
|
|
649
662
|
throw new HelpShown;
|
|
650
663
|
}
|
|
651
664
|
checkChoices(parsed.values, all);
|
|
@@ -782,7 +795,7 @@ function nearestOption(message, options, allowNegative) {
|
|
|
782
795
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
783
796
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
784
797
|
}
|
|
785
|
-
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
798
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, heading, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
786
799
|
var init_args = __esm(() => {
|
|
787
800
|
init_format();
|
|
788
801
|
init_help();
|
|
@@ -817,6 +830,7 @@ var init_args = __esm(() => {
|
|
|
817
830
|
}
|
|
818
831
|
};
|
|
819
832
|
completion = { active: false };
|
|
833
|
+
heading = { bin: undefined };
|
|
820
834
|
OUTPUT_OPTIONS = {
|
|
821
835
|
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
822
836
|
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
@@ -1206,10 +1220,13 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
|
|
|
1206
1220
|
}
|
|
1207
1221
|
let code;
|
|
1208
1222
|
const started = performance.now();
|
|
1223
|
+
heading.bin = { name, version: () => version ?? packageVersion() };
|
|
1209
1224
|
try {
|
|
1210
1225
|
code = await run(argv);
|
|
1211
1226
|
} catch (error) {
|
|
1212
1227
|
code = reportThrown(name, error, redact, wantsJson(argv));
|
|
1228
|
+
} finally {
|
|
1229
|
+
heading.bin = undefined;
|
|
1213
1230
|
}
|
|
1214
1231
|
notifyEnd(name, code, performance.now() - started);
|
|
1215
1232
|
if (usage !== false) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-probe",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.7",
|
|
5
5
|
"description": "probe: a site's HTTP version, redirect chain, timings, addresses, TLS certificate and notable headers in one call, with warnings.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"registry": "https://git.kaynooo.fr/api/packages/kaynooo/npm/"
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
|
-
"build": "$npm_execpath build src/probe.ts --target bun --outdir dist",
|
|
34
|
+
"build": "$npm_execpath build src/probe.ts --target bun --outdir dist && $npm_execpath ../../scripts/shell-shebang.ts",
|
|
35
35
|
"probe": "$npm_execpath src/probe.ts"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@kaynooo/cli-kit": "0.46.
|
|
38
|
+
"@kaynooo/cli-kit": "0.46.5"
|
|
39
39
|
}
|
|
40
40
|
}
|