@optique/core 1.4.0-dev.2740 → 1.4.0-dev.2748

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.
@@ -13,6 +13,7 @@ const require_empty_input = require('./internal/empty-input.cjs');
13
13
  const require_execution_context = require('./execution-context.cjs');
14
14
  const require_usage_internals = require('./usage-internals.cjs');
15
15
  const require_short_option = require('./short-option.cjs');
16
+ const require_command_doc_metadata = require('./internal/command-doc-metadata.cjs');
16
17
  const require_passthrough = require('./internal/passthrough.cjs');
17
18
  const require_command_alias = require('./internal/command-alias.cjs');
18
19
  const require_failure = require('./internal/failure.cjs');
@@ -1977,6 +1978,7 @@ function or(...args) {
1977
1978
  children.push(docs);
1978
1979
  return docs.fragments;
1979
1980
  };
1981
+ let commandMetadata;
1980
1982
  let brief;
1981
1983
  let description;
1982
1984
  let footer;
@@ -1989,19 +1991,20 @@ function or(...args) {
1989
1991
  state: parserResult.next.state
1990
1992
  } : { kind: "unavailable" };
1991
1993
  const docFragments = parsers[index].getDocFragments(innerState, void 0);
1994
+ commandMetadata = require_command_doc_metadata.getCommandDocMetadata(docFragments);
1992
1995
  brief = docFragments.brief;
1993
1996
  description = docFragments.description;
1994
1997
  footer = docFragments.footer;
1995
1998
  fragments = collect(docFragments);
1996
1999
  }
1997
2000
  if (state.kind === "unavailable" || state.state == null) fragments = require_doc.deduplicateDocFragments(fragments);
1998
- return {
2001
+ return require_command_doc_metadata.withCommandDocMetadata({
1999
2002
  ...sourceDocumentation(children),
2000
2003
  brief,
2001
2004
  description,
2002
2005
  footer,
2003
2006
  fragments
2004
- };
2007
+ }, commandMetadata);
2005
2008
  }
2006
2009
  };
2007
2010
  const singleDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -2214,6 +2217,7 @@ function createLongestMatch(...args) {
2214
2217
  children.push(docs);
2215
2218
  return docs.fragments;
2216
2219
  };
2220
+ let commandMetadata;
2217
2221
  let brief;
2218
2222
  let description;
2219
2223
  let footer;
@@ -2229,6 +2233,7 @@ function createLongestMatch(...args) {
2229
2233
  kind: "available",
2230
2234
  state: result.next.state
2231
2235
  });
2236
+ commandMetadata = require_command_doc_metadata.getCommandDocMetadata(docResult);
2232
2237
  brief = docResult.brief;
2233
2238
  description = docResult.description;
2234
2239
  footer = docResult.footer;
@@ -2239,13 +2244,13 @@ function createLongestMatch(...args) {
2239
2244
  shouldDeduplicate = true;
2240
2245
  }
2241
2246
  }
2242
- return {
2247
+ return require_command_doc_metadata.withCommandDocMetadata({
2243
2248
  ...sourceDocumentation(children),
2244
2249
  brief,
2245
2250
  description,
2246
2251
  fragments: shouldDeduplicate ? require_doc.deduplicateDocFragments(fragments) : fragments,
2247
2252
  footer
2248
- };
2253
+ }, commandMetadata);
2249
2254
  }
2250
2255
  };
2251
2256
  const multiDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -3252,12 +3257,15 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3252
3257
  children.push(docs);
3253
3258
  return docs.fragments;
3254
3259
  };
3260
+ let commandMetadata;
3255
3261
  const fragments = parserPairs.flatMap(([field, p]) => {
3256
3262
  const fieldState = state.kind === "unavailable" ? { kind: "unavailable" } : {
3257
3263
  kind: "available",
3258
3264
  state: state.state[field]
3259
3265
  };
3260
- return collect(p.getDocFragments(fieldState, defaultValue?.[field]));
3266
+ const docs = p.getDocFragments(fieldState, defaultValue?.[field]);
3267
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs);
3268
+ return collect(docs);
3261
3269
  });
3262
3270
  const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
3263
3271
  const entries = hiddenAwareFragments.filter((d) => d.type === "entry");
@@ -3272,13 +3280,14 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3272
3280
  entries
3273
3281
  };
3274
3282
  sections.push(section);
3275
- return {
3283
+ return require_command_doc_metadata.withCommandDocMetadata({
3276
3284
  ...sourceDocumentation(children, options.hidden),
3285
+ ...commandMetadata,
3277
3286
  fragments: sections.map((s) => ({
3278
3287
  ...s,
3279
3288
  type: "section"
3280
3289
  }))
3281
- };
3290
+ }, commandMetadata);
3282
3291
  }
3283
3292
  };
3284
3293
  const fieldNormalizers = [];
@@ -4304,12 +4313,15 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
4304
4313
  children.push(docs);
4305
4314
  return docs.fragments;
4306
4315
  };
4316
+ let commandMetadata;
4307
4317
  const fragments = syncParsers.flatMap((p, i) => {
4308
4318
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
4309
4319
  kind: "available",
4310
4320
  state: state.state[i]
4311
4321
  };
4312
- return collect(p.getDocFragments(indexState, defaultValue?.[i]));
4322
+ const docs = p.getDocFragments(indexState, defaultValue?.[i]);
4323
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs);
4324
+ return collect(docs);
4313
4325
  });
4314
4326
  const entries = fragments.filter((d) => d.type === "entry");
4315
4327
  const sections = [];
@@ -4323,13 +4335,14 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
4323
4335
  entries
4324
4336
  };
4325
4337
  sections.push(section);
4326
- return {
4338
+ return require_command_doc_metadata.withCommandDocMetadata({
4327
4339
  ...sourceDocumentation(children),
4340
+ ...commandMetadata,
4328
4341
  fragments: sections.map((s) => ({
4329
4342
  ...s,
4330
4343
  type: "section"
4331
4344
  }))
4332
- };
4345
+ }, commandMetadata);
4333
4346
  },
4334
4347
  [Symbol.for("Deno.customInspect")]() {
4335
4348
  const parsersStr = parsers.length === 1 ? `[1 parser]` : `[${parsers.length} parsers]`;
@@ -5688,6 +5701,7 @@ function merge(...args) {
5688
5701
  children.push(docs);
5689
5702
  return docs.fragments;
5690
5703
  };
5704
+ let commandMetadata;
5691
5705
  let brief;
5692
5706
  let description;
5693
5707
  let footer;
@@ -5705,6 +5719,7 @@ function merge(...args) {
5705
5719
  state: state.state
5706
5720
  };
5707
5721
  const docFragments = p.getDocFragments(parserState, void 0);
5722
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docFragments, true);
5708
5723
  brief ??= docFragments.brief;
5709
5724
  description ??= docFragments.description;
5710
5725
  footer ??= docFragments.footer;
@@ -5724,7 +5739,7 @@ function merge(...args) {
5724
5739
  entries
5725
5740
  };
5726
5741
  sections.push(labeledSection);
5727
- return {
5742
+ return require_command_doc_metadata.withCommandDocMetadata({
5728
5743
  ...sourceDocumentation(children, options.hidden),
5729
5744
  brief,
5730
5745
  description,
@@ -5733,9 +5748,9 @@ function merge(...args) {
5733
5748
  ...s,
5734
5749
  type: "section"
5735
5750
  }))
5736
- };
5751
+ }, commandMetadata);
5737
5752
  }
5738
- return {
5753
+ return require_command_doc_metadata.withCommandDocMetadata({
5739
5754
  ...sourceDocumentation(children, options.hidden),
5740
5755
  brief,
5741
5756
  description,
@@ -5747,7 +5762,7 @@ function merge(...args) {
5747
5762
  type: "section",
5748
5763
  entries
5749
5764
  }]
5750
- };
5765
+ }, commandMetadata);
5751
5766
  }
5752
5767
  };
5753
5768
  require_internal_parser.defineParseLanes(mergeParser, mergeParseLanes);
@@ -6383,12 +6398,15 @@ function concat(...parsers) {
6383
6398
  children.push(docs);
6384
6399
  return docs.fragments;
6385
6400
  };
6401
+ let commandMetadata;
6386
6402
  const fragments = syncParsers.flatMap((p, index) => {
6387
6403
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
6388
6404
  kind: "available",
6389
6405
  state: state.state[index]
6390
6406
  };
6391
- return collect(p.getDocFragments(indexState, void 0));
6407
+ const docs = p.getDocFragments(indexState, void 0);
6408
+ commandMetadata = require_command_doc_metadata.collectCommandDocMetadata(commandMetadata, docs);
6409
+ return collect(docs);
6392
6410
  });
6393
6411
  const entries = fragments.filter((f) => f.type === "entry");
6394
6412
  const sections = [];
@@ -6405,10 +6423,11 @@ function concat(...parsers) {
6405
6423
  type: "section",
6406
6424
  entries
6407
6425
  });
6408
- return {
6426
+ return require_command_doc_metadata.withCommandDocMetadata({
6409
6427
  ...sourceDocumentation(children),
6428
+ ...commandMetadata,
6410
6429
  fragments: result
6411
- };
6430
+ }, commandMetadata);
6412
6431
  }
6413
6432
  };
6414
6433
  require_internal_parser.defineInheritedAnnotationParser(concatParser);
@@ -6479,7 +6498,7 @@ function group(label, parser, options = {}) {
6479
6498
  title: label,
6480
6499
  entries: allEntries
6481
6500
  } : { entries: allEntries };
6482
- return {
6501
+ return require_command_doc_metadata.withCommandDocMetadata({
6483
6502
  ...sourceDocumentation(children, options.hidden),
6484
6503
  brief,
6485
6504
  description,
@@ -6491,7 +6510,7 @@ function group(label, parser, options = {}) {
6491
6510
  type: "section",
6492
6511
  ...labeledSection
6493
6512
  }]
6494
- };
6513
+ }, require_command_doc_metadata.getCommandDocMetadata(docs));
6495
6514
  }
6496
6515
  };
6497
6516
  require_internal_parser.defineParseLanes(groupParser, require_internal_parser.getOwnParseLanes(parser));
@@ -13,6 +13,7 @@ import { acceptsEmptyInput, getEmptyInputFacts, longestMatchFacts, objectFacts,
13
13
  import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
14
14
  import { collectLeadingCandidates } from "./usage-internals.js";
15
15
  import { adoptOptionScope, combinedOptionScope, conditionalOptionScope, forkOptionScope, restoreOptionScope, scopeParser, selectableOptionScope, withOptionScope, withParserOptionScope } from "./short-option.js";
16
+ import { collectCommandDocMetadata, getCommandDocMetadata, withCommandDocMetadata } from "./internal/command-doc-metadata.js";
16
17
  import { defineReachableChildren, delegateKnownCompletion, getKnownCompletion, getOptionMatch, getPassThroughFailureHint, getPassThroughPriority, hasPassThroughUsage, matchesOptionToken, retainConsumingFailure, retainConsumingFailureHint, withPassThroughFailure, withReturnedConsumingFailure } from "./internal/passthrough.js";
17
18
  import { allowDuplicateLeadingCommandNamesKey } from "./internal/command-alias.js";
18
19
  import { createDeferredFailure, withConsumedDepth } from "./internal/failure.js";
@@ -1977,6 +1978,7 @@ function or(...args) {
1977
1978
  children.push(docs);
1978
1979
  return docs.fragments;
1979
1980
  };
1981
+ let commandMetadata;
1980
1982
  let brief;
1981
1983
  let description;
1982
1984
  let footer;
@@ -1989,19 +1991,20 @@ function or(...args) {
1989
1991
  state: parserResult.next.state
1990
1992
  } : { kind: "unavailable" };
1991
1993
  const docFragments = parsers[index].getDocFragments(innerState, void 0);
1994
+ commandMetadata = getCommandDocMetadata(docFragments);
1992
1995
  brief = docFragments.brief;
1993
1996
  description = docFragments.description;
1994
1997
  footer = docFragments.footer;
1995
1998
  fragments = collect(docFragments);
1996
1999
  }
1997
2000
  if (state.kind === "unavailable" || state.state == null) fragments = deduplicateDocFragments(fragments);
1998
- return {
2001
+ return withCommandDocMetadata({
1999
2002
  ...sourceDocumentation(children),
2000
2003
  brief,
2001
2004
  description,
2002
2005
  footer,
2003
2006
  fragments
2004
- };
2007
+ }, commandMetadata);
2005
2008
  }
2006
2009
  };
2007
2010
  const singleDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -2214,6 +2217,7 @@ function createLongestMatch(...args) {
2214
2217
  children.push(docs);
2215
2218
  return docs.fragments;
2216
2219
  };
2220
+ let commandMetadata;
2217
2221
  let brief;
2218
2222
  let description;
2219
2223
  let footer;
@@ -2229,6 +2233,7 @@ function createLongestMatch(...args) {
2229
2233
  kind: "available",
2230
2234
  state: result.next.state
2231
2235
  });
2236
+ commandMetadata = getCommandDocMetadata(docResult);
2232
2237
  brief = docResult.brief;
2233
2238
  description = docResult.description;
2234
2239
  footer = docResult.footer;
@@ -2239,13 +2244,13 @@ function createLongestMatch(...args) {
2239
2244
  shouldDeduplicate = true;
2240
2245
  }
2241
2246
  }
2242
- return {
2247
+ return withCommandDocMetadata({
2243
2248
  ...sourceDocumentation(children),
2244
2249
  brief,
2245
2250
  description,
2246
2251
  fragments: shouldDeduplicate ? deduplicateDocFragments(fragments) : fragments,
2247
2252
  footer
2248
- };
2253
+ }, commandMetadata);
2249
2254
  }
2250
2255
  };
2251
2256
  const multiDependencyMetadata = composeExclusiveDependencyMetadata(parsers);
@@ -3252,12 +3257,15 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3252
3257
  children.push(docs);
3253
3258
  return docs.fragments;
3254
3259
  };
3260
+ let commandMetadata;
3255
3261
  const fragments = parserPairs.flatMap(([field, p]) => {
3256
3262
  const fieldState = state.kind === "unavailable" ? { kind: "unavailable" } : {
3257
3263
  kind: "available",
3258
3264
  state: state.state[field]
3259
3265
  };
3260
- return collect(p.getDocFragments(fieldState, defaultValue?.[field]));
3266
+ const docs = p.getDocFragments(fieldState, defaultValue?.[field]);
3267
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docs);
3268
+ return collect(docs);
3261
3269
  });
3262
3270
  const hiddenAwareFragments = applyHiddenToDocFragments(fragments, options.hidden);
3263
3271
  const entries = hiddenAwareFragments.filter((d) => d.type === "entry");
@@ -3272,13 +3280,14 @@ function object(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
3272
3280
  entries
3273
3281
  };
3274
3282
  sections.push(section);
3275
- return {
3283
+ return withCommandDocMetadata({
3276
3284
  ...sourceDocumentation(children, options.hidden),
3285
+ ...commandMetadata,
3277
3286
  fragments: sections.map((s) => ({
3278
3287
  ...s,
3279
3288
  type: "section"
3280
3289
  }))
3281
- };
3290
+ }, commandMetadata);
3282
3291
  }
3283
3292
  };
3284
3293
  const fieldNormalizers = [];
@@ -4304,12 +4313,15 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
4304
4313
  children.push(docs);
4305
4314
  return docs.fragments;
4306
4315
  };
4316
+ let commandMetadata;
4307
4317
  const fragments = syncParsers.flatMap((p, i) => {
4308
4318
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
4309
4319
  kind: "available",
4310
4320
  state: state.state[i]
4311
4321
  };
4312
- return collect(p.getDocFragments(indexState, defaultValue?.[i]));
4322
+ const docs = p.getDocFragments(indexState, defaultValue?.[i]);
4323
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docs);
4324
+ return collect(docs);
4313
4325
  });
4314
4326
  const entries = fragments.filter((d) => d.type === "entry");
4315
4327
  const sections = [];
@@ -4323,13 +4335,14 @@ function tuple(labelOrParsers, maybeParsersOrOptions, maybeOptions) {
4323
4335
  entries
4324
4336
  };
4325
4337
  sections.push(section);
4326
- return {
4338
+ return withCommandDocMetadata({
4327
4339
  ...sourceDocumentation(children),
4340
+ ...commandMetadata,
4328
4341
  fragments: sections.map((s) => ({
4329
4342
  ...s,
4330
4343
  type: "section"
4331
4344
  }))
4332
- };
4345
+ }, commandMetadata);
4333
4346
  },
4334
4347
  [Symbol.for("Deno.customInspect")]() {
4335
4348
  const parsersStr = parsers.length === 1 ? `[1 parser]` : `[${parsers.length} parsers]`;
@@ -5688,6 +5701,7 @@ function merge(...args) {
5688
5701
  children.push(docs);
5689
5702
  return docs.fragments;
5690
5703
  };
5704
+ let commandMetadata;
5691
5705
  let brief;
5692
5706
  let description;
5693
5707
  let footer;
@@ -5705,6 +5719,7 @@ function merge(...args) {
5705
5719
  state: state.state
5706
5720
  };
5707
5721
  const docFragments = p.getDocFragments(parserState, void 0);
5722
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docFragments, true);
5708
5723
  brief ??= docFragments.brief;
5709
5724
  description ??= docFragments.description;
5710
5725
  footer ??= docFragments.footer;
@@ -5724,7 +5739,7 @@ function merge(...args) {
5724
5739
  entries
5725
5740
  };
5726
5741
  sections.push(labeledSection);
5727
- return {
5742
+ return withCommandDocMetadata({
5728
5743
  ...sourceDocumentation(children, options.hidden),
5729
5744
  brief,
5730
5745
  description,
@@ -5733,9 +5748,9 @@ function merge(...args) {
5733
5748
  ...s,
5734
5749
  type: "section"
5735
5750
  }))
5736
- };
5751
+ }, commandMetadata);
5737
5752
  }
5738
- return {
5753
+ return withCommandDocMetadata({
5739
5754
  ...sourceDocumentation(children, options.hidden),
5740
5755
  brief,
5741
5756
  description,
@@ -5747,7 +5762,7 @@ function merge(...args) {
5747
5762
  type: "section",
5748
5763
  entries
5749
5764
  }]
5750
- };
5765
+ }, commandMetadata);
5751
5766
  }
5752
5767
  };
5753
5768
  defineParseLanes(mergeParser, mergeParseLanes);
@@ -6383,12 +6398,15 @@ function concat(...parsers) {
6383
6398
  children.push(docs);
6384
6399
  return docs.fragments;
6385
6400
  };
6401
+ let commandMetadata;
6386
6402
  const fragments = syncParsers.flatMap((p, index) => {
6387
6403
  const indexState = state.kind === "unavailable" ? { kind: "unavailable" } : {
6388
6404
  kind: "available",
6389
6405
  state: state.state[index]
6390
6406
  };
6391
- return collect(p.getDocFragments(indexState, void 0));
6407
+ const docs = p.getDocFragments(indexState, void 0);
6408
+ commandMetadata = collectCommandDocMetadata(commandMetadata, docs);
6409
+ return collect(docs);
6392
6410
  });
6393
6411
  const entries = fragments.filter((f) => f.type === "entry");
6394
6412
  const sections = [];
@@ -6405,10 +6423,11 @@ function concat(...parsers) {
6405
6423
  type: "section",
6406
6424
  entries
6407
6425
  });
6408
- return {
6426
+ return withCommandDocMetadata({
6409
6427
  ...sourceDocumentation(children),
6428
+ ...commandMetadata,
6410
6429
  fragments: result
6411
- };
6430
+ }, commandMetadata);
6412
6431
  }
6413
6432
  };
6414
6433
  defineInheritedAnnotationParser(concatParser);
@@ -6479,7 +6498,7 @@ function group(label, parser, options = {}) {
6479
6498
  title: label,
6480
6499
  entries: allEntries
6481
6500
  } : { entries: allEntries };
6482
- return {
6501
+ return withCommandDocMetadata({
6483
6502
  ...sourceDocumentation(children, options.hidden),
6484
6503
  brief,
6485
6504
  description,
@@ -6491,7 +6510,7 @@ function group(label, parser, options = {}) {
6491
6510
  type: "section",
6492
6511
  ...labeledSection
6493
6512
  }]
6494
- };
6513
+ }, getCommandDocMetadata(docs));
6495
6514
  }
6496
6515
  };
6497
6516
  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 };
@@ -7,6 +7,7 @@ const require_annotation_state = require('./annotation-state.cjs');
7
7
  const require_empty_input = require('./internal/empty-input.cjs');
8
8
  const require_execution_context = require('./execution-context.cjs');
9
9
  const require_short_option = require('./short-option.cjs');
10
+ const require_command_doc_metadata = require('./internal/command-doc-metadata.cjs');
10
11
  const require_passthrough = require('./internal/passthrough.cjs');
11
12
  const require_phase2_seed = require('./phase2-seed.cjs');
12
13
  const require_dependency_metadata = require('./dependency-metadata.cjs');
@@ -667,10 +668,10 @@ function withDefault(parser, defaultValue, options) {
667
668
  };
668
669
  return fragment;
669
670
  });
670
- return {
671
+ return require_command_doc_metadata.withCommandDocMetadata({
671
672
  ...fragments,
672
673
  fragments: modifiedFragments
673
- };
674
+ }, require_command_doc_metadata.getCommandDocMetadata(fragments));
674
675
  }
675
676
  return fragments;
676
677
  }
package/dist/modifiers.js CHANGED
@@ -7,6 +7,7 @@ import { getDelegatedAnnotationState, hasDelegatedAnnotationCarrier, isAnnotatio
7
7
  import { acceptsEmptyInput, defineEmptyInputFacts, getEmptyInputFacts, multipleFacts, optionalLikeFacts, resolveEmptyStepState } from "./internal/empty-input.js";
8
8
  import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
9
9
  import { combinedOptionScope, repeatedOptionScope, scopeParser } from "./short-option.js";
10
+ import { getCommandDocMetadata, withCommandDocMetadata } from "./internal/command-doc-metadata.js";
10
11
  import { defineKnownCompletionLookup, defineReachableChildren, getKnownCompletion } from "./internal/passthrough.js";
11
12
  import { completeOrExtractPhase2Seed, extractPhase2Seed, extractPhase2SeedKey, phase2SeedFromValueResult } from "./phase2-seed.js";
12
13
  import { composeDependencyMetadata } from "./dependency-metadata.js";
@@ -667,10 +668,10 @@ function withDefault(parser, defaultValue, options) {
667
668
  };
668
669
  return fragment;
669
670
  });
670
- return {
671
+ return withCommandDocMetadata({
671
672
  ...fragments,
672
673
  fragments: modifiedFragments
673
- };
674
+ }, getCommandDocMetadata(fragments));
674
675
  }
675
676
  return fragments;
676
677
  }
@@ -11,6 +11,7 @@ const require_empty_input = require('./internal/empty-input.cjs');
11
11
  const require_execution_context = require('./execution-context.cjs');
12
12
  const require_usage_internals = require('./usage-internals.cjs');
13
13
  const require_short_option = require('./short-option.cjs');
14
+ const require_command_doc_metadata = require('./internal/command-doc-metadata.cjs');
14
15
  const require_passthrough = require('./internal/passthrough.cjs');
15
16
  const require_command_alias = require('./internal/command-alias.cjs');
16
17
  const require_failure = require('./internal/failure.cjs');
@@ -695,10 +696,10 @@ function option(...args) {
695
696
  return suggestOptionSync(optionNames$1, valueParser, require_usage.isSuggestionHidden(options.hidden), options.description, context, prefix);
696
697
  },
697
698
  getDocFragments(_state, defaultValue) {
698
- if (require_usage.isDocHidden(options.hidden)) return {
699
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
699
700
  fragments: [],
700
701
  description: options.description
701
- };
702
+ }, {});
702
703
  const choicesMessage = valueParser?.choices != null && valueParser.choices.length > 0 ? require_message.valueSet(valueParser.choices.map((c) => valueParser.format(c)), {
703
704
  fallback: "",
704
705
  type: "unit"
@@ -714,10 +715,10 @@ function option(...args) {
714
715
  default: defaultValue != null && valueParser != null ? require_message.message`${valueParser.format(defaultValue)}` : void 0,
715
716
  choices: choicesMessage
716
717
  }];
717
- return {
718
+ return require_command_doc_metadata.withCommandDocMetadata({
718
719
  fragments,
719
720
  description: options.description
720
- };
721
+ }, {});
721
722
  },
722
723
  [Symbol.for("Deno.customInspect")]() {
723
724
  return `option(${optionNames$1.map((o) => JSON.stringify(o)).join(", ")})`;
@@ -967,10 +968,10 @@ function flag(...args) {
967
968
  return suggestions;
968
969
  },
969
970
  getDocFragments(_state, _defaultValue) {
970
- if (require_usage.isDocHidden(options.hidden)) return {
971
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
971
972
  fragments: [],
972
973
  description: options.description
973
- };
974
+ }, {});
974
975
  const fragments = [{
975
976
  type: "entry",
976
977
  term: {
@@ -979,10 +980,10 @@ function flag(...args) {
979
980
  },
980
981
  description: options.description
981
982
  }];
982
- return {
983
+ return require_command_doc_metadata.withCommandDocMetadata({
983
984
  fragments,
984
985
  description: options.description
985
- };
986
+ }, {});
986
987
  },
987
988
  [Symbol.for("Deno.customInspect")]() {
988
989
  return `flag(${optionNames$1.map((o) => JSON.stringify(o)).join(", ")})`;
@@ -1324,10 +1325,10 @@ function argument(valueParser, options = {}) {
1324
1325
  return suggestArgumentSync(valueParser, require_usage.isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry, context.exec);
1325
1326
  },
1326
1327
  getDocFragments(_state, defaultValue) {
1327
- if (require_usage.isDocHidden(options.hidden)) return {
1328
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
1328
1329
  fragments: [],
1329
1330
  description: options.description
1330
- };
1331
+ }, {});
1331
1332
  const choicesMessage = valueParser.choices != null && valueParser.choices.length > 0 ? require_message.valueSet(valueParser.choices.map((c) => valueParser.format(c)), {
1332
1333
  fallback: "",
1333
1334
  type: "unit"
@@ -1339,10 +1340,10 @@ function argument(valueParser, options = {}) {
1339
1340
  default: defaultValue == null ? void 0 : require_message.message`${valueParser.format(defaultValue)}`,
1340
1341
  choices: choicesMessage
1341
1342
  }];
1342
- return {
1343
+ return require_command_doc_metadata.withCommandDocMetadata({
1343
1344
  fragments,
1344
1345
  description: options.description
1345
- };
1346
+ }, {});
1346
1347
  },
1347
1348
  [Symbol.for("Deno.customInspect")]() {
1348
1349
  return `argument()`;
@@ -1723,11 +1724,11 @@ function command(name, parser, options = {}) {
1723
1724
  getDocFragments(state, defaultValue) {
1724
1725
  const commandState = state.kind === "available" ? normalizeCommandState(state.state) : void 0;
1725
1726
  if (state.kind === "unavailable" || typeof commandState === "undefined") {
1726
- if (require_usage.isDocHidden(options.hidden)) return {
1727
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
1727
1728
  fragments: [],
1728
1729
  description: options.description
1729
- };
1730
- return {
1730
+ }, {});
1731
+ return require_command_doc_metadata.withCommandDocMetadata({
1731
1732
  description: options.description,
1732
1733
  fragments: [{
1733
1734
  type: "entry",
@@ -1739,7 +1740,7 @@ function command(name, parser, options = {}) {
1739
1740
  description: options.brief ?? options.description,
1740
1741
  ...showAliases != null && { showAliases }
1741
1742
  }]
1742
- };
1743
+ }, {});
1743
1744
  }
1744
1745
  const innerState = commandState[0] === "parsing" ? {
1745
1746
  kind: "available",
@@ -1749,12 +1750,18 @@ function command(name, parser, options = {}) {
1749
1750
  state: getCommandChildState(state.state, parser.initialState, parser)
1750
1751
  };
1751
1752
  const innerFragments = parser.getDocFragments(innerState, defaultValue);
1752
- return {
1753
+ const innerMetadata = require_command_doc_metadata.getCommandDocMetadata(innerFragments) ?? innerFragments;
1754
+ return require_command_doc_metadata.withCommandDocMetadata({
1753
1755
  ...innerFragments,
1754
1756
  brief: innerFragments.brief ?? options.brief,
1755
1757
  description: innerFragments.description ?? options.description,
1756
1758
  footer: innerFragments.footer ?? options.footer
1757
- };
1759
+ }, {
1760
+ origin: "command",
1761
+ brief: innerMetadata?.brief ?? options.brief,
1762
+ description: innerMetadata?.description ?? options.description,
1763
+ footer: innerMetadata?.footer ?? options.footer
1764
+ });
1758
1765
  },
1759
1766
  [Symbol.for("Deno.customInspect")]() {
1760
1767
  return `command(${JSON.stringify(name)})`;
@@ -1972,18 +1979,18 @@ function passThrough(options = {}) {
1972
1979
  return [];
1973
1980
  },
1974
1981
  getDocFragments(_state, _defaultValue) {
1975
- if (require_usage.isDocHidden(options.hidden)) return {
1982
+ if (require_usage.isDocHidden(options.hidden)) return require_command_doc_metadata.withCommandDocMetadata({
1976
1983
  fragments: [],
1977
1984
  description: options.description
1978
- };
1979
- return {
1985
+ }, {});
1986
+ return require_command_doc_metadata.withCommandDocMetadata({
1980
1987
  fragments: [{
1981
1988
  type: "entry",
1982
1989
  term: { type: "passthrough" },
1983
1990
  description: options.description
1984
1991
  }],
1985
1992
  description: options.description
1986
- };
1993
+ }, {});
1987
1994
  },
1988
1995
  [Symbol.for("Deno.customInspect")]() {
1989
1996
  return `passThrough(${format})`;
@@ -11,6 +11,7 @@ import { UNCHANGED, defineEmptyInputFacts, failingStepFacts } from "./internal/e
11
11
  import { mergeChildExec, withChildContext, withChildExecPath } from "./execution-context.js";
12
12
  import { extractLeadingCommandNames } from "./usage-internals.js";
13
13
  import { attachedValuePrefix, combinedOptionScope, fullNameOwnsToken, prefixSuggestion, scopeParser, selectableOptionScope } from "./short-option.js";
14
+ import { getCommandDocMetadata, withCommandDocMetadata } from "./internal/command-doc-metadata.js";
14
15
  import { defineKnownCompletion, definePassThroughPriority, defineReachableChildren, getPassThroughFailure } from "./internal/passthrough.js";
15
16
  import { hiddenCommandAliasesKey } from "./internal/command-alias.js";
16
17
  import { createDeferredFailure } from "./internal/failure.js";
@@ -695,10 +696,10 @@ function option(...args) {
695
696
  return suggestOptionSync(optionNames$1, valueParser, isSuggestionHidden(options.hidden), options.description, context, prefix);
696
697
  },
697
698
  getDocFragments(_state, defaultValue) {
698
- if (isDocHidden(options.hidden)) return {
699
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
699
700
  fragments: [],
700
701
  description: options.description
701
- };
702
+ }, {});
702
703
  const choicesMessage = valueParser?.choices != null && valueParser.choices.length > 0 ? valueSet(valueParser.choices.map((c) => valueParser.format(c)), {
703
704
  fallback: "",
704
705
  type: "unit"
@@ -714,10 +715,10 @@ function option(...args) {
714
715
  default: defaultValue != null && valueParser != null ? message`${valueParser.format(defaultValue)}` : void 0,
715
716
  choices: choicesMessage
716
717
  }];
717
- return {
718
+ return withCommandDocMetadata({
718
719
  fragments,
719
720
  description: options.description
720
- };
721
+ }, {});
721
722
  },
722
723
  [Symbol.for("Deno.customInspect")]() {
723
724
  return `option(${optionNames$1.map((o) => JSON.stringify(o)).join(", ")})`;
@@ -967,10 +968,10 @@ function flag(...args) {
967
968
  return suggestions;
968
969
  },
969
970
  getDocFragments(_state, _defaultValue) {
970
- if (isDocHidden(options.hidden)) return {
971
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
971
972
  fragments: [],
972
973
  description: options.description
973
- };
974
+ }, {});
974
975
  const fragments = [{
975
976
  type: "entry",
976
977
  term: {
@@ -979,10 +980,10 @@ function flag(...args) {
979
980
  },
980
981
  description: options.description
981
982
  }];
982
- return {
983
+ return withCommandDocMetadata({
983
984
  fragments,
984
985
  description: options.description
985
- };
986
+ }, {});
986
987
  },
987
988
  [Symbol.for("Deno.customInspect")]() {
988
989
  return `flag(${optionNames$1.map((o) => JSON.stringify(o)).join(", ")})`;
@@ -1324,10 +1325,10 @@ function argument(valueParser, options = {}) {
1324
1325
  return suggestArgumentSync(valueParser, isSuggestionHidden(options.hidden), prefix, context.dependencyRegistry, context.exec);
1325
1326
  },
1326
1327
  getDocFragments(_state, defaultValue) {
1327
- if (isDocHidden(options.hidden)) return {
1328
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
1328
1329
  fragments: [],
1329
1330
  description: options.description
1330
- };
1331
+ }, {});
1331
1332
  const choicesMessage = valueParser.choices != null && valueParser.choices.length > 0 ? valueSet(valueParser.choices.map((c) => valueParser.format(c)), {
1332
1333
  fallback: "",
1333
1334
  type: "unit"
@@ -1339,10 +1340,10 @@ function argument(valueParser, options = {}) {
1339
1340
  default: defaultValue == null ? void 0 : message`${valueParser.format(defaultValue)}`,
1340
1341
  choices: choicesMessage
1341
1342
  }];
1342
- return {
1343
+ return withCommandDocMetadata({
1343
1344
  fragments,
1344
1345
  description: options.description
1345
- };
1346
+ }, {});
1346
1347
  },
1347
1348
  [Symbol.for("Deno.customInspect")]() {
1348
1349
  return `argument()`;
@@ -1723,11 +1724,11 @@ function command(name, parser, options = {}) {
1723
1724
  getDocFragments(state, defaultValue) {
1724
1725
  const commandState = state.kind === "available" ? normalizeCommandState(state.state) : void 0;
1725
1726
  if (state.kind === "unavailable" || typeof commandState === "undefined") {
1726
- if (isDocHidden(options.hidden)) return {
1727
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
1727
1728
  fragments: [],
1728
1729
  description: options.description
1729
- };
1730
- return {
1730
+ }, {});
1731
+ return withCommandDocMetadata({
1731
1732
  description: options.description,
1732
1733
  fragments: [{
1733
1734
  type: "entry",
@@ -1739,7 +1740,7 @@ function command(name, parser, options = {}) {
1739
1740
  description: options.brief ?? options.description,
1740
1741
  ...showAliases != null && { showAliases }
1741
1742
  }]
1742
- };
1743
+ }, {});
1743
1744
  }
1744
1745
  const innerState = commandState[0] === "parsing" ? {
1745
1746
  kind: "available",
@@ -1749,12 +1750,18 @@ function command(name, parser, options = {}) {
1749
1750
  state: getCommandChildState(state.state, parser.initialState, parser)
1750
1751
  };
1751
1752
  const innerFragments = parser.getDocFragments(innerState, defaultValue);
1752
- return {
1753
+ const innerMetadata = getCommandDocMetadata(innerFragments) ?? innerFragments;
1754
+ return withCommandDocMetadata({
1753
1755
  ...innerFragments,
1754
1756
  brief: innerFragments.brief ?? options.brief,
1755
1757
  description: innerFragments.description ?? options.description,
1756
1758
  footer: innerFragments.footer ?? options.footer
1757
- };
1759
+ }, {
1760
+ origin: "command",
1761
+ brief: innerMetadata?.brief ?? options.brief,
1762
+ description: innerMetadata?.description ?? options.description,
1763
+ footer: innerMetadata?.footer ?? options.footer
1764
+ });
1758
1765
  },
1759
1766
  [Symbol.for("Deno.customInspect")]() {
1760
1767
  return `command(${JSON.stringify(name)})`;
@@ -1972,18 +1979,18 @@ function passThrough(options = {}) {
1972
1979
  return [];
1973
1980
  },
1974
1981
  getDocFragments(_state, _defaultValue) {
1975
- if (isDocHidden(options.hidden)) return {
1982
+ if (isDocHidden(options.hidden)) return withCommandDocMetadata({
1976
1983
  fragments: [],
1977
1984
  description: options.description
1978
- };
1979
- return {
1985
+ }, {});
1986
+ return withCommandDocMetadata({
1980
1987
  fragments: [{
1981
1988
  type: "entry",
1982
1989
  term: { type: "passthrough" },
1983
1990
  description: options.description
1984
1991
  }],
1985
1992
  description: options.description
1986
- };
1993
+ }, {});
1987
1994
  },
1988
1995
  [Symbol.for("Deno.customInspect")]() {
1989
1996
  return `passThrough(${format})`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.4.0-dev.2740",
3
+ "version": "1.4.0-dev.2748",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",
@@ -253,7 +253,7 @@
253
253
  },
254
254
  "sideEffects": false,
255
255
  "devDependencies": {
256
- "@optique/env": "1.4.0-dev.2740+fe673463",
256
+ "@optique/env": "1.4.0-dev.2748+8f05c2bd",
257
257
  "@types/node": "^24.0.0",
258
258
  "fast-check": "^4.7.0",
259
259
  "tsdown": "^0.13.0",