@optique/core 1.2.10 → 1.2.12

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.
@@ -8,6 +8,7 @@ const require_internal_dependency = require('./internal/dependency.cjs');
8
8
  const require_dependency_runtime = require('./dependency-runtime.cjs');
9
9
  const require_internal_parser = require('./internal/parser.cjs');
10
10
  const require_annotation_state = require('./annotation-state.cjs');
11
+ const require_command_doc_metadata = require('./internal/command-doc-metadata.cjs');
11
12
  const require_passthrough = require('./internal/passthrough.cjs');
12
13
  const require_command_alias = require('./internal/command-alias.cjs');
13
14
  const require_execution_context = require('./execution-context.cjs');
@@ -1351,6 +1352,7 @@ function or(...args) {
1351
1352
  },
1352
1353
  suggest: createExclusiveSuggest(parsers, combinedMode),
1353
1354
  getDocFragments(state, _defaultValue) {
1355
+ let commandMetadata;
1354
1356
  let brief;
1355
1357
  let description;
1356
1358
  let footer;
@@ -1363,18 +1365,19 @@ function or(...args) {
1363
1365
  state: parserResult.next.state
1364
1366
  } : { kind: "unavailable" };
1365
1367
  const docFragments = parsers[index].getDocFragments(innerState, void 0);
1368
+ commandMetadata = require_command_doc_metadata.getCommandDocMetadata(docFragments);
1366
1369
  brief = docFragments.brief;
1367
1370
  description = docFragments.description;
1368
1371
  footer = docFragments.footer;
1369
1372
  fragments = docFragments.fragments;
1370
1373
  }
1371
1374
  if (state.kind === "unavailable" || state.state == null) fragments = require_doc.deduplicateDocFragments(fragments);
1372
- return {
1375
+ return require_command_doc_metadata.withCommandDocMetadata({
1373
1376
  brief,
1374
1377
  description,
1375
1378
  footer,
1376
1379
  fragments
1377
- };
1380
+ }, commandMetadata);
1378
1381
  }
1379
1382
  };
1380
1383
  const singleDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -1582,6 +1585,7 @@ function createLongestMatch(...args) {
1582
1585
  },
1583
1586
  suggest: createExclusiveSuggest(parsers, combinedMode),
1584
1587
  getDocFragments(state, _defaultValue) {
1588
+ let commandMetadata;
1585
1589
  let brief;
1586
1590
  let description;
1587
1591
  let footer;
@@ -1597,6 +1601,7 @@ function createLongestMatch(...args) {
1597
1601
  kind: "available",
1598
1602
  state: result.next.state
1599
1603
  });
1604
+ commandMetadata = require_command_doc_metadata.getCommandDocMetadata(docResult);
1600
1605
  brief = docResult.brief;
1601
1606
  description = docResult.description;
1602
1607
  footer = docResult.footer;
@@ -1607,12 +1612,12 @@ function createLongestMatch(...args) {
1607
1612
  shouldDeduplicate = true;
1608
1613
  }
1609
1614
  }
1610
- return {
1615
+ return require_command_doc_metadata.withCommandDocMetadata({
1611
1616
  brief,
1612
1617
  description,
1613
1618
  fragments: shouldDeduplicate ? require_doc.deduplicateDocFragments(fragments) : fragments,
1614
1619
  footer
1615
- };
1620
+ }, commandMetadata);
1616
1621
  }
1617
1622
  };
1618
1623
  const multiDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -2584,12 +2589,15 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2584
2589
  }, () => suggestObjectAsync(context, prefix, parserPairs));
2585
2590
  },
2586
2591
  getDocFragments(state, defaultValue) {
2592
+ let commandMetadata;
2587
2593
  const fragments = parserPairs.flatMap(([field, p]) => {
2588
2594
  const fieldState = state.kind === "unavailable" ? { kind: "unavailable" } : {
2589
2595
  kind: "available",
2590
2596
  state: state.state[field]
2591
2597
  };
2592
- return p.getDocFragments(fieldState, defaultValue?.[field]).fragments;
2598
+ const docs = p.getDocFragments(fieldState, defaultValue?.[field]);
2599
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs);
2600
+ return docs.fragments;
2593
2601
  });
2594
2602
  const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
2595
2603
  const entries = hiddenAwareFragments.filter((d) => d.type === "entry");
@@ -2604,10 +2612,13 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2604
2612
  entries
2605
2613
  };
2606
2614
  sections.push(section);
2607
- return { fragments: sections.map((s) => ({
2608
- ...s,
2609
- type: "section"
2610
- })) };
2615
+ return require_command_doc_metadata.withCommandDocMetadata({
2616
+ ...commandMetadata,
2617
+ fragments: sections.map((s) => ({
2618
+ ...s,
2619
+ type: "section"
2620
+ }))
2621
+ }, commandMetadata);
2611
2622
  }
2612
2623
  };
2613
2624
  const fieldNormalizers = [];
@@ -3600,12 +3611,15 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3600
3611
  return require_mode_dispatch.dispatchIterableByMode(combinedMode, () => suggestTupleSync(context, prefix, syncParsers), () => suggestTupleAsync(context, prefix, parsers));
3601
3612
  },
3602
3613
  getDocFragments(state, defaultValue) {
3614
+ let commandMetadata;
3603
3615
  const fragments = syncParsers.flatMap((p, i) => {
3604
3616
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
3605
3617
  kind: "available",
3606
3618
  state: state.state[i]
3607
3619
  };
3608
- return p.getDocFragments(indexState, defaultValue?.[i]).fragments;
3620
+ const docs = p.getDocFragments(indexState, defaultValue?.[i]);
3621
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs);
3622
+ return docs.fragments;
3609
3623
  });
3610
3624
  const entries = fragments.filter((d) => d.type === "entry");
3611
3625
  const sections = [];
@@ -3619,10 +3633,13 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3619
3633
  entries
3620
3634
  };
3621
3635
  sections.push(section);
3622
- return { fragments: sections.map((s) => ({
3623
- ...s,
3624
- type: "section"
3625
- })) };
3636
+ return require_command_doc_metadata.withCommandDocMetadata({
3637
+ ...commandMetadata,
3638
+ fragments: sections.map((s) => ({
3639
+ ...s,
3640
+ type: "section"
3641
+ }))
3642
+ }, commandMetadata);
3626
3643
  },
3627
3644
  [Symbol.for("Deno.customInspect")]() {
3628
3645
  const parsersStr = parsers.length === 1 ? `[1 parser]` : `[${parsers.length} parsers]`;
@@ -4848,6 +4865,7 @@ function merge(...args) {
4848
4865
  }();
4849
4866
  },
4850
4867
  getDocFragments(state, _defaultValue) {
4868
+ let commandMetadata;
4851
4869
  let brief;
4852
4870
  let description;
4853
4871
  let footer;
@@ -4865,6 +4883,7 @@ function merge(...args) {
4865
4883
  state: state.state
4866
4884
  };
4867
4885
  const docFragments = p.getDocFragments(parserState, void 0);
4886
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docFragments, true);
4868
4887
  brief ??= docFragments.brief;
4869
4888
  description ??= docFragments.description;
4870
4889
  footer ??= docFragments.footer;
@@ -4884,7 +4903,7 @@ function merge(...args) {
4884
4903
  entries
4885
4904
  };
4886
4905
  sections.push(labeledSection);
4887
- return {
4906
+ return require_command_doc_metadata.withCommandDocMetadata({
4888
4907
  brief,
4889
4908
  description,
4890
4909
  footer,
@@ -4892,9 +4911,9 @@ function merge(...args) {
4892
4911
  ...s,
4893
4912
  type: "section"
4894
4913
  }))
4895
- };
4914
+ }, commandMetadata);
4896
4915
  }
4897
- return {
4916
+ return require_command_doc_metadata.withCommandDocMetadata({
4898
4917
  brief,
4899
4918
  description,
4900
4919
  footer,
@@ -4905,7 +4924,7 @@ function merge(...args) {
4905
4924
  type: "section",
4906
4925
  entries
4907
4926
  }]
4908
- };
4927
+ }, commandMetadata);
4909
4928
  }
4910
4929
  };
4911
4930
  require_internal_parser.defineParseLanes(mergeParser, mergeParseLanes);
@@ -5521,12 +5540,15 @@ function concat(...parsers) {
5521
5540
  }();
5522
5541
  },
5523
5542
  getDocFragments(state, _defaultValue) {
5543
+ let commandMetadata;
5524
5544
  const fragments = syncParsers.flatMap((p, index) => {
5525
5545
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
5526
5546
  kind: "available",
5527
5547
  state: state.state[index]
5528
5548
  };
5529
- return p.getDocFragments(indexState, void 0).fragments;
5549
+ const docs = p.getDocFragments(indexState, void 0);
5550
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs);
5551
+ return docs.fragments;
5530
5552
  });
5531
5553
  const entries = fragments.filter((f) => f.type === "entry");
5532
5554
  const sections = [];
@@ -5543,7 +5565,10 @@ function concat(...parsers) {
5543
5565
  type: "section",
5544
5566
  entries
5545
5567
  });
5546
- return { fragments: result };
5568
+ return require_command_doc_metadata.withCommandDocMetadata({
5569
+ ...commandMetadata,
5570
+ fragments: result
5571
+ }, commandMetadata);
5547
5572
  }
5548
5573
  };
5549
5574
  require_internal_parser.defineInheritedAnnotationParser(concatParser);
@@ -5579,7 +5604,8 @@ function group(label, parser, options = {}) {
5579
5604
  return parser.suggest(context, prefix);
5580
5605
  },
5581
5606
  getDocFragments: (state, defaultValue) => {
5582
- const { brief, description, footer, fragments } = parser.getDocFragments(state, defaultValue);
5607
+ const docs = parser.getDocFragments(state, defaultValue);
5608
+ const { brief, description, footer, fragments } = docs;
5583
5609
  const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
5584
5610
  const allEntries = [];
5585
5611
  const titledSections = [];
@@ -5602,7 +5628,7 @@ function group(label, parser, options = {}) {
5602
5628
  title: label,
5603
5629
  entries: allEntries
5604
5630
  } : { entries: allEntries };
5605
- return {
5631
+ return require_command_doc_metadata.withCommandDocMetadata({
5606
5632
  brief,
5607
5633
  description,
5608
5634
  footer,
@@ -5613,7 +5639,7 @@ function group(label, parser, options = {}) {
5613
5639
  type: "section",
5614
5640
  ...labeledSection
5615
5641
  }]
5616
- };
5642
+ }, require_command_doc_metadata.getCommandDocMetadata(docs));
5617
5643
  }
5618
5644
  };
5619
5645
  require_internal_parser.defineParseLanes(groupParser, require_internal_parser.getOwnParseLanes(parser));
@@ -8,6 +8,7 @@ import { createDependencySourceState, dependencyId, isDependencySourceState, isP
8
8
  import { buildRuntimeNodesFromArray, buildRuntimeNodesFromPairs, collectExplicitSourceValues, collectExplicitSourceValuesAsync, collectSourcesFromState, createDependencyRuntimeContext, fillMissingSourceDefaults, fillMissingSourceDefaultsAsync, resolveStateWithRuntime, resolveStateWithRuntimeAsync } from "./dependency-runtime.js";
9
9
  import { defineInheritedAnnotationParser, defineParseLanes, getOwnParseLanes, getParserSuggestRuntimeNodes, unmatchedNonCliDependencySourceStateMarker } from "./internal/parser.js";
10
10
  import { annotationViewTargets, getWrappedChildParseState, getWrappedChildState, reconcileObjectChildState, unwrapAnnotationView } from "./annotation-state.js";
11
+ import { collectCommandDocMetadata, getCommandDocMetadata, withCommandDocMetadata } from "./internal/command-doc-metadata.js";
11
12
  import { combineOptionMatches, combinePassThroughPriorities, defineOptionMatch, definePassThroughPriority, delegateKnownCompletion, getKnownCompletion, getOptionMatch, getPassThroughFailureHint, getPassThroughPriority, hasPassThroughUsage, matchesOptionToken, retainConsumingFailure, retainConsumingFailureHint, withPassThroughFailure } from "./internal/passthrough.js";
12
13
  import { allowDuplicateLeadingCommandNamesKey } from "./internal/command-alias.js";
13
14
  import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
@@ -1351,6 +1352,7 @@ function or(...args) {
1351
1352
  },
1352
1353
  suggest: createExclusiveSuggest(parsers, combinedMode),
1353
1354
  getDocFragments(state, _defaultValue) {
1355
+ let commandMetadata;
1354
1356
  let brief;
1355
1357
  let description;
1356
1358
  let footer;
@@ -1363,18 +1365,19 @@ function or(...args) {
1363
1365
  state: parserResult.next.state
1364
1366
  } : { kind: "unavailable" };
1365
1367
  const docFragments = parsers[index].getDocFragments(innerState, void 0);
1368
+ commandMetadata = getCommandDocMetadata(docFragments);
1366
1369
  brief = docFragments.brief;
1367
1370
  description = docFragments.description;
1368
1371
  footer = docFragments.footer;
1369
1372
  fragments = docFragments.fragments;
1370
1373
  }
1371
1374
  if (state.kind === "unavailable" || state.state == null) fragments = deduplicateDocFragments(fragments);
1372
- return {
1375
+ return withCommandDocMetadata({
1373
1376
  brief,
1374
1377
  description,
1375
1378
  footer,
1376
1379
  fragments
1377
- };
1380
+ }, commandMetadata);
1378
1381
  }
1379
1382
  };
1380
1383
  const singleDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -1582,6 +1585,7 @@ function createLongestMatch(...args) {
1582
1585
  },
1583
1586
  suggest: createExclusiveSuggest(parsers, combinedMode),
1584
1587
  getDocFragments(state, _defaultValue) {
1588
+ let commandMetadata;
1585
1589
  let brief;
1586
1590
  let description;
1587
1591
  let footer;
@@ -1597,6 +1601,7 @@ function createLongestMatch(...args) {
1597
1601
  kind: "available",
1598
1602
  state: result.next.state
1599
1603
  });
1604
+ commandMetadata = getCommandDocMetadata(docResult);
1600
1605
  brief = docResult.brief;
1601
1606
  description = docResult.description;
1602
1607
  footer = docResult.footer;
@@ -1607,12 +1612,12 @@ function createLongestMatch(...args) {
1607
1612
  shouldDeduplicate = true;
1608
1613
  }
1609
1614
  }
1610
- return {
1615
+ return withCommandDocMetadata({
1611
1616
  brief,
1612
1617
  description,
1613
1618
  fragments: shouldDeduplicate ? deduplicateDocFragments(fragments) : fragments,
1614
1619
  footer
1615
- };
1620
+ }, commandMetadata);
1616
1621
  }
1617
1622
  };
1618
1623
  const multiDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -2584,12 +2589,15 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2584
2589
  }, () => suggestObjectAsync(context, prefix, parserPairs));
2585
2590
  },
2586
2591
  getDocFragments(state, defaultValue) {
2592
+ let commandMetadata;
2587
2593
  const fragments = parserPairs.flatMap(([field, p]) => {
2588
2594
  const fieldState = state.kind === "unavailable" ? { kind: "unavailable" } : {
2589
2595
  kind: "available",
2590
2596
  state: state.state[field]
2591
2597
  };
2592
- return p.getDocFragments(fieldState, defaultValue?.[field]).fragments;
2598
+ const docs = p.getDocFragments(fieldState, defaultValue?.[field]);
2599
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docs);
2600
+ return docs.fragments;
2593
2601
  });
2594
2602
  const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
2595
2603
  const entries = hiddenAwareFragments.filter((d) => d.type === "entry");
@@ -2604,10 +2612,13 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
2604
2612
  entries
2605
2613
  };
2606
2614
  sections.push(section);
2607
- return { fragments: sections.map((s) => ({
2608
- ...s,
2609
- type: "section"
2610
- })) };
2615
+ return withCommandDocMetadata({
2616
+ ...commandMetadata,
2617
+ fragments: sections.map((s) => ({
2618
+ ...s,
2619
+ type: "section"
2620
+ }))
2621
+ }, commandMetadata);
2611
2622
  }
2612
2623
  };
2613
2624
  const fieldNormalizers = [];
@@ -3600,12 +3611,15 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3600
3611
  return dispatchIterableByMode(combinedMode, () => suggestTupleSync(context, prefix, syncParsers), () => suggestTupleAsync(context, prefix, parsers));
3601
3612
  },
3602
3613
  getDocFragments(state, defaultValue) {
3614
+ let commandMetadata;
3603
3615
  const fragments = syncParsers.flatMap((p, i) => {
3604
3616
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
3605
3617
  kind: "available",
3606
3618
  state: state.state[i]
3607
3619
  };
3608
- return p.getDocFragments(indexState, defaultValue?.[i]).fragments;
3620
+ const docs = p.getDocFragments(indexState, defaultValue?.[i]);
3621
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docs);
3622
+ return docs.fragments;
3609
3623
  });
3610
3624
  const entries = fragments.filter((d) => d.type === "entry");
3611
3625
  const sections = [];
@@ -3619,10 +3633,13 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3619
3633
  entries
3620
3634
  };
3621
3635
  sections.push(section);
3622
- return { fragments: sections.map((s) => ({
3623
- ...s,
3624
- type: "section"
3625
- })) };
3636
+ return withCommandDocMetadata({
3637
+ ...commandMetadata,
3638
+ fragments: sections.map((s) => ({
3639
+ ...s,
3640
+ type: "section"
3641
+ }))
3642
+ }, commandMetadata);
3626
3643
  },
3627
3644
  [Symbol.for("Deno.customInspect")]() {
3628
3645
  const parsersStr = parsers.length === 1 ? `[1 parser]` : `[${parsers.length} parsers]`;
@@ -4848,6 +4865,7 @@ function merge(...args) {
4848
4865
  }();
4849
4866
  },
4850
4867
  getDocFragments(state, _defaultValue) {
4868
+ let commandMetadata;
4851
4869
  let brief;
4852
4870
  let description;
4853
4871
  let footer;
@@ -4865,6 +4883,7 @@ function merge(...args) {
4865
4883
  state: state.state
4866
4884
  };
4867
4885
  const docFragments = p.getDocFragments(parserState, void 0);
4886
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docFragments, true);
4868
4887
  brief ??= docFragments.brief;
4869
4888
  description ??= docFragments.description;
4870
4889
  footer ??= docFragments.footer;
@@ -4884,7 +4903,7 @@ function merge(...args) {
4884
4903
  entries
4885
4904
  };
4886
4905
  sections.push(labeledSection);
4887
- return {
4906
+ return withCommandDocMetadata({
4888
4907
  brief,
4889
4908
  description,
4890
4909
  footer,
@@ -4892,9 +4911,9 @@ function merge(...args) {
4892
4911
  ...s,
4893
4912
  type: "section"
4894
4913
  }))
4895
- };
4914
+ }, commandMetadata);
4896
4915
  }
4897
- return {
4916
+ return withCommandDocMetadata({
4898
4917
  brief,
4899
4918
  description,
4900
4919
  footer,
@@ -4905,7 +4924,7 @@ function merge(...args) {
4905
4924
  type: "section",
4906
4925
  entries
4907
4926
  }]
4908
- };
4927
+ }, commandMetadata);
4909
4928
  }
4910
4929
  };
4911
4930
  defineParseLanes(mergeParser, mergeParseLanes);
@@ -5521,12 +5540,15 @@ function concat(...parsers) {
5521
5540
  }();
5522
5541
  },
5523
5542
  getDocFragments(state, _defaultValue) {
5543
+ let commandMetadata;
5524
5544
  const fragments = syncParsers.flatMap((p, index) => {
5525
5545
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
5526
5546
  kind: "available",
5527
5547
  state: state.state[index]
5528
5548
  };
5529
- return p.getDocFragments(indexState, void 0).fragments;
5549
+ const docs = p.getDocFragments(indexState, void 0);
5550
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docs);
5551
+ return docs.fragments;
5530
5552
  });
5531
5553
  const entries = fragments.filter((f) => f.type === "entry");
5532
5554
  const sections = [];
@@ -5543,7 +5565,10 @@ function concat(...parsers) {
5543
5565
  type: "section",
5544
5566
  entries
5545
5567
  });
5546
- return { fragments: result };
5568
+ return withCommandDocMetadata({
5569
+ ...commandMetadata,
5570
+ fragments: result
5571
+ }, commandMetadata);
5547
5572
  }
5548
5573
  };
5549
5574
  defineInheritedAnnotationParser(concatParser);
@@ -5579,7 +5604,8 @@ function group(label, parser, options = {}) {
5579
5604
  return parser.suggest(context, prefix);
5580
5605
  },
5581
5606
  getDocFragments: (state, defaultValue) => {
5582
- const { brief, description, footer, fragments } = parser.getDocFragments(state, defaultValue);
5607
+ const docs = parser.getDocFragments(state, defaultValue);
5608
+ const { brief, description, footer, fragments } = docs;
5583
5609
  const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
5584
5610
  const allEntries = [];
5585
5611
  const titledSections = [];
@@ -5602,7 +5628,7 @@ function group(label, parser, options = {}) {
5602
5628
  title: label,
5603
5629
  entries: allEntries
5604
5630
  } : { entries: allEntries };
5605
- return {
5631
+ return withCommandDocMetadata({
5606
5632
  brief,
5607
5633
  description,
5608
5634
  footer,
@@ -5613,7 +5639,7 @@ function group(label, parser, options = {}) {
5613
5639
  type: "section",
5614
5640
  ...labeledSection
5615
5641
  }]
5616
- };
5642
+ }, getCommandDocMetadata(docs));
5617
5643
  }
5618
5644
  };
5619
5645
  defineParseLanes(groupParser, getOwnParseLanes(parser));
@@ -0,0 +1,90 @@
1
+
2
+ //#region src/internal/command-doc-metadata.ts
3
+ function withOrigin(metadata, origin) {
4
+ const result = { ...metadata };
5
+ Object.defineProperty(result, "origin", {
6
+ value: origin,
7
+ enumerable: false
8
+ });
9
+ return result;
10
+ }
11
+ const commandDocMetadata = Symbol.for("@optique/core/commandDocMetadata");
12
+ const commandDocCarrier = Symbol.for("@optique/core/commandDocMetadataCarrier");
13
+ /**
14
+ * Reads effective page metadata, including custom collection-level fields.
15
+ * @param docs The child's documentation.
16
+ * @returns Its selected-command metadata, if any.
17
+ */
18
+ function getCommandDocMetadata(docs) {
19
+ const carrier = docs.fragments[commandDocCarrier];
20
+ if (carrier != null) {
21
+ const brief = docs.brief === carrier.brief ? carrier.metadata.brief : docs.brief;
22
+ const origin = carrier.metadata.origin ?? "entry";
23
+ const customPage = origin === "entry" && (docs.brief !== carrier.brief || docs.footer !== carrier.footer);
24
+ const description = origin === "entry" && !customPage || docs.description === carrier.description ? carrier.metadata.description : docs.description;
25
+ const footer = docs.footer === carrier.footer ? carrier.metadata.footer : docs.footer;
26
+ return withOrigin({
27
+ ...brief == null ? {} : { brief },
28
+ ...description == null ? {} : { description },
29
+ ...footer == null ? {} : { footer }
30
+ }, customPage ? "custom" : origin);
31
+ }
32
+ const metadata = docs[commandDocMetadata];
33
+ if (metadata != null) return metadata;
34
+ return docs.brief != null || docs.description != null || docs.footer != null ? withOrigin({
35
+ brief: docs.brief,
36
+ description: docs.description,
37
+ footer: docs.footer
38
+ }, "custom") : void 0;
39
+ }
40
+ /**
41
+ * Preserves selected-command metadata when rebuilding documentation fragments.
42
+ * @param docs The rebuilt documentation.
43
+ * @param metadata The selected-command metadata to preserve.
44
+ * @returns Documentation with the internal metadata attached.
45
+ */
46
+ function withCommandDocMetadata(docs, metadata) {
47
+ if (metadata == null) return docs;
48
+ metadata = withOrigin(metadata, metadata.origin ?? "entry");
49
+ const fragments = [...docs.fragments];
50
+ Object.defineProperty(fragments, commandDocCarrier, { value: {
51
+ metadata,
52
+ brief: docs.brief,
53
+ description: docs.description,
54
+ footer: docs.footer
55
+ } });
56
+ const result = {
57
+ ...docs,
58
+ fragments
59
+ };
60
+ Object.defineProperty(result, commandDocMetadata, { value: metadata });
61
+ return result;
62
+ }
63
+ /**
64
+ * Collects selected-command metadata in documentation traversal order.
65
+ * @param current Metadata from earlier children.
66
+ * @param docs The next child's documentation.
67
+ * @param includeCustom Whether to retain custom page fields inside merge().
68
+ * @returns The first defined value from children with the same origin.
69
+ */
70
+ function collectCommandDocMetadata(current, docs, includeCustom = false) {
71
+ const next = getCommandDocMetadata(docs);
72
+ if (next == null) return current;
73
+ const origin = next.origin ?? "entry";
74
+ if (origin === "entry" || origin === "custom" && !includeCustom) return current ?? withOrigin({}, "entry");
75
+ if (current?.origin === "command" && origin !== "command") return current;
76
+ if (current?.origin !== origin) current = void 0;
77
+ const brief = current?.brief ?? next.brief;
78
+ const description = current?.description ?? next.description;
79
+ const footer = current?.footer ?? next.footer;
80
+ return withOrigin({
81
+ ...brief == null ? {} : { brief },
82
+ ...description == null ? {} : { description },
83
+ ...footer == null ? {} : { footer }
84
+ }, origin);
85
+ }
86
+
87
+ //#endregion
88
+ exports.collectCommandDocMetadata = collectCommandDocMetadata;
89
+ exports.getCommandDocMetadata = getCommandDocMetadata;
90
+ exports.withCommandDocMetadata = withCommandDocMetadata;
@@ -0,0 +1,87 @@
1
+ //#region src/internal/command-doc-metadata.ts
2
+ function withOrigin(metadata, origin) {
3
+ const result = { ...metadata };
4
+ Object.defineProperty(result, "origin", {
5
+ value: origin,
6
+ enumerable: false
7
+ });
8
+ return result;
9
+ }
10
+ const commandDocMetadata = Symbol.for("@optique/core/commandDocMetadata");
11
+ const commandDocCarrier = Symbol.for("@optique/core/commandDocMetadataCarrier");
12
+ /**
13
+ * Reads effective page metadata, including custom collection-level fields.
14
+ * @param docs The child's documentation.
15
+ * @returns Its selected-command metadata, if any.
16
+ */
17
+ function getCommandDocMetadata(docs) {
18
+ const carrier = docs.fragments[commandDocCarrier];
19
+ if (carrier != null) {
20
+ const brief = docs.brief === carrier.brief ? carrier.metadata.brief : docs.brief;
21
+ const origin = carrier.metadata.origin ?? "entry";
22
+ const customPage = origin === "entry" && (docs.brief !== carrier.brief || docs.footer !== carrier.footer);
23
+ const description = origin === "entry" && !customPage || docs.description === carrier.description ? carrier.metadata.description : docs.description;
24
+ const footer = docs.footer === carrier.footer ? carrier.metadata.footer : docs.footer;
25
+ return withOrigin({
26
+ ...brief == null ? {} : { brief },
27
+ ...description == null ? {} : { description },
28
+ ...footer == null ? {} : { footer }
29
+ }, customPage ? "custom" : origin);
30
+ }
31
+ const metadata = docs[commandDocMetadata];
32
+ if (metadata != null) return metadata;
33
+ return docs.brief != null || docs.description != null || docs.footer != null ? withOrigin({
34
+ brief: docs.brief,
35
+ description: docs.description,
36
+ footer: docs.footer
37
+ }, "custom") : void 0;
38
+ }
39
+ /**
40
+ * Preserves selected-command metadata when rebuilding documentation fragments.
41
+ * @param docs The rebuilt documentation.
42
+ * @param metadata The selected-command metadata to preserve.
43
+ * @returns Documentation with the internal metadata attached.
44
+ */
45
+ function withCommandDocMetadata(docs, metadata) {
46
+ if (metadata == null) return docs;
47
+ metadata = withOrigin(metadata, metadata.origin ?? "entry");
48
+ const fragments = [...docs.fragments];
49
+ Object.defineProperty(fragments, commandDocCarrier, { value: {
50
+ metadata,
51
+ brief: docs.brief,
52
+ description: docs.description,
53
+ footer: docs.footer
54
+ } });
55
+ const result = {
56
+ ...docs,
57
+ fragments
58
+ };
59
+ Object.defineProperty(result, commandDocMetadata, { value: metadata });
60
+ return result;
61
+ }
62
+ /**
63
+ * Collects selected-command metadata in documentation traversal order.
64
+ * @param current Metadata from earlier children.
65
+ * @param docs The next child's documentation.
66
+ * @param includeCustom Whether to retain custom page fields inside merge().
67
+ * @returns The first defined value from children with the same origin.
68
+ */
69
+ function collectCommandDocMetadata(current, docs, includeCustom = false) {
70
+ const next = getCommandDocMetadata(docs);
71
+ if (next == null) return current;
72
+ const origin = next.origin ?? "entry";
73
+ if (origin === "entry" || origin === "custom" && !includeCustom) return current ?? withOrigin({}, "entry");
74
+ if (current?.origin === "command" && origin !== "command") return current;
75
+ if (current?.origin !== origin) current = void 0;
76
+ const brief = current?.brief ?? next.brief;
77
+ const description = current?.description ?? next.description;
78
+ const footer = current?.footer ?? next.footer;
79
+ return withOrigin({
80
+ ...brief == null ? {} : { brief },
81
+ ...description == null ? {} : { description },
82
+ ...footer == null ? {} : { footer }
83
+ }, origin);
84
+ }
85
+
86
+ //#endregion
87
+ export { collectCommandDocMetadata, getCommandDocMetadata, withCommandDocMetadata };
@@ -3,6 +3,7 @@ const require_message = require('./message.cjs');
3
3
  const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
4
4
  const require_internal_parser = require('./internal/parser.cjs');
5
5
  const require_annotation_state = require('./annotation-state.cjs');
6
+ const require_command_doc_metadata = require('./internal/command-doc-metadata.cjs');
6
7
  const require_passthrough = require('./internal/passthrough.cjs');
7
8
  const require_execution_context = require('./execution-context.cjs');
8
9
  const require_phase2_seed = require('./phase2-seed.cjs');
@@ -636,10 +637,10 @@ function withDefault(parser, defaultValue, options) {
636
637
  };
637
638
  return fragment;
638
639
  });
639
- return {
640
+ return require_command_doc_metadata.withCommandDocMetadata({
640
641
  ...fragments,
641
642
  fragments: modifiedFragments
642
- };
643
+ }, require_command_doc_metadata.getCommandDocMetadata(fragments));
643
644
  }
644
645
  return fragments;
645
646
  }
package/dist/modifiers.js CHANGED
@@ -3,6 +3,7 @@ import { formatMessage, message, text } from "./message.js";
3
3
  import { dispatchByMode, dispatchIterableByMode, mapModeValue, wrapForMode } from "./internal/mode-dispatch.js";
4
4
  import { defineInheritedAnnotationParser, defineParseLanes, defineSourceBindingOnlyAnnotationCompletionParser, getOwnParseLanes, unmatchedNonCliDependencySourceStateMarker } from "./internal/parser.js";
5
5
  import { getDelegatedAnnotationState, hasDelegatedAnnotationCarrier, isAnnotationWrappedInitialState, normalizeDelegatedAnnotationState, normalizeNestedDelegatedAnnotationState } from "./annotation-state.js";
6
+ import { getCommandDocMetadata, withCommandDocMetadata } from "./internal/command-doc-metadata.js";
6
7
  import { defineKnownCompletionLookup, defineOptionMatch, definePassThroughPriority, getKnownCompletion, getOptionMatch, getPassThroughPriority } from "./internal/passthrough.js";
7
8
  import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
8
9
  import { completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult } from "./phase2-seed.js";
@@ -636,10 +637,10 @@ function withDefault(parser, defaultValue, options) {
636
637
  };
637
638
  return fragment;
638
639
  });
639
- return {
640
+ return withCommandDocMetadata({
640
641
  ...fragments,
641
642
  fragments: modifiedFragments
642
- };
643
+ }, getCommandDocMetadata(fragments));
643
644
  }
644
645
  return fragments;
645
646
  }
@@ -6,6 +6,7 @@ const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
6
6
  const require_internal_dependency = require('./internal/dependency.cjs');
7
7
  const require_dependency_runtime = require('./dependency-runtime.cjs');
8
8
  const require_annotation_state = require('./annotation-state.cjs');
9
+ const require_command_doc_metadata = require('./internal/command-doc-metadata.cjs');
9
10
  const require_passthrough = require('./internal/passthrough.cjs');
10
11
  const require_command_alias = require('./internal/command-alias.cjs');
11
12
  const require_execution_context = require('./execution-context.cjs');
@@ -251,7 +252,7 @@ function* getSuggestionsWithDependency(valueParser, prefix, dependencyRegistry,
251
252
  * @internal
252
253
  */
253
254
  function* suggestOptionSync(optionNames$1, valueParser, hidden, description, context, prefix) {
254
- if (hidden) return;
255
+ if (hidden || context.optionsTerminated) return;
255
256
  const equalsIndex = prefix.indexOf("=");
256
257
  if (equalsIndex >= 0) {
257
258
  const optionPart = prefix.slice(0, equalsIndex);
@@ -336,7 +337,7 @@ async function* getSuggestionsWithDependencyAsync(valueParser, prefix, dependenc
336
337
  * @internal
337
338
  */
338
339
  async function* suggestOptionAsync(optionNames$1, valueParser, hidden, description, context, prefix) {
339
- if (hidden) return;
340
+ if (hidden || context.optionsTerminated) return;
340
341
  const equalsIndex = prefix.indexOf("=");
341
342
  if (equalsIndex >= 0) {
342
343
  const optionPart = prefix.slice(0, equalsIndex);
@@ -640,10 +641,10 @@ function option(...args) {
640
641
  return suggestOptionSync(optionNames$1, valueParser, require_usage.isSuggestionHidden(options.hidden), options.description, context, prefix);
641
642
  },
642
643
  getDocFragments(_state, defaultValue) {
643
- if (require_usage.isDocHidden(options.hidden)) return {
644
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
644
645
  fragments: [],
645
646
  description: options.description
646
- };
647
+ }, {});
647
648
  const choicesMessage = valueParser?.choices != null && valueParser.choices.length > 0 ? require_message.valueSet(valueParser.choices.map((c) => valueParser.format(c)), {
648
649
  fallback: "",
649
650
  type: "unit"
@@ -659,10 +660,10 @@ function option(...args) {
659
660
  default: defaultValue != null && valueParser != null ? require_message.message`${valueParser.format(defaultValue)}` : void 0,
660
661
  choices: choicesMessage
661
662
  }];
662
- return {
663
+ return require_command_doc_metadata.withCommandDocMetadata({
663
664
  fragments,
664
665
  description: options.description
665
- };
666
+ }, {});
666
667
  },
667
668
  [Symbol.for("Deno.customInspect")]() {
668
669
  return `option(${optionNames$1.map((o) => JSON.stringify(o)).join(", ")})`;
@@ -915,8 +916,8 @@ function flag(...args) {
915
916
  error: require_message.message`${require_message.optionNames(optionNames$1)}: ${state.error}`
916
917
  };
917
918
  },
918
- suggest(_context, prefix) {
919
- if (require_usage.isSuggestionHidden(options.hidden)) return [];
919
+ suggest(context, prefix) {
920
+ if (require_usage.isSuggestionHidden(options.hidden) || context.optionsTerminated) return [];
920
921
  const suggestions = [];
921
922
  if (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/") || prefix.startsWith("+")) {
922
923
  for (const optionName$1 of optionNames$1) if (optionName$1.startsWith(prefix)) {
@@ -931,10 +932,10 @@ function flag(...args) {
931
932
  return suggestions;
932
933
  },
933
934
  getDocFragments(_state, _defaultValue) {
934
- if (require_usage.isDocHidden(options.hidden)) return {
935
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
935
936
  fragments: [],
936
937
  description: options.description
937
- };
938
+ }, {});
938
939
  const fragments = [{
939
940
  type: "entry",
940
941
  term: {
@@ -943,10 +944,10 @@ function flag(...args) {
943
944
  },
944
945
  description: options.description
945
946
  }];
946
- return {
947
+ return require_command_doc_metadata.withCommandDocMetadata({
947
948
  fragments,
948
949
  description: options.description
949
- };
950
+ }, {});
950
951
  },
951
952
  [Symbol.for("Deno.customInspect")]() {
952
953
  return `flag(${optionNames$1.map((o) => JSON.stringify(o)).join(", ")})`;
@@ -1303,10 +1304,10 @@ function argument(valueParser, options = {}) {
1303
1304
  return suggestArgumentSync(valueParser, require_usage.isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry, context.exec);
1304
1305
  },
1305
1306
  getDocFragments(_state, defaultValue) {
1306
- if (require_usage.isDocHidden(options.hidden)) return {
1307
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
1307
1308
  fragments: [],
1308
1309
  description: options.description
1309
- };
1310
+ }, {});
1310
1311
  const choicesMessage = valueParser.choices != null && valueParser.choices.length > 0 ? require_message.valueSet(valueParser.choices.map((c) => valueParser.format(c)), {
1311
1312
  fallback: "",
1312
1313
  type: "unit"
@@ -1318,10 +1319,10 @@ function argument(valueParser, options = {}) {
1318
1319
  default: defaultValue == null ? void 0 : require_message.message`${valueParser.format(defaultValue)}`,
1319
1320
  choices: choicesMessage
1320
1321
  }];
1321
- return {
1322
+ return require_command_doc_metadata.withCommandDocMetadata({
1322
1323
  fragments,
1323
1324
  description: options.description
1324
- };
1325
+ }, {});
1325
1326
  },
1326
1327
  [Symbol.for("Deno.customInspect")]() {
1327
1328
  return `argument()`;
@@ -1672,11 +1673,11 @@ function command(name, parser, options = {}) {
1672
1673
  getDocFragments(state, defaultValue) {
1673
1674
  const commandState = state.kind === "available" ? normalizeCommandState(state.state) : void 0;
1674
1675
  if (state.kind === "unavailable" || typeof commandState === "undefined") {
1675
- if (require_usage.isDocHidden(options.hidden)) return {
1676
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
1676
1677
  fragments: [],
1677
1678
  description: options.description
1678
- };
1679
- return {
1679
+ }, {});
1680
+ return require_command_doc_metadata.withCommandDocMetadata({
1680
1681
  description: options.description,
1681
1682
  fragments: [{
1682
1683
  type: "entry",
@@ -1686,7 +1687,7 @@ function command(name, parser, options = {}) {
1686
1687
  },
1687
1688
  description: options.brief ?? options.description
1688
1689
  }]
1689
- };
1690
+ }, {});
1690
1691
  }
1691
1692
  const innerState = commandState[0] === "parsing" ? {
1692
1693
  kind: "available",
@@ -1696,12 +1697,18 @@ function command(name, parser, options = {}) {
1696
1697
  state: getCommandChildState(state.state, parser.initialState, parser)
1697
1698
  };
1698
1699
  const innerFragments = parser.getDocFragments(innerState, defaultValue);
1699
- return {
1700
+ const innerMetadata = require_command_doc_metadata.getCommandDocMetadata(innerFragments) ?? innerFragments;
1701
+ return require_command_doc_metadata.withCommandDocMetadata({
1700
1702
  ...innerFragments,
1701
1703
  brief: innerFragments.brief ?? options.brief,
1702
1704
  description: innerFragments.description ?? options.description,
1703
1705
  footer: innerFragments.footer ?? options.footer
1704
- };
1706
+ }, {
1707
+ origin: "command",
1708
+ brief: innerMetadata?.brief ?? options.brief,
1709
+ description: innerMetadata?.description ?? options.description,
1710
+ footer: innerMetadata?.footer ?? options.footer
1711
+ });
1705
1712
  },
1706
1713
  [Symbol.for("Deno.customInspect")]() {
1707
1714
  return `command(${JSON.stringify(name)})`;
@@ -1902,18 +1909,18 @@ function passThrough(options = {}) {
1902
1909
  return [];
1903
1910
  },
1904
1911
  getDocFragments(_state, _defaultValue) {
1905
- if (require_usage.isDocHidden(options.hidden)) return {
1912
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
1906
1913
  fragments: [],
1907
1914
  description: options.description
1908
- };
1909
- return {
1915
+ }, {});
1916
+ return require_command_doc_metadata.withCommandDocMetadata({
1910
1917
  fragments: [{
1911
1918
  type: "entry",
1912
1919
  term: { type: "passthrough" },
1913
1920
  description: options.description
1914
1921
  }],
1915
1922
  description: options.description
1916
- };
1923
+ }, {});
1917
1924
  },
1918
1925
  [Symbol.for("Deno.customInspect")]() {
1919
1926
  return `passThrough(${format})`;
@@ -6,6 +6,7 @@ import { dispatchByMode, dispatchIterableByMode, wrapForMode } from "./internal/
6
6
  import { getDefaultValuesFunction, getDependencyIds, getSnapshottedDefaultDependencyValues, isDerivedValueParser, suggestWithDependency } from "./internal/dependency.js";
7
7
  import { replayDerivedParser, replayDerivedParserAsync } from "./dependency-runtime.js";
8
8
  import { getWrappedChildParseState, getWrappedChildState, isAnnotationWrappedInitialState, normalizeInjectedAnnotationState } from "./annotation-state.js";
9
+ import { getCommandDocMetadata, withCommandDocMetadata } from "./internal/command-doc-metadata.js";
9
10
  import { defineKnownCompletion, defineOptionMatch, definePassThroughPriority, getOptionMatch, getPassThroughFailure, getPassThroughPriority } from "./internal/passthrough.js";
10
11
  import { hiddenCommandAliasesKey } from "./internal/command-alias.js";
11
12
  import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
@@ -251,7 +252,7 @@ function* getSuggestionsWithDependency(valueParser, prefix, dependencyRegistry,
251
252
  * @internal
252
253
  */
253
254
  function* suggestOptionSync(optionNames$1, valueParser, hidden, description, context, prefix) {
254
- if (hidden) return;
255
+ if (hidden || context.optionsTerminated) return;
255
256
  const equalsIndex = prefix.indexOf("=");
256
257
  if (equalsIndex >= 0) {
257
258
  const optionPart = prefix.slice(0, equalsIndex);
@@ -336,7 +337,7 @@ async function* getSuggestionsWithDependencyAsync(valueParser, prefix, dependenc
336
337
  * @internal
337
338
  */
338
339
  async function* suggestOptionAsync(optionNames$1, valueParser, hidden, description, context, prefix) {
339
- if (hidden) return;
340
+ if (hidden || context.optionsTerminated) return;
340
341
  const equalsIndex = prefix.indexOf("=");
341
342
  if (equalsIndex >= 0) {
342
343
  const optionPart = prefix.slice(0, equalsIndex);
@@ -640,10 +641,10 @@ function option(...args) {
640
641
  return suggestOptionSync(optionNames$1, valueParser, isSuggestionHidden(options.hidden), options.description, context, prefix);
641
642
  },
642
643
  getDocFragments(_state, defaultValue) {
643
- if (isDocHidden(options.hidden)) return {
644
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
644
645
  fragments: [],
645
646
  description: options.description
646
- };
647
+ }, {});
647
648
  const choicesMessage = valueParser?.choices != null && valueParser.choices.length > 0 ? valueSet(valueParser.choices.map((c) => valueParser.format(c)), {
648
649
  fallback: "",
649
650
  type: "unit"
@@ -659,10 +660,10 @@ function option(...args) {
659
660
  default: defaultValue != null && valueParser != null ? message`${valueParser.format(defaultValue)}` : void 0,
660
661
  choices: choicesMessage
661
662
  }];
662
- return {
663
+ return withCommandDocMetadata({
663
664
  fragments,
664
665
  description: options.description
665
- };
666
+ }, {});
666
667
  },
667
668
  [Symbol.for("Deno.customInspect")]() {
668
669
  return `option(${optionNames$1.map((o) => JSON.stringify(o)).join(", ")})`;
@@ -915,8 +916,8 @@ function flag(...args) {
915
916
  error: message`${optionNames(optionNames$1)}: ${state.error}`
916
917
  };
917
918
  },
918
- suggest(_context, prefix) {
919
- if (isSuggestionHidden(options.hidden)) return [];
919
+ suggest(context, prefix) {
920
+ if (isSuggestionHidden(options.hidden) || context.optionsTerminated) return [];
920
921
  const suggestions = [];
921
922
  if (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/") || prefix.startsWith("+")) {
922
923
  for (const optionName$1 of optionNames$1) if (optionName$1.startsWith(prefix)) {
@@ -931,10 +932,10 @@ function flag(...args) {
931
932
  return suggestions;
932
933
  },
933
934
  getDocFragments(_state, _defaultValue) {
934
- if (isDocHidden(options.hidden)) return {
935
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
935
936
  fragments: [],
936
937
  description: options.description
937
- };
938
+ }, {});
938
939
  const fragments = [{
939
940
  type: "entry",
940
941
  term: {
@@ -943,10 +944,10 @@ function flag(...args) {
943
944
  },
944
945
  description: options.description
945
946
  }];
946
- return {
947
+ return withCommandDocMetadata({
947
948
  fragments,
948
949
  description: options.description
949
- };
950
+ }, {});
950
951
  },
951
952
  [Symbol.for("Deno.customInspect")]() {
952
953
  return `flag(${optionNames$1.map((o) => JSON.stringify(o)).join(", ")})`;
@@ -1303,10 +1304,10 @@ function argument(valueParser, options = {}) {
1303
1304
  return suggestArgumentSync(valueParser, isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry, context.exec);
1304
1305
  },
1305
1306
  getDocFragments(_state, defaultValue) {
1306
- if (isDocHidden(options.hidden)) return {
1307
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
1307
1308
  fragments: [],
1308
1309
  description: options.description
1309
- };
1310
+ }, {});
1310
1311
  const choicesMessage = valueParser.choices != null && valueParser.choices.length > 0 ? valueSet(valueParser.choices.map((c) => valueParser.format(c)), {
1311
1312
  fallback: "",
1312
1313
  type: "unit"
@@ -1318,10 +1319,10 @@ function argument(valueParser, options = {}) {
1318
1319
  default: defaultValue == null ? void 0 : message`${valueParser.format(defaultValue)}`,
1319
1320
  choices: choicesMessage
1320
1321
  }];
1321
- return {
1322
+ return withCommandDocMetadata({
1322
1323
  fragments,
1323
1324
  description: options.description
1324
- };
1325
+ }, {});
1325
1326
  },
1326
1327
  [Symbol.for("Deno.customInspect")]() {
1327
1328
  return `argument()`;
@@ -1672,11 +1673,11 @@ function command(name, parser, options = {}) {
1672
1673
  getDocFragments(state, defaultValue) {
1673
1674
  const commandState = state.kind === "available" ? normalizeCommandState(state.state) : void 0;
1674
1675
  if (state.kind === "unavailable" || typeof commandState === "undefined") {
1675
- if (isDocHidden(options.hidden)) return {
1676
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
1676
1677
  fragments: [],
1677
1678
  description: options.description
1678
- };
1679
- return {
1679
+ }, {});
1680
+ return withCommandDocMetadata({
1680
1681
  description: options.description,
1681
1682
  fragments: [{
1682
1683
  type: "entry",
@@ -1686,7 +1687,7 @@ function command(name, parser, options = {}) {
1686
1687
  },
1687
1688
  description: options.brief ?? options.description
1688
1689
  }]
1689
- };
1690
+ }, {});
1690
1691
  }
1691
1692
  const innerState = commandState[0] === "parsing" ? {
1692
1693
  kind: "available",
@@ -1696,12 +1697,18 @@ function command(name, parser, options = {}) {
1696
1697
  state: getCommandChildState(state.state, parser.initialState, parser)
1697
1698
  };
1698
1699
  const innerFragments = parser.getDocFragments(innerState, defaultValue);
1699
- return {
1700
+ const innerMetadata = getCommandDocMetadata(innerFragments) ?? innerFragments;
1701
+ return withCommandDocMetadata({
1700
1702
  ...innerFragments,
1701
1703
  brief: innerFragments.brief ?? options.brief,
1702
1704
  description: innerFragments.description ?? options.description,
1703
1705
  footer: innerFragments.footer ?? options.footer
1704
- };
1706
+ }, {
1707
+ origin: "command",
1708
+ brief: innerMetadata?.brief ?? options.brief,
1709
+ description: innerMetadata?.description ?? options.description,
1710
+ footer: innerMetadata?.footer ?? options.footer
1711
+ });
1705
1712
  },
1706
1713
  [Symbol.for("Deno.customInspect")]() {
1707
1714
  return `command(${JSON.stringify(name)})`;
@@ -1902,18 +1909,18 @@ function passThrough(options = {}) {
1902
1909
  return [];
1903
1910
  },
1904
1911
  getDocFragments(_state, _defaultValue) {
1905
- if (isDocHidden(options.hidden)) return {
1912
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
1906
1913
  fragments: [],
1907
1914
  description: options.description
1908
- };
1909
- return {
1915
+ }, {});
1916
+ return withCommandDocMetadata({
1910
1917
  fragments: [{
1911
1918
  type: "entry",
1912
1919
  term: { type: "passthrough" },
1913
1920
  description: options.description
1914
1921
  }],
1915
1922
  description: options.description
1916
- };
1923
+ }, {});
1917
1924
  },
1918
1925
  [Symbol.for("Deno.customInspect")]() {
1919
1926
  return `passThrough(${format})`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.2.10",
3
+ "version": "1.2.12",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",
@@ -221,7 +221,7 @@
221
221
  },
222
222
  "sideEffects": false,
223
223
  "devDependencies": {
224
- "@optique/env": "1.2.10",
224
+ "@optique/env": "1.2.12",
225
225
  "@types/node": "^24.0.0",
226
226
  "fast-check": "^4.7.0",
227
227
  "tsdown": "^0.13.0",