politty 0.2.0 → 0.2.2

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 (32) hide show
  1. package/dist/{command-DCpFEZFM.js → command-D-P2Pc3J.js} +1 -1
  2. package/dist/{command-DCpFEZFM.js.map → command-D-P2Pc3J.js.map} +1 -1
  3. package/dist/completion/index.cjs +1 -0
  4. package/dist/completion/index.cjs.map +1 -1
  5. package/dist/completion/index.js +2 -2
  6. package/dist/docs/index.cjs +47 -21
  7. package/dist/docs/index.cjs.map +1 -1
  8. package/dist/docs/index.d.cts +6 -6
  9. package/dist/docs/index.d.cts.map +1 -1
  10. package/dist/docs/index.d.ts +6 -6
  11. package/dist/docs/index.d.ts.map +1 -1
  12. package/dist/docs/index.js +33 -22
  13. package/dist/docs/index.js.map +1 -1
  14. package/dist/index.cjs +4 -1
  15. package/dist/index.d.cts +30 -1
  16. package/dist/index.d.cts.map +1 -1
  17. package/dist/index.d.ts +30 -1
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +4 -4
  20. package/dist/{runner-ttyvfYGi.cjs → runner-B38UBqhv.cjs} +336 -8
  21. package/dist/runner-B38UBqhv.cjs.map +1 -0
  22. package/dist/{runner-CyxuNkT1.js → runner-CUN50BqK.js} +338 -11
  23. package/dist/runner-CUN50BqK.js.map +1 -0
  24. package/dist/{schema-extractor-D0q5Fj2R.js → schema-extractor-1YXqFSDT.js} +1 -1
  25. package/dist/{schema-extractor-D0q5Fj2R.js.map → schema-extractor-1YXqFSDT.js.map} +1 -1
  26. package/dist/{subcommand-router-D9QSLX56.js → subcommand-router-DtCeT_O9.js} +1 -1
  27. package/dist/{subcommand-router-D9QSLX56.js.map → subcommand-router-DtCeT_O9.js.map} +1 -1
  28. package/package.json +22 -25
  29. package/dist/runner-BkhekqT9.cjs +0 -4
  30. package/dist/runner-CyxuNkT1.js.map +0 -1
  31. package/dist/runner-DzzbIwEy.js +0 -4
  32. package/dist/runner-ttyvfYGi.cjs.map +0 -1
@@ -1,8 +1,25 @@
1
- import { n as getExtractedFields, t as extractFields } from "./schema-extractor-D0q5Fj2R.js";
2
- import { a as emptyLogs, i as createLogCollector, n as resolveLazyCommand, o as mergeLogs, r as resolveSubcommand, t as listSubCommands } from "./subcommand-router-D9QSLX56.js";
1
+ import { n as getExtractedFields, t as extractFields } from "./schema-extractor-1YXqFSDT.js";
2
+ import { a as emptyLogs, i as createLogCollector, n as resolveLazyCommand, o as mergeLogs, r as resolveSubcommand, t as listSubCommands } from "./subcommand-router-DtCeT_O9.js";
3
3
  import { z } from "zod";
4
4
  import { styleText } from "node:util";
5
5
 
6
+ //#region \0rolldown/runtime.js
7
+ var __defProp = Object.defineProperty;
8
+ var __exportAll = (all, no_symbols) => {
9
+ let target = {};
10
+ for (var name in all) {
11
+ __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
15
+ }
16
+ if (!no_symbols) {
17
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
18
+ }
19
+ return target;
20
+ };
21
+
22
+ //#endregion
6
23
  //#region src/executor/command-runner.ts
7
24
  /**
8
25
  * Execute a command lifecycle: setup → run → cleanup
@@ -140,7 +157,7 @@ const styles = {
140
157
  white: createStyleFn("white"),
141
158
  gray: createStyleFn("gray"),
142
159
  command: createStyleFn("bold"),
143
- commandName: createStyleFn("bold", "cyan"),
160
+ commandName: createStyleFn("bold", "underline", "cyan"),
144
161
  option: createStyleFn("cyan"),
145
162
  optionName: createStyleFn("bold"),
146
163
  placeholder: createStyleFn("dim"),
@@ -188,6 +205,311 @@ const logger = {
188
205
  }
189
206
  };
190
207
 
208
+ //#endregion
209
+ //#region src/output/markdown-renderer.ts
210
+ /**
211
+ * Lightweight Markdown-to-terminal renderer.
212
+ *
213
+ * Supports a subset of Markdown tailored for CLI help notes:
214
+ * - Inline: bold, italic, inline code, links
215
+ * - Block: paragraphs, unordered/ordered lists, blockquotes, headings,
216
+ * horizontal rules, fenced code blocks
217
+ */
218
+ /**
219
+ * Apply inline Markdown formatting to a string.
220
+ *
221
+ * Processing order matters to avoid conflicts:
222
+ * 1. Inline code (backticks) — content inside is literal, no further processing
223
+ * 2. Bold (**text**)
224
+ * 3. Italic (*text* or _text_)
225
+ * 4. Links [text](url)
226
+ */
227
+ function renderInline(text) {
228
+ const codeSpans = [];
229
+ let result = text.replace(/`([^`]+)`/g, (_match, code) => {
230
+ const index = codeSpans.length;
231
+ codeSpans.push(styles.cyan(code));
232
+ return `\x00CODE${index}\x00`;
233
+ });
234
+ result = result.replace(/\*\*(.+?)\*\*/g, (_match, content) => styles.bold(content));
235
+ result = result.replace(/__(.+?)__/g, (_match, content) => styles.bold(content));
236
+ result = result.replace(/\*(.+?)\*/g, (_match, content) => styles.italic(content));
237
+ result = result.replace(/(?<!\w)_(.+?)_(?!\w)/g, (_match, content) => styles.italic(content));
238
+ result = result.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_match, linkText, url) => `${styles.underline(linkText)} ${styles.dim(`(${url})`)}`);
239
+ result = result.replace(/\x00CODE(\d+)\x00/g, (_match, index) => codeSpans[Number(index)]);
240
+ return result;
241
+ }
242
+ /**
243
+ * Render a Markdown string to styled terminal output.
244
+ *
245
+ * Block-level processing:
246
+ * - Splits input into blocks separated by blank lines
247
+ * - Detects headings, horizontal rules, blockquotes, lists, code blocks, and paragraphs
248
+ * - Applies inline formatting within each block
249
+ */
250
+ function renderMarkdown(markdown) {
251
+ return splitIntoBlocks(markdown.split("\n")).map(renderBlock).join("\n\n");
252
+ }
253
+ const HEADING_RE = /^(#{1,6})\s+(.+)$/;
254
+ const HR_RE = /^(?:---+|\*\*\*+|___+)\s*$/;
255
+ const BLOCKQUOTE_RE = /^>\s?(.*)$/;
256
+ const UL_RE = /^-\s+(.+)$/;
257
+ const OL_RE = /^(\d+)[.)]\s+(.+)$/;
258
+ const FENCE_OPEN_RE = /^(`{3,}|~{3,})(\S*)\s*$/;
259
+ const ALERT_RE = /^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*$/;
260
+ const TABLE_ROW_RE = /^\|(.+)\|$/;
261
+ const TABLE_SEP_RE = /^\|(\s*:?-+:?\s*\|)+$/;
262
+ /**
263
+ * Split lines into logical blocks separated by blank lines.
264
+ * Consecutive lines of the same block type are grouped together.
265
+ */
266
+ function splitIntoBlocks(lines) {
267
+ const blocks = [];
268
+ let i = 0;
269
+ while (i < lines.length) {
270
+ const line = lines[i];
271
+ if (line.trim() === "") {
272
+ i++;
273
+ continue;
274
+ }
275
+ const fenceMatch = line.match(FENCE_OPEN_RE);
276
+ if (fenceMatch) {
277
+ const fence = fenceMatch[1];
278
+ const lang = fenceMatch[2] ?? "";
279
+ const codeLines = [];
280
+ i++;
281
+ while (i < lines.length) {
282
+ if (lines[i].startsWith(fence.charAt(0).repeat(fence.length)) && lines[i].trim() === fence.charAt(0).repeat(Math.max(fence.length, lines[i].trim().length))) {
283
+ i++;
284
+ break;
285
+ }
286
+ codeLines.push(lines[i]);
287
+ i++;
288
+ }
289
+ blocks.push({
290
+ type: "code",
291
+ lang,
292
+ lines: codeLines
293
+ });
294
+ continue;
295
+ }
296
+ const headingMatch = line.match(HEADING_RE);
297
+ if (headingMatch) {
298
+ blocks.push({
299
+ type: "heading",
300
+ level: headingMatch[1].length,
301
+ content: headingMatch[2]
302
+ });
303
+ i++;
304
+ continue;
305
+ }
306
+ if (HR_RE.test(line)) {
307
+ blocks.push({ type: "hr" });
308
+ i++;
309
+ continue;
310
+ }
311
+ if (BLOCKQUOTE_RE.test(line)) {
312
+ const bqLines = [];
313
+ while (i < lines.length) {
314
+ const bqMatch = lines[i].match(BLOCKQUOTE_RE);
315
+ if (bqMatch) {
316
+ bqLines.push(bqMatch[1]);
317
+ i++;
318
+ } else break;
319
+ }
320
+ if (bqLines.length > 0) {
321
+ const alertMatch = bqLines[0].match(ALERT_RE);
322
+ if (alertMatch) {
323
+ const contentLines = bqLines.slice(1).filter((l) => l !== "");
324
+ blocks.push({
325
+ type: "alert",
326
+ alertType: alertMatch[1],
327
+ lines: contentLines
328
+ });
329
+ continue;
330
+ }
331
+ }
332
+ blocks.push({
333
+ type: "blockquote",
334
+ lines: bqLines
335
+ });
336
+ continue;
337
+ }
338
+ if (UL_RE.test(line)) {
339
+ const items = [];
340
+ while (i < lines.length) {
341
+ const ulMatch = lines[i].match(UL_RE);
342
+ if (ulMatch) {
343
+ items.push(ulMatch[1]);
344
+ i++;
345
+ } else break;
346
+ }
347
+ blocks.push({
348
+ type: "ul",
349
+ items
350
+ });
351
+ continue;
352
+ }
353
+ const olMatch = line.match(OL_RE);
354
+ if (olMatch) {
355
+ const start = Number(olMatch[1]);
356
+ const items = [];
357
+ while (i < lines.length) {
358
+ const match = lines[i].match(OL_RE);
359
+ if (match) {
360
+ items.push(match[2]);
361
+ i++;
362
+ } else break;
363
+ }
364
+ blocks.push({
365
+ type: "ol",
366
+ items,
367
+ start
368
+ });
369
+ continue;
370
+ }
371
+ if (TABLE_ROW_RE.test(line) && i + 1 < lines.length && TABLE_SEP_RE.test(lines[i + 1])) {
372
+ const headers = parseCells(line);
373
+ const alignments = parseAlignments(lines[i + 1]);
374
+ i += 2;
375
+ const rows = [];
376
+ while (i < lines.length && TABLE_ROW_RE.test(lines[i])) {
377
+ rows.push(parseCells(lines[i]));
378
+ i++;
379
+ }
380
+ blocks.push({
381
+ type: "table",
382
+ headers,
383
+ alignments,
384
+ rows
385
+ });
386
+ continue;
387
+ }
388
+ const paraLines = [];
389
+ while (i < lines.length) {
390
+ const l = lines[i];
391
+ if (l.trim() === "" || HEADING_RE.test(l) || HR_RE.test(l) || BLOCKQUOTE_RE.test(l) || UL_RE.test(l) || OL_RE.test(l) || FENCE_OPEN_RE.test(l) || TABLE_ROW_RE.test(l) && i + 1 < lines.length && TABLE_SEP_RE.test(lines[i + 1])) break;
392
+ paraLines.push(l);
393
+ i++;
394
+ }
395
+ if (paraLines.length > 0) blocks.push({
396
+ type: "paragraph",
397
+ lines: paraLines
398
+ });
399
+ }
400
+ return blocks;
401
+ }
402
+ /**
403
+ * Parse cells from a table row: `| a | b | c |` → `["a", "b", "c"]`
404
+ */
405
+ function parseCells(row) {
406
+ return row.slice(1, -1).split("|").map((cell) => cell.trim());
407
+ }
408
+ /**
409
+ * Parse alignment from separator row: `|:---|:---:|---:|` → `["left", "center", "right"]`
410
+ */
411
+ function parseAlignments(sepRow) {
412
+ return sepRow.slice(1, -1).split("|").map((cell) => {
413
+ const trimmed = cell.trim();
414
+ if (trimmed.startsWith(":") && trimmed.endsWith(":")) return "center";
415
+ if (trimmed.endsWith(":")) return "right";
416
+ return "left";
417
+ });
418
+ }
419
+ /**
420
+ * Pad a string to a given width with the specified alignment.
421
+ */
422
+ function alignText(text, width, alignment) {
423
+ if (alignment === "right") return text.padStart(width);
424
+ if (alignment === "center") {
425
+ const total = width - text.length;
426
+ const left = Math.floor(total / 2);
427
+ return " ".repeat(left) + text + " ".repeat(total - left);
428
+ }
429
+ return text.padEnd(width);
430
+ }
431
+ /**
432
+ * Style configuration for GitHub-style alert blocks.
433
+ */
434
+ const alertStyles = {
435
+ NOTE: {
436
+ icon: "ℹ",
437
+ label: "Note",
438
+ styleFn: styles.cyan
439
+ },
440
+ TIP: {
441
+ icon: "💡",
442
+ label: "Tip",
443
+ styleFn: styles.green
444
+ },
445
+ IMPORTANT: {
446
+ icon: "❗",
447
+ label: "Important",
448
+ styleFn: styles.magenta
449
+ },
450
+ WARNING: {
451
+ icon: "⚠",
452
+ label: "Warning",
453
+ styleFn: styles.yellow
454
+ },
455
+ CAUTION: {
456
+ icon: "🔴",
457
+ label: "Caution",
458
+ styleFn: styles.red
459
+ }
460
+ };
461
+ /**
462
+ * Render a single block to styled terminal output.
463
+ */
464
+ function renderBlock(block) {
465
+ switch (block.type) {
466
+ case "heading": return styles.green(styles.bold(renderInline(block.content)));
467
+ case "hr": return styles.dim("─".repeat(40));
468
+ case "blockquote": {
469
+ const prefix = styles.dim("│ ");
470
+ return block.lines.map((line) => `${prefix}${renderInline(line)}`).join("\n");
471
+ }
472
+ case "alert": {
473
+ const { icon, label, styleFn } = alertStyles[block.alertType];
474
+ const prefix = styleFn(styles.bold("│")) + " ";
475
+ const header = `${prefix}${styleFn(icon)} ${styleFn(label)}`;
476
+ if (block.lines.length === 0) return header;
477
+ return `${header}\n${block.lines.map((line) => `${prefix}${renderInline(line)}`).join("\n")}`;
478
+ }
479
+ case "ul": return block.items.map((item) => `${styles.dim("•")} ${renderInline(item)}`).join("\n");
480
+ case "ol": {
481
+ const maxNum = block.start + block.items.length - 1;
482
+ const width = String(maxNum).length;
483
+ return block.items.map((item, i) => {
484
+ const num = String(block.start + i).padStart(width, " ");
485
+ return `${styles.dim(`${num}.`)} ${renderInline(item)}`;
486
+ }).join("\n");
487
+ }
488
+ case "table": {
489
+ const colCount = block.headers.length;
490
+ const colWidths = block.headers.map((h, i) => {
491
+ const cellLengths = block.rows.map((row) => (row[i] ?? "").length);
492
+ return Math.max(h.length, ...cellLengths);
493
+ });
494
+ const pipe = styles.dim("│");
495
+ const topBorder = styles.dim(`┌─${colWidths.map((w) => "─".repeat(w)).join("─┬─")}─┐`);
496
+ const midBorder = styles.dim(`├─${colWidths.map((w) => "─".repeat(w)).join("─┼─")}─┤`);
497
+ const botBorder = styles.dim(`└─${colWidths.map((w) => "─".repeat(w)).join("─┴─")}─┘`);
498
+ return [
499
+ topBorder,
500
+ `${pipe} ${block.headers.map((h, i) => styles.bold(alignText(h, colWidths[i], block.alignments[i] ?? "left"))).join(` ${pipe} `)} ${pipe}`,
501
+ midBorder,
502
+ ...block.rows.map((row) => {
503
+ return `${pipe} ${Array.from({ length: colCount }, (_, i) => renderInline(alignText(row[i] ?? "", colWidths[i], block.alignments[i] ?? "left"))).join(` ${pipe} `)} ${pipe}`;
504
+ }),
505
+ botBorder
506
+ ].join("\n");
507
+ }
508
+ case "code": return block.lines.map((line) => ` ${styles.yellow(line)}`).join("\n");
509
+ case "paragraph": return renderInline(block.lines.join(" "));
510
+ }
511
+ }
512
+
191
513
  //#endregion
192
514
  //#region src/output/help-generator.ts
193
515
  /**
@@ -453,17 +775,15 @@ function renderSubcommandsWithOptions(subCommands, parentPath, baseIndent) {
453
775
  function generateHelp(command, options) {
454
776
  const sections = [];
455
777
  const context = options.context;
456
- const headerLines = [];
457
778
  const displayName = buildFullCommandName(command, context);
458
779
  if (displayName) {
459
780
  let header = styles.commandName(displayName);
460
781
  if (context?.rootName && context.commandPath && context.commandPath.length > 0) if (context.rootVersion) header += ` ${styles.version(`(${context.rootName} v${context.rootVersion})`)}`;
461
782
  else header += ` ${styles.version(`(${context.rootName})`)}`;
462
783
  else if (context?.rootVersion) header += ` ${styles.version(`v${context.rootVersion}`)}`;
463
- headerLines.push(header);
784
+ sections.push(header);
464
785
  }
465
- if (command.description) headerLines.push(command.description);
466
- if (headerLines.length > 0) sections.push(headerLines.join("\n"));
786
+ if (command.description) sections.push(command.description);
467
787
  sections.push(`${styles.sectionHeader("Usage:")} ${renderUsageLine(command, context)}`);
468
788
  const optionsText = renderOptions(command, options.descriptions, context);
469
789
  if (optionsText) sections.push(`${styles.sectionHeader("Options:")}\n${optionsText}`);
@@ -486,8 +806,11 @@ function generateHelp(command, options) {
486
806
  const exampleLines = renderExamplesForHelp(command.examples, context);
487
807
  sections.push(`${styles.sectionHeader("Examples:")}\n${exampleLines}`);
488
808
  }
489
- if (command.notes) sections.push(`${styles.sectionHeader("Notes:")}\n${command.notes}`);
490
- return sections.join("\n\n");
809
+ if (command.notes) {
810
+ const indented = renderMarkdown(command.notes).split("\n").map((line) => line === "" ? "" : ` ${line}`).join("\n");
811
+ sections.push(`${styles.sectionHeader("Notes:")}\n${indented}`);
812
+ }
813
+ return `\n${sections.join("\n\n")}\n`;
491
814
  }
492
815
  /**
493
816
  * Render examples for CLI help output
@@ -1148,6 +1471,10 @@ function formatValidationErrors(errors) {
1148
1471
 
1149
1472
  //#endregion
1150
1473
  //#region src/core/runner.ts
1474
+ var runner_exports = /* @__PURE__ */ __exportAll({
1475
+ runCommand: () => runCommand,
1476
+ runMain: () => runMain
1477
+ });
1151
1478
  /**
1152
1479
  * Default logger using console
1153
1480
  */
@@ -1368,5 +1695,5 @@ async function runCommandInternal(command, argv, options = {}) {
1368
1695
  }
1369
1696
 
1370
1697
  //#endregion
1371
- export { logger as _, formatCommandValidationErrors as a, symbols as b, validateDuplicateFields as c, DuplicateAliasError as d, DuplicateFieldError as f, isColorEnabled as g, generateHelp as h, parseArgv as i, validatePositionalConfig as l, ReservedAliasError as m, runMain as n, validateCommand as o, PositionalConfigError as p, formatValidationErrors as r, validateDuplicateAliases as s, runCommand as t, validateReservedAliases as u, setColorEnabled as v, styles as y };
1372
- //# sourceMappingURL=runner-CyxuNkT1.js.map
1698
+ export { symbols as C, styles as S, renderInline as _, parseArgv as a, logger as b, validateDuplicateAliases as c, validateReservedAliases as d, DuplicateAliasError as f, generateHelp as g, ReservedAliasError as h, formatValidationErrors as i, validateDuplicateFields as l, PositionalConfigError as m, runMain as n, formatCommandValidationErrors as o, DuplicateFieldError as p, runner_exports as r, validateCommand as s, runCommand as t, validatePositionalConfig as u, renderMarkdown as v, setColorEnabled as x, isColorEnabled as y };
1699
+ //# sourceMappingURL=runner-CUN50BqK.js.map