@optique/core 1.3.3 → 1.3.5

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');
@@ -1902,6 +1903,7 @@ function or(...args) {
1902
1903
  },
1903
1904
  suggest: createExclusiveSuggest(parsers, combinedMode),
1904
1905
  getDocFragments(state, _defaultValue) {
1906
+ let commandMetadata;
1905
1907
  let brief;
1906
1908
  let description;
1907
1909
  let footer;
@@ -1914,18 +1916,19 @@ function or(...args) {
1914
1916
  state: parserResult.next.state
1915
1917
  } : { kind: "unavailable" };
1916
1918
  const docFragments = parsers[index].getDocFragments(innerState, void 0);
1919
+ commandMetadata = require_command_doc_metadata.getCommandDocMetadata(docFragments);
1917
1920
  brief = docFragments.brief;
1918
1921
  description = docFragments.description;
1919
1922
  footer = docFragments.footer;
1920
1923
  fragments = docFragments.fragments;
1921
1924
  }
1922
1925
  if (state.kind === "unavailable" || state.state == null) fragments = require_doc.deduplicateDocFragments(fragments);
1923
- return {
1926
+ return require_command_doc_metadata.withCommandDocMetadata({
1924
1927
  brief,
1925
1928
  description,
1926
1929
  footer,
1927
1930
  fragments
1928
- };
1931
+ }, commandMetadata);
1929
1932
  }
1930
1933
  };
1931
1934
  const singleDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -2134,6 +2137,7 @@ function createLongestMatch(...args) {
2134
2137
  },
2135
2138
  suggest: createExclusiveSuggest(parsers, combinedMode),
2136
2139
  getDocFragments(state, _defaultValue) {
2140
+ let commandMetadata;
2137
2141
  let brief;
2138
2142
  let description;
2139
2143
  let footer;
@@ -2149,6 +2153,7 @@ function createLongestMatch(...args) {
2149
2153
  kind: "available",
2150
2154
  state: result.next.state
2151
2155
  });
2156
+ commandMetadata = require_command_doc_metadata.getCommandDocMetadata(docResult);
2152
2157
  brief = docResult.brief;
2153
2158
  description = docResult.description;
2154
2159
  footer = docResult.footer;
@@ -2159,12 +2164,12 @@ function createLongestMatch(...args) {
2159
2164
  shouldDeduplicate = true;
2160
2165
  }
2161
2166
  }
2162
- return {
2167
+ return require_command_doc_metadata.withCommandDocMetadata({
2163
2168
  brief,
2164
2169
  description,
2165
2170
  fragments: shouldDeduplicate ? require_doc.deduplicateDocFragments(fragments) : fragments,
2166
2171
  footer
2167
- };
2172
+ }, commandMetadata);
2168
2173
  }
2169
2174
  };
2170
2175
  const multiDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -3162,12 +3167,15 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3162
3167
  }, () => suggestObjectAsync(context, prefix, parserPairs));
3163
3168
  },
3164
3169
  getDocFragments(state, defaultValue) {
3170
+ let commandMetadata;
3165
3171
  const fragments = parserPairs.flatMap(([field, p]) => {
3166
3172
  const fieldState = state.kind === "unavailable" ? { kind: "unavailable" } : {
3167
3173
  kind: "available",
3168
3174
  state: state.state[field]
3169
3175
  };
3170
- return p.getDocFragments(fieldState, defaultValue?.[field]).fragments;
3176
+ const docs = p.getDocFragments(fieldState, defaultValue?.[field]);
3177
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs);
3178
+ return docs.fragments;
3171
3179
  });
3172
3180
  const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
3173
3181
  const entries = hiddenAwareFragments.filter((d) => d.type === "entry");
@@ -3182,10 +3190,13 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3182
3190
  entries
3183
3191
  };
3184
3192
  sections.push(section);
3185
- return { fragments: sections.map((s) => ({
3186
- ...s,
3187
- type: "section"
3188
- })) };
3193
+ return require_command_doc_metadata.withCommandDocMetadata({
3194
+ ...commandMetadata,
3195
+ fragments: sections.map((s) => ({
3196
+ ...s,
3197
+ type: "section"
3198
+ }))
3199
+ }, commandMetadata);
3189
3200
  }
3190
3201
  };
3191
3202
  const fieldNormalizers = [];
@@ -4196,12 +4207,15 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
4196
4207
  return require_mode_dispatch.dispatchIterableByMode(combinedMode, () => suggestTupleSync(context, prefix, syncParsers), () => suggestTupleAsync(context, prefix, parsers));
4197
4208
  },
4198
4209
  getDocFragments(state, defaultValue) {
4210
+ let commandMetadata;
4199
4211
  const fragments = syncParsers.flatMap((p, i) => {
4200
4212
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
4201
4213
  kind: "available",
4202
4214
  state: state.state[i]
4203
4215
  };
4204
- return p.getDocFragments(indexState, defaultValue?.[i]).fragments;
4216
+ const docs = p.getDocFragments(indexState, defaultValue?.[i]);
4217
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs);
4218
+ return docs.fragments;
4205
4219
  });
4206
4220
  const entries = fragments.filter((d) => d.type === "entry");
4207
4221
  const sections = [];
@@ -4215,10 +4229,13 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
4215
4229
  entries
4216
4230
  };
4217
4231
  sections.push(section);
4218
- return { fragments: sections.map((s) => ({
4219
- ...s,
4220
- type: "section"
4221
- })) };
4232
+ return require_command_doc_metadata.withCommandDocMetadata({
4233
+ ...commandMetadata,
4234
+ fragments: sections.map((s) => ({
4235
+ ...s,
4236
+ type: "section"
4237
+ }))
4238
+ }, commandMetadata);
4222
4239
  },
4223
4240
  [Symbol.for("Deno.customInspect")]() {
4224
4241
  const parsersStr = parsers.length === 1 ? `[1 parser]` : `[${parsers.length} parsers]`;
@@ -5534,6 +5551,7 @@ function merge(...args) {
5534
5551
  }();
5535
5552
  },
5536
5553
  getDocFragments(state, _defaultValue) {
5554
+ let commandMetadata;
5537
5555
  let brief;
5538
5556
  let description;
5539
5557
  let footer;
@@ -5551,6 +5569,7 @@ function merge(...args) {
5551
5569
  state: state.state
5552
5570
  };
5553
5571
  const docFragments = p.getDocFragments(parserState, void 0);
5572
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docFragments, true);
5554
5573
  brief ??= docFragments.brief;
5555
5574
  description ??= docFragments.description;
5556
5575
  footer ??= docFragments.footer;
@@ -5570,7 +5589,7 @@ function merge(...args) {
5570
5589
  entries
5571
5590
  };
5572
5591
  sections.push(labeledSection);
5573
- return {
5592
+ return require_command_doc_metadata.withCommandDocMetadata({
5574
5593
  brief,
5575
5594
  description,
5576
5595
  footer,
@@ -5578,9 +5597,9 @@ function merge(...args) {
5578
5597
  ...s,
5579
5598
  type: "section"
5580
5599
  }))
5581
- };
5600
+ }, commandMetadata);
5582
5601
  }
5583
- return {
5602
+ return require_command_doc_metadata.withCommandDocMetadata({
5584
5603
  brief,
5585
5604
  description,
5586
5605
  footer,
@@ -5591,7 +5610,7 @@ function merge(...args) {
5591
5610
  type: "section",
5592
5611
  entries
5593
5612
  }]
5594
- };
5613
+ }, commandMetadata);
5595
5614
  }
5596
5615
  };
5597
5616
  require_internal_parser.defineParseLanes(mergeParser, mergeParseLanes);
@@ -6220,12 +6239,15 @@ function concat(...parsers) {
6220
6239
  }();
6221
6240
  },
6222
6241
  getDocFragments(state, _defaultValue) {
6242
+ let commandMetadata;
6223
6243
  const fragments = syncParsers.flatMap((p, index) => {
6224
6244
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
6225
6245
  kind: "available",
6226
6246
  state: state.state[index]
6227
6247
  };
6228
- return p.getDocFragments(indexState, void 0).fragments;
6248
+ const docs = p.getDocFragments(indexState, void 0);
6249
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs);
6250
+ return docs.fragments;
6229
6251
  });
6230
6252
  const entries = fragments.filter((f) => f.type === "entry");
6231
6253
  const sections = [];
@@ -6242,7 +6264,10 @@ function concat(...parsers) {
6242
6264
  type: "section",
6243
6265
  entries
6244
6266
  });
6245
- return { fragments: result };
6267
+ return require_command_doc_metadata.withCommandDocMetadata({
6268
+ ...commandMetadata,
6269
+ fragments: result
6270
+ }, commandMetadata);
6246
6271
  }
6247
6272
  };
6248
6273
  require_internal_parser.defineInheritedAnnotationParser(concatParser);
@@ -6281,7 +6306,8 @@ function group(label, parser, options = {}) {
6281
6306
  return parser.suggest(context, prefix);
6282
6307
  },
6283
6308
  getDocFragments: (state, defaultValue) => {
6284
- const { brief, description, footer, fragments } = parser.getDocFragments(state, defaultValue);
6309
+ const docs = parser.getDocFragments(state, defaultValue);
6310
+ const { brief, description, footer, fragments } = docs;
6285
6311
  const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
6286
6312
  const allEntries = [];
6287
6313
  const titledSections = [];
@@ -6304,7 +6330,7 @@ function group(label, parser, options = {}) {
6304
6330
  title: label,
6305
6331
  entries: allEntries
6306
6332
  } : { entries: allEntries };
6307
- return {
6333
+ return require_command_doc_metadata.withCommandDocMetadata({
6308
6334
  brief,
6309
6335
  description,
6310
6336
  footer,
@@ -6315,7 +6341,7 @@ function group(label, parser, options = {}) {
6315
6341
  type: "section",
6316
6342
  ...labeledSection
6317
6343
  }]
6318
- };
6344
+ }, require_command_doc_metadata.getCommandDocMetadata(docs));
6319
6345
  }
6320
6346
  };
6321
6347
  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, completeEffectfulSourcesAsync, createDependencyRuntimeContext, effectfulSchedulingNodesKey, exclusiveSourceScopeKey, extractRawInputFromState, fillMissingSourceDefaults, fillMissingSourceDefaultsAsync, forkRuntimeForCommittedSubtree, getDefaultDependencySnapshot, guaranteedStaticSourceIdsKey, hasInactiveCompletion, isMatchedState, recordSourceScope, releaseUncollectedSourceValues, replaceCachedBarrierFailure, resolveDerivedSourceValues, resolveDerivedSourceValuesAsync, resolveStateWithRuntime, resolveStateWithRuntimeAsync, serializeSchedulingPath, sourceCollectionExpansionKey, staticSourceScopeKey } 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";
@@ -1902,6 +1903,7 @@ function or(...args) {
1902
1903
  },
1903
1904
  suggest: createExclusiveSuggest(parsers, combinedMode),
1904
1905
  getDocFragments(state, _defaultValue) {
1906
+ let commandMetadata;
1905
1907
  let brief;
1906
1908
  let description;
1907
1909
  let footer;
@@ -1914,18 +1916,19 @@ function or(...args) {
1914
1916
  state: parserResult.next.state
1915
1917
  } : { kind: "unavailable" };
1916
1918
  const docFragments = parsers[index].getDocFragments(innerState, void 0);
1919
+ commandMetadata = getCommandDocMetadata(docFragments);
1917
1920
  brief = docFragments.brief;
1918
1921
  description = docFragments.description;
1919
1922
  footer = docFragments.footer;
1920
1923
  fragments = docFragments.fragments;
1921
1924
  }
1922
1925
  if (state.kind === "unavailable" || state.state == null) fragments = deduplicateDocFragments(fragments);
1923
- return {
1926
+ return withCommandDocMetadata({
1924
1927
  brief,
1925
1928
  description,
1926
1929
  footer,
1927
1930
  fragments
1928
- };
1931
+ }, commandMetadata);
1929
1932
  }
1930
1933
  };
1931
1934
  const singleDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -2134,6 +2137,7 @@ function createLongestMatch(...args) {
2134
2137
  },
2135
2138
  suggest: createExclusiveSuggest(parsers, combinedMode),
2136
2139
  getDocFragments(state, _defaultValue) {
2140
+ let commandMetadata;
2137
2141
  let brief;
2138
2142
  let description;
2139
2143
  let footer;
@@ -2149,6 +2153,7 @@ function createLongestMatch(...args) {
2149
2153
  kind: "available",
2150
2154
  state: result.next.state
2151
2155
  });
2156
+ commandMetadata = getCommandDocMetadata(docResult);
2152
2157
  brief = docResult.brief;
2153
2158
  description = docResult.description;
2154
2159
  footer = docResult.footer;
@@ -2159,12 +2164,12 @@ function createLongestMatch(...args) {
2159
2164
  shouldDeduplicate = true;
2160
2165
  }
2161
2166
  }
2162
- return {
2167
+ return withCommandDocMetadata({
2163
2168
  brief,
2164
2169
  description,
2165
2170
  fragments: shouldDeduplicate ? deduplicateDocFragments(fragments) : fragments,
2166
2171
  footer
2167
- };
2172
+ }, commandMetadata);
2168
2173
  }
2169
2174
  };
2170
2175
  const multiDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -3162,12 +3167,15 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3162
3167
  }, () => suggestObjectAsync(context, prefix, parserPairs));
3163
3168
  },
3164
3169
  getDocFragments(state, defaultValue) {
3170
+ let commandMetadata;
3165
3171
  const fragments = parserPairs.flatMap(([field, p]) => {
3166
3172
  const fieldState = state.kind === "unavailable" ? { kind: "unavailable" } : {
3167
3173
  kind: "available",
3168
3174
  state: state.state[field]
3169
3175
  };
3170
- return p.getDocFragments(fieldState, defaultValue?.[field]).fragments;
3176
+ const docs = p.getDocFragments(fieldState, defaultValue?.[field]);
3177
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docs);
3178
+ return docs.fragments;
3171
3179
  });
3172
3180
  const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
3173
3181
  const entries = hiddenAwareFragments.filter((d) => d.type === "entry");
@@ -3182,10 +3190,13 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3182
3190
  entries
3183
3191
  };
3184
3192
  sections.push(section);
3185
- return { fragments: sections.map((s) => ({
3186
- ...s,
3187
- type: "section"
3188
- })) };
3193
+ return withCommandDocMetadata({
3194
+ ...commandMetadata,
3195
+ fragments: sections.map((s) => ({
3196
+ ...s,
3197
+ type: "section"
3198
+ }))
3199
+ }, commandMetadata);
3189
3200
  }
3190
3201
  };
3191
3202
  const fieldNormalizers = [];
@@ -4196,12 +4207,15 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
4196
4207
  return dispatchIterableByMode(combinedMode, () => suggestTupleSync(context, prefix, syncParsers), () => suggestTupleAsync(context, prefix, parsers));
4197
4208
  },
4198
4209
  getDocFragments(state, defaultValue) {
4210
+ let commandMetadata;
4199
4211
  const fragments = syncParsers.flatMap((p, i) => {
4200
4212
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
4201
4213
  kind: "available",
4202
4214
  state: state.state[i]
4203
4215
  };
4204
- return p.getDocFragments(indexState, defaultValue?.[i]).fragments;
4216
+ const docs = p.getDocFragments(indexState, defaultValue?.[i]);
4217
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docs);
4218
+ return docs.fragments;
4205
4219
  });
4206
4220
  const entries = fragments.filter((d) => d.type === "entry");
4207
4221
  const sections = [];
@@ -4215,10 +4229,13 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
4215
4229
  entries
4216
4230
  };
4217
4231
  sections.push(section);
4218
- return { fragments: sections.map((s) => ({
4219
- ...s,
4220
- type: "section"
4221
- })) };
4232
+ return withCommandDocMetadata({
4233
+ ...commandMetadata,
4234
+ fragments: sections.map((s) => ({
4235
+ ...s,
4236
+ type: "section"
4237
+ }))
4238
+ }, commandMetadata);
4222
4239
  },
4223
4240
  [Symbol.for("Deno.customInspect")]() {
4224
4241
  const parsersStr = parsers.length === 1 ? `[1 parser]` : `[${parsers.length} parsers]`;
@@ -5534,6 +5551,7 @@ function merge(...args) {
5534
5551
  }();
5535
5552
  },
5536
5553
  getDocFragments(state, _defaultValue) {
5554
+ let commandMetadata;
5537
5555
  let brief;
5538
5556
  let description;
5539
5557
  let footer;
@@ -5551,6 +5569,7 @@ function merge(...args) {
5551
5569
  state: state.state
5552
5570
  };
5553
5571
  const docFragments = p.getDocFragments(parserState, void 0);
5572
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docFragments, true);
5554
5573
  brief ??= docFragments.brief;
5555
5574
  description ??= docFragments.description;
5556
5575
  footer ??= docFragments.footer;
@@ -5570,7 +5589,7 @@ function merge(...args) {
5570
5589
  entries
5571
5590
  };
5572
5591
  sections.push(labeledSection);
5573
- return {
5592
+ return withCommandDocMetadata({
5574
5593
  brief,
5575
5594
  description,
5576
5595
  footer,
@@ -5578,9 +5597,9 @@ function merge(...args) {
5578
5597
  ...s,
5579
5598
  type: "section"
5580
5599
  }))
5581
- };
5600
+ }, commandMetadata);
5582
5601
  }
5583
- return {
5602
+ return withCommandDocMetadata({
5584
5603
  brief,
5585
5604
  description,
5586
5605
  footer,
@@ -5591,7 +5610,7 @@ function merge(...args) {
5591
5610
  type: "section",
5592
5611
  entries
5593
5612
  }]
5594
- };
5613
+ }, commandMetadata);
5595
5614
  }
5596
5615
  };
5597
5616
  defineParseLanes(mergeParser, mergeParseLanes);
@@ -6220,12 +6239,15 @@ function concat(...parsers) {
6220
6239
  }();
6221
6240
  },
6222
6241
  getDocFragments(state, _defaultValue) {
6242
+ let commandMetadata;
6223
6243
  const fragments = syncParsers.flatMap((p, index) => {
6224
6244
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
6225
6245
  kind: "available",
6226
6246
  state: state.state[index]
6227
6247
  };
6228
- return p.getDocFragments(indexState, void 0).fragments;
6248
+ const docs = p.getDocFragments(indexState, void 0);
6249
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docs);
6250
+ return docs.fragments;
6229
6251
  });
6230
6252
  const entries = fragments.filter((f) => f.type === "entry");
6231
6253
  const sections = [];
@@ -6242,7 +6264,10 @@ function concat(...parsers) {
6242
6264
  type: "section",
6243
6265
  entries
6244
6266
  });
6245
- return { fragments: result };
6267
+ return withCommandDocMetadata({
6268
+ ...commandMetadata,
6269
+ fragments: result
6270
+ }, commandMetadata);
6246
6271
  }
6247
6272
  };
6248
6273
  defineInheritedAnnotationParser(concatParser);
@@ -6281,7 +6306,8 @@ function group(label, parser, options = {}) {
6281
6306
  return parser.suggest(context, prefix);
6282
6307
  },
6283
6308
  getDocFragments: (state, defaultValue) => {
6284
- const { brief, description, footer, fragments } = parser.getDocFragments(state, defaultValue);
6309
+ const docs = parser.getDocFragments(state, defaultValue);
6310
+ const { brief, description, footer, fragments } = docs;
6285
6311
  const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
6286
6312
  const allEntries = [];
6287
6313
  const titledSections = [];
@@ -6304,7 +6330,7 @@ function group(label, parser, options = {}) {
6304
6330
  title: label,
6305
6331
  entries: allEntries
6306
6332
  } : { entries: allEntries };
6307
- return {
6333
+ return withCommandDocMetadata({
6308
6334
  brief,
6309
6335
  description,
6310
6336
  footer,
@@ -6315,7 +6341,7 @@ function group(label, parser, options = {}) {
6315
6341
  type: "section",
6316
6342
  ...labeledSection
6317
6343
  }]
6318
- };
6344
+ }, getCommandDocMetadata(docs));
6319
6345
  }
6320
6346
  };
6321
6347
  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 };
@@ -4,6 +4,7 @@ const require_mode_dispatch = require('./internal/mode-dispatch.cjs');
4
4
  const require_dependency_runtime = require('./dependency-runtime.cjs');
5
5
  const require_internal_parser = require('./internal/parser.cjs');
6
6
  const require_annotation_state = require('./annotation-state.cjs');
7
+ const require_command_doc_metadata = require('./internal/command-doc-metadata.cjs');
7
8
  const require_passthrough = require('./internal/passthrough.cjs');
8
9
  const require_execution_context = require('./execution-context.cjs');
9
10
  const require_phase2_seed = require('./phase2-seed.cjs');
@@ -653,10 +654,10 @@ function withDefault(parser, defaultValue, options) {
653
654
  };
654
655
  return fragment;
655
656
  });
656
- return {
657
+ return require_command_doc_metadata.withCommandDocMetadata({
657
658
  ...fragments,
658
659
  fragments: modifiedFragments
659
- };
660
+ }, require_command_doc_metadata.getCommandDocMetadata(fragments));
660
661
  }
661
662
  return fragments;
662
663
  }
package/dist/modifiers.js CHANGED
@@ -4,6 +4,7 @@ import { dispatchByMode, dispatchIterableByMode, mapModeValue, wrapForMode } fro
4
4
  import { defineForwardedEffectfulSchedulingNodes } from "./dependency-runtime.js";
5
5
  import { defineInheritedAnnotationParser, defineParseLanes, defineSourceBindingOnlyAnnotationCompletionParser, getOwnParseLanes, unmatchedNonCliDependencySourceStateMarker } from "./internal/parser.js";
6
6
  import { getDelegatedAnnotationState, hasDelegatedAnnotationCarrier, isAnnotationWrappedInitialState, normalizeDelegatedAnnotationState, normalizeNestedDelegatedAnnotationState } from "./annotation-state.js";
7
+ import { getCommandDocMetadata, withCommandDocMetadata } from "./internal/command-doc-metadata.js";
7
8
  import { defineKnownCompletionLookup, defineOptionMatch, definePassThroughPriority, getKnownCompletion, getOptionMatch, getPassThroughPriority } from "./internal/passthrough.js";
8
9
  import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
9
10
  import { completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult } from "./phase2-seed.js";
@@ -653,10 +654,10 @@ function withDefault(parser, defaultValue, options) {
653
654
  };
654
655
  return fragment;
655
656
  });
656
- return {
657
+ return withCommandDocMetadata({
657
658
  ...fragments,
658
659
  fragments: modifiedFragments
659
- };
660
+ }, getCommandDocMetadata(fragments));
660
661
  }
661
662
  return fragments;
662
663
  }
@@ -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');
@@ -257,7 +258,7 @@ function* getSuggestionsWithDependency(valueParser, prefix, dependencyRegistry,
257
258
  * @internal
258
259
  */
259
260
  function* suggestOptionSync(optionNames$1, valueParser, hidden, description, context, prefix) {
260
- if (hidden) return;
261
+ if (hidden || context.optionsTerminated) return;
261
262
  const equalsIndex = prefix.indexOf("=");
262
263
  if (equalsIndex >= 0) {
263
264
  const optionPart = prefix.slice(0, equalsIndex);
@@ -342,7 +343,7 @@ async function* getSuggestionsWithDependencyAsync(valueParser, prefix, dependenc
342
343
  * @internal
343
344
  */
344
345
  async function* suggestOptionAsync(optionNames$1, valueParser, hidden, description, context, prefix) {
345
- if (hidden) return;
346
+ if (hidden || context.optionsTerminated) return;
346
347
  const equalsIndex = prefix.indexOf("=");
347
348
  if (equalsIndex >= 0) {
348
349
  const optionPart = prefix.slice(0, equalsIndex);
@@ -646,10 +647,10 @@ function option(...args) {
646
647
  return suggestOptionSync(optionNames$1, valueParser, require_usage.isSuggestionHidden(options.hidden), options.description, context, prefix);
647
648
  },
648
649
  getDocFragments(_state, defaultValue) {
649
- if (require_usage.isDocHidden(options.hidden)) return {
650
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
650
651
  fragments: [],
651
652
  description: options.description
652
- };
653
+ }, {});
653
654
  const choicesMessage = valueParser?.choices != null && valueParser.choices.length > 0 ? require_message.valueSet(valueParser.choices.map((c) => valueParser.format(c)), {
654
655
  fallback: "",
655
656
  type: "unit"
@@ -665,10 +666,10 @@ function option(...args) {
665
666
  default: defaultValue != null && valueParser != null ? require_message.message`${valueParser.format(defaultValue)}` : void 0,
666
667
  choices: choicesMessage
667
668
  }];
668
- return {
669
+ return require_command_doc_metadata.withCommandDocMetadata({
669
670
  fragments,
670
671
  description: options.description
671
- };
672
+ }, {});
672
673
  },
673
674
  [Symbol.for("Deno.customInspect")]() {
674
675
  return `option(${optionNames$1.map((o) => JSON.stringify(o)).join(", ")})`;
@@ -921,8 +922,8 @@ function flag(...args) {
921
922
  error: require_message.message`${require_message.optionNames(optionNames$1)}: ${state.error}`
922
923
  };
923
924
  },
924
- suggest(_context, prefix) {
925
- if (require_usage.isSuggestionHidden(options.hidden)) return [];
925
+ suggest(context, prefix) {
926
+ if (require_usage.isSuggestionHidden(options.hidden) || context.optionsTerminated) return [];
926
927
  const suggestions = [];
927
928
  if (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/") || prefix.startsWith("+")) {
928
929
  for (const optionName$1 of optionNames$1) if (optionName$1.startsWith(prefix)) {
@@ -937,10 +938,10 @@ function flag(...args) {
937
938
  return suggestions;
938
939
  },
939
940
  getDocFragments(_state, _defaultValue) {
940
- if (require_usage.isDocHidden(options.hidden)) return {
941
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
941
942
  fragments: [],
942
943
  description: options.description
943
- };
944
+ }, {});
944
945
  const fragments = [{
945
946
  type: "entry",
946
947
  term: {
@@ -949,10 +950,10 @@ function flag(...args) {
949
950
  },
950
951
  description: options.description
951
952
  }];
952
- return {
953
+ return require_command_doc_metadata.withCommandDocMetadata({
953
954
  fragments,
954
955
  description: options.description
955
- };
956
+ }, {});
956
957
  },
957
958
  [Symbol.for("Deno.customInspect")]() {
958
959
  return `flag(${optionNames$1.map((o) => JSON.stringify(o)).join(", ")})`;
@@ -1309,10 +1310,10 @@ function argument(valueParser, options = {}) {
1309
1310
  return suggestArgumentSync(valueParser, require_usage.isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry, context.exec);
1310
1311
  },
1311
1312
  getDocFragments(_state, defaultValue) {
1312
- if (require_usage.isDocHidden(options.hidden)) return {
1313
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
1313
1314
  fragments: [],
1314
1315
  description: options.description
1315
- };
1316
+ }, {});
1316
1317
  const choicesMessage = valueParser.choices != null && valueParser.choices.length > 0 ? require_message.valueSet(valueParser.choices.map((c) => valueParser.format(c)), {
1317
1318
  fallback: "",
1318
1319
  type: "unit"
@@ -1324,10 +1325,10 @@ function argument(valueParser, options = {}) {
1324
1325
  default: defaultValue == null ? void 0 : require_message.message`${valueParser.format(defaultValue)}`,
1325
1326
  choices: choicesMessage
1326
1327
  }];
1327
- return {
1328
+ return require_command_doc_metadata.withCommandDocMetadata({
1328
1329
  fragments,
1329
1330
  description: options.description
1330
- };
1331
+ }, {});
1331
1332
  },
1332
1333
  [Symbol.for("Deno.customInspect")]() {
1333
1334
  return `argument()`;
@@ -1678,11 +1679,11 @@ function command(name, parser, options = {}) {
1678
1679
  getDocFragments(state, defaultValue) {
1679
1680
  const commandState = state.kind === "available" ? normalizeCommandState(state.state) : void 0;
1680
1681
  if (state.kind === "unavailable" || typeof commandState === "undefined") {
1681
- if (require_usage.isDocHidden(options.hidden)) return {
1682
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
1682
1683
  fragments: [],
1683
1684
  description: options.description
1684
- };
1685
- return {
1685
+ }, {});
1686
+ return require_command_doc_metadata.withCommandDocMetadata({
1686
1687
  description: options.description,
1687
1688
  fragments: [{
1688
1689
  type: "entry",
@@ -1692,7 +1693,7 @@ function command(name, parser, options = {}) {
1692
1693
  },
1693
1694
  description: options.brief ?? options.description
1694
1695
  }]
1695
- };
1696
+ }, {});
1696
1697
  }
1697
1698
  const innerState = commandState[0] === "parsing" ? {
1698
1699
  kind: "available",
@@ -1702,12 +1703,18 @@ function command(name, parser, options = {}) {
1702
1703
  state: getCommandChildState(state.state, parser.initialState, parser)
1703
1704
  };
1704
1705
  const innerFragments = parser.getDocFragments(innerState, defaultValue);
1705
- return {
1706
+ const innerMetadata = require_command_doc_metadata.getCommandDocMetadata(innerFragments) ?? innerFragments;
1707
+ return require_command_doc_metadata.withCommandDocMetadata({
1706
1708
  ...innerFragments,
1707
1709
  brief: innerFragments.brief ?? options.brief,
1708
1710
  description: innerFragments.description ?? options.description,
1709
1711
  footer: innerFragments.footer ?? options.footer
1710
- };
1712
+ }, {
1713
+ origin: "command",
1714
+ brief: innerMetadata?.brief ?? options.brief,
1715
+ description: innerMetadata?.description ?? options.description,
1716
+ footer: innerMetadata?.footer ?? options.footer
1717
+ });
1711
1718
  },
1712
1719
  [Symbol.for("Deno.customInspect")]() {
1713
1720
  return `command(${JSON.stringify(name)})`;
@@ -1932,18 +1939,18 @@ function passThrough(options = {}) {
1932
1939
  return [];
1933
1940
  },
1934
1941
  getDocFragments(_state, _defaultValue) {
1935
- if (require_usage.isDocHidden(options.hidden)) return {
1942
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
1936
1943
  fragments: [],
1937
1944
  description: options.description
1938
- };
1939
- return {
1945
+ }, {});
1946
+ return require_command_doc_metadata.withCommandDocMetadata({
1940
1947
  fragments: [{
1941
1948
  type: "entry",
1942
1949
  term: { type: "passthrough" },
1943
1950
  description: options.description
1944
1951
  }],
1945
1952
  description: options.description
1946
- };
1953
+ }, {});
1947
1954
  },
1948
1955
  [Symbol.for("Deno.customInspect")]() {
1949
1956
  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 { effectfulSchedulingNodesKey, exclusiveSourceScopeKey, includeSourceFailureChain, recordDerivedRawInput, replayDerivedParser, replayDerivedParserAsync, sourceCollectionExpansionKey } 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";
@@ -257,7 +258,7 @@ function* getSuggestionsWithDependency(valueParser, prefix, dependencyRegistry,
257
258
  * @internal
258
259
  */
259
260
  function* suggestOptionSync(optionNames$1, valueParser, hidden, description, context, prefix) {
260
- if (hidden) return;
261
+ if (hidden || context.optionsTerminated) return;
261
262
  const equalsIndex = prefix.indexOf("=");
262
263
  if (equalsIndex >= 0) {
263
264
  const optionPart = prefix.slice(0, equalsIndex);
@@ -342,7 +343,7 @@ async function* getSuggestionsWithDependencyAsync(valueParser, prefix, dependenc
342
343
  * @internal
343
344
  */
344
345
  async function* suggestOptionAsync(optionNames$1, valueParser, hidden, description, context, prefix) {
345
- if (hidden) return;
346
+ if (hidden || context.optionsTerminated) return;
346
347
  const equalsIndex = prefix.indexOf("=");
347
348
  if (equalsIndex >= 0) {
348
349
  const optionPart = prefix.slice(0, equalsIndex);
@@ -646,10 +647,10 @@ function option(...args) {
646
647
  return suggestOptionSync(optionNames$1, valueParser, isSuggestionHidden(options.hidden), options.description, context, prefix);
647
648
  },
648
649
  getDocFragments(_state, defaultValue) {
649
- if (isDocHidden(options.hidden)) return {
650
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
650
651
  fragments: [],
651
652
  description: options.description
652
- };
653
+ }, {});
653
654
  const choicesMessage = valueParser?.choices != null && valueParser.choices.length > 0 ? valueSet(valueParser.choices.map((c) => valueParser.format(c)), {
654
655
  fallback: "",
655
656
  type: "unit"
@@ -665,10 +666,10 @@ function option(...args) {
665
666
  default: defaultValue != null && valueParser != null ? message`${valueParser.format(defaultValue)}` : void 0,
666
667
  choices: choicesMessage
667
668
  }];
668
- return {
669
+ return withCommandDocMetadata({
669
670
  fragments,
670
671
  description: options.description
671
- };
672
+ }, {});
672
673
  },
673
674
  [Symbol.for("Deno.customInspect")]() {
674
675
  return `option(${optionNames$1.map((o) => JSON.stringify(o)).join(", ")})`;
@@ -921,8 +922,8 @@ function flag(...args) {
921
922
  error: message`${optionNames(optionNames$1)}: ${state.error}`
922
923
  };
923
924
  },
924
- suggest(_context, prefix) {
925
- if (isSuggestionHidden(options.hidden)) return [];
925
+ suggest(context, prefix) {
926
+ if (isSuggestionHidden(options.hidden) || context.optionsTerminated) return [];
926
927
  const suggestions = [];
927
928
  if (prefix.startsWith("--") || prefix.startsWith("-") || prefix.startsWith("/") || prefix.startsWith("+")) {
928
929
  for (const optionName$1 of optionNames$1) if (optionName$1.startsWith(prefix)) {
@@ -937,10 +938,10 @@ function flag(...args) {
937
938
  return suggestions;
938
939
  },
939
940
  getDocFragments(_state, _defaultValue) {
940
- if (isDocHidden(options.hidden)) return {
941
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
941
942
  fragments: [],
942
943
  description: options.description
943
- };
944
+ }, {});
944
945
  const fragments = [{
945
946
  type: "entry",
946
947
  term: {
@@ -949,10 +950,10 @@ function flag(...args) {
949
950
  },
950
951
  description: options.description
951
952
  }];
952
- return {
953
+ return withCommandDocMetadata({
953
954
  fragments,
954
955
  description: options.description
955
- };
956
+ }, {});
956
957
  },
957
958
  [Symbol.for("Deno.customInspect")]() {
958
959
  return `flag(${optionNames$1.map((o) => JSON.stringify(o)).join(", ")})`;
@@ -1309,10 +1310,10 @@ function argument(valueParser, options = {}) {
1309
1310
  return suggestArgumentSync(valueParser, isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry, context.exec);
1310
1311
  },
1311
1312
  getDocFragments(_state, defaultValue) {
1312
- if (isDocHidden(options.hidden)) return {
1313
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
1313
1314
  fragments: [],
1314
1315
  description: options.description
1315
- };
1316
+ }, {});
1316
1317
  const choicesMessage = valueParser.choices != null && valueParser.choices.length > 0 ? valueSet(valueParser.choices.map((c) => valueParser.format(c)), {
1317
1318
  fallback: "",
1318
1319
  type: "unit"
@@ -1324,10 +1325,10 @@ function argument(valueParser, options = {}) {
1324
1325
  default: defaultValue == null ? void 0 : message`${valueParser.format(defaultValue)}`,
1325
1326
  choices: choicesMessage
1326
1327
  }];
1327
- return {
1328
+ return withCommandDocMetadata({
1328
1329
  fragments,
1329
1330
  description: options.description
1330
- };
1331
+ }, {});
1331
1332
  },
1332
1333
  [Symbol.for("Deno.customInspect")]() {
1333
1334
  return `argument()`;
@@ -1678,11 +1679,11 @@ function command(name, parser, options = {}) {
1678
1679
  getDocFragments(state, defaultValue) {
1679
1680
  const commandState = state.kind === "available" ? normalizeCommandState(state.state) : void 0;
1680
1681
  if (state.kind === "unavailable" || typeof commandState === "undefined") {
1681
- if (isDocHidden(options.hidden)) return {
1682
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
1682
1683
  fragments: [],
1683
1684
  description: options.description
1684
- };
1685
- return {
1685
+ }, {});
1686
+ return withCommandDocMetadata({
1686
1687
  description: options.description,
1687
1688
  fragments: [{
1688
1689
  type: "entry",
@@ -1692,7 +1693,7 @@ function command(name, parser, options = {}) {
1692
1693
  },
1693
1694
  description: options.brief ?? options.description
1694
1695
  }]
1695
- };
1696
+ }, {});
1696
1697
  }
1697
1698
  const innerState = commandState[0] === "parsing" ? {
1698
1699
  kind: "available",
@@ -1702,12 +1703,18 @@ function command(name, parser, options = {}) {
1702
1703
  state: getCommandChildState(state.state, parser.initialState, parser)
1703
1704
  };
1704
1705
  const innerFragments = parser.getDocFragments(innerState, defaultValue);
1705
- return {
1706
+ const innerMetadata = getCommandDocMetadata(innerFragments) ?? innerFragments;
1707
+ return withCommandDocMetadata({
1706
1708
  ...innerFragments,
1707
1709
  brief: innerFragments.brief ?? options.brief,
1708
1710
  description: innerFragments.description ?? options.description,
1709
1711
  footer: innerFragments.footer ?? options.footer
1710
- };
1712
+ }, {
1713
+ origin: "command",
1714
+ brief: innerMetadata?.brief ?? options.brief,
1715
+ description: innerMetadata?.description ?? options.description,
1716
+ footer: innerMetadata?.footer ?? options.footer
1717
+ });
1711
1718
  },
1712
1719
  [Symbol.for("Deno.customInspect")]() {
1713
1720
  return `command(${JSON.stringify(name)})`;
@@ -1932,18 +1939,18 @@ function passThrough(options = {}) {
1932
1939
  return [];
1933
1940
  },
1934
1941
  getDocFragments(_state, _defaultValue) {
1935
- if (isDocHidden(options.hidden)) return {
1942
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
1936
1943
  fragments: [],
1937
1944
  description: options.description
1938
- };
1939
- return {
1945
+ }, {});
1946
+ return withCommandDocMetadata({
1940
1947
  fragments: [{
1941
1948
  type: "entry",
1942
1949
  term: { type: "passthrough" },
1943
1950
  description: options.description
1944
1951
  }],
1945
1952
  description: options.description
1946
- };
1953
+ }, {});
1947
1954
  },
1948
1955
  [Symbol.for("Deno.customInspect")]() {
1949
1956
  return `passThrough(${format})`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",
@@ -237,7 +237,7 @@
237
237
  },
238
238
  "sideEffects": false,
239
239
  "devDependencies": {
240
- "@optique/env": "1.3.3",
240
+ "@optique/env": "1.3.5",
241
241
  "@types/node": "^24.0.0",
242
242
  "fast-check": "^4.7.0",
243
243
  "tsdown": "^0.13.0",