@kaynooo/cli-probe 0.4.6 → 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.
Files changed (2) hide show
  1. package/dist/probe.js +12 -6
  2. package/package.json +2 -2
package/dist/probe.js CHANGED
@@ -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
- return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
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)) {
@@ -656,7 +658,7 @@ function parse(args, usage, options, settings = {}) {
656
658
  const values = parsed.values;
657
659
  applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
658
660
  if (values.help === true) {
659
- 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 }));
660
662
  throw new HelpShown;
661
663
  }
662
664
  checkChoices(parsed.values, all);
@@ -793,7 +795,7 @@ function nearestOption(message, options, allowNegative) {
793
795
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
794
796
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
795
797
  }
796
- var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
798
+ var DASHES, EXIT, Exit, UsageError, HelpShown, completion, heading, OUTPUT_OPTIONS, UNKNOWN_OPTION;
797
799
  var init_args = __esm(() => {
798
800
  init_format();
799
801
  init_help();
@@ -828,6 +830,7 @@ var init_args = __esm(() => {
828
830
  }
829
831
  };
830
832
  completion = { active: false };
833
+ heading = { bin: undefined };
831
834
  OUTPUT_OPTIONS = {
832
835
  color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
833
836
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
@@ -1217,10 +1220,13 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
1217
1220
  }
1218
1221
  let code;
1219
1222
  const started = performance.now();
1223
+ heading.bin = { name, version: () => version ?? packageVersion() };
1220
1224
  try {
1221
1225
  code = await run(argv);
1222
1226
  } catch (error) {
1223
1227
  code = reportThrown(name, error, redact, wantsJson(argv));
1228
+ } finally {
1229
+ heading.bin = undefined;
1224
1230
  }
1225
1231
  notifyEnd(name, code, performance.now() - started);
1226
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.6",
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",
@@ -35,6 +35,6 @@
35
35
  "probe": "$npm_execpath src/probe.ts"
36
36
  },
37
37
  "devDependencies": {
38
- "@kaynooo/cli-kit": "0.46.4"
38
+ "@kaynooo/cli-kit": "0.46.5"
39
39
  }
40
40
  }