@kaynooo/cli-view 0.7.5 → 0.7.6

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/view.js +12 -6
  2. package/package.json +2 -2
package/dist/view.js CHANGED
@@ -422,7 +422,7 @@ var init_format = __esm(() => {
422
422
 
423
423
  // ../kit/src/help.ts
424
424
  import process8 from "process";
425
- function usageLine(usage, colors = paint(process8.stdout)) {
425
+ function usageLine(usage, colors = paint(process8.stdout), { summary: withSummary = true } = {}) {
426
426
  const lines = usage.replace(USAGE_PREFIX, "").split(`
427
427
  `);
428
428
  const blank = lines.indexOf("");
@@ -435,7 +435,7 @@ function usageLine(usage, colors = paint(process8.stdout)) {
435
435
  synopses[0] = synopses[0].slice(0, colon);
436
436
  const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
437
437
  `)}`;
438
- const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
438
+ const lead = summary === undefined || !withSummary ? [] : ["", colors.bold(prose(summary, colors))];
439
439
  const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
440
440
  return [head, ...lead, ...rest].join(`
441
441
  `);
@@ -445,8 +445,10 @@ function prose(line, colors) {
445
445
  return line;
446
446
  return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
447
447
  }
448
- function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
449
- return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
448
+ function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [], bin } = {}) {
449
+ const { summary } = description(usage);
450
+ const head = bin === undefined ? [usageLine(usage, colors)] : [`${colors.bold(bin.name)} ${colors.dim(bin.version())}${summary === "" ? "" : ` ${summary}`}`, "", usageLine(usage, colors, { summary: false })];
451
+ return [...head, "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
450
452
  `);
451
453
  }
452
454
  function exitRows(exits, colors = paint(process8.stdout)) {
@@ -629,7 +631,7 @@ function parse(args, usage, options, settings = {}) {
629
631
  const values = parsed.values;
630
632
  applyOutput("color" in output ? values.color : undefined, "plain" in output ? values.plain : undefined);
631
633
  if (values.help === true) {
632
- console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings, listing)) : helpText(usage, listing, undefined, settings));
634
+ console.log(wantsHelpJson() ? JSON.stringify(description(usage, settings, listing)) : helpText(usage, listing, undefined, { ...settings, bin: heading.bin }));
633
635
  throw new HelpShown;
634
636
  }
635
637
  checkChoices(parsed.values, all);
@@ -766,7 +768,7 @@ function nearestOption(message, options, allowNegative) {
766
768
  const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
767
769
  return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
768
770
  }
769
- var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
771
+ var DASHES, EXIT, Exit, UsageError, HelpShown, completion, heading, OUTPUT_OPTIONS, UNKNOWN_OPTION;
770
772
  var init_args = __esm(() => {
771
773
  init_format();
772
774
  init_help();
@@ -801,6 +803,7 @@ var init_args = __esm(() => {
801
803
  }
802
804
  };
803
805
  completion = { active: false };
806
+ heading = { bin: undefined };
804
807
  OUTPUT_OPTIONS = {
805
808
  color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
806
809
  plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
@@ -1189,10 +1192,13 @@ async function runMain({ name, version, run, redact, usage }, argv = scriptArgs(
1189
1192
  }
1190
1193
  let code;
1191
1194
  const started = performance.now();
1195
+ heading.bin = { name, version: () => version ?? packageVersion() };
1192
1196
  try {
1193
1197
  code = await run(argv);
1194
1198
  } catch (error) {
1195
1199
  code = reportThrown(name, error, redact, wantsJson(argv));
1200
+ } finally {
1201
+ heading.bin = undefined;
1196
1202
  }
1197
1203
  notifyEnd(name, code, performance.now() - started);
1198
1204
  if (usage !== false) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-view",
3
3
  "type": "module",
4
- "version": "0.7.5",
4
+ "version": "0.7.6",
5
5
  "description": "view: markdown files and git diffs shown in the colours of the other @kaynooo CLIs, paged when long.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -35,6 +35,6 @@
35
35
  "view": "$npm_execpath src/view.ts"
36
36
  },
37
37
  "devDependencies": {
38
- "@kaynooo/cli-kit": "0.46.4"
38
+ "@kaynooo/cli-kit": "0.46.5"
39
39
  }
40
40
  }