@optique/core 0.8.9-dev.349 → 0.8.10

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.
@@ -238,7 +238,9 @@ function or(...args) {
238
238
  },
239
239
  suggest: createExclusiveSuggest(parsers),
240
240
  getDocFragments(state, _defaultValue) {
241
+ let brief;
241
242
  let description;
243
+ let footer;
242
244
  let fragments;
243
245
  if (state.kind === "unavailable" || state.state == null) fragments = parsers.flatMap((p) => p.getDocFragments({ kind: "unavailable" }, void 0).fragments);
244
246
  else {
@@ -248,7 +250,9 @@ function or(...args) {
248
250
  state: parserResult.next.state
249
251
  } : { kind: "unavailable" };
250
252
  const docFragments = parsers[index].getDocFragments(innerState, void 0);
253
+ brief = docFragments.brief;
251
254
  description = docFragments.description;
255
+ footer = docFragments.footer;
252
256
  fragments = docFragments.fragments;
253
257
  }
254
258
  const entries = fragments.filter((f) => f.type === "entry");
@@ -259,7 +263,9 @@ function or(...args) {
259
263
  else sections.push(fragment);
260
264
  }
261
265
  return {
266
+ brief,
262
267
  description,
268
+ footer,
263
269
  fragments: [...sections.map((s) => ({
264
270
  ...s,
265
271
  type: "section"
@@ -333,6 +339,7 @@ function longestMatch(...args) {
333
339
  },
334
340
  suggest: createExclusiveSuggest(parsers),
335
341
  getDocFragments(state, _defaultValue) {
342
+ let brief;
336
343
  let description;
337
344
  let footer;
338
345
  let fragments;
@@ -344,12 +351,14 @@ function longestMatch(...args) {
344
351
  kind: "available",
345
352
  state: result.next.state
346
353
  });
354
+ brief = docResult.brief;
347
355
  description = docResult.description;
348
356
  footer = docResult.footer;
349
357
  fragments = docResult.fragments;
350
358
  } else fragments = parsers.flatMap((p) => p.getDocFragments({ kind: "unavailable" }).fragments);
351
359
  }
352
360
  return {
361
+ brief,
353
362
  description,
354
363
  fragments,
355
364
  footer
@@ -238,7 +238,9 @@ function or(...args) {
238
238
  },
239
239
  suggest: createExclusiveSuggest(parsers),
240
240
  getDocFragments(state, _defaultValue) {
241
+ let brief;
241
242
  let description;
243
+ let footer;
242
244
  let fragments;
243
245
  if (state.kind === "unavailable" || state.state == null) fragments = parsers.flatMap((p) => p.getDocFragments({ kind: "unavailable" }, void 0).fragments);
244
246
  else {
@@ -248,7 +250,9 @@ function or(...args) {
248
250
  state: parserResult.next.state
249
251
  } : { kind: "unavailable" };
250
252
  const docFragments = parsers[index].getDocFragments(innerState, void 0);
253
+ brief = docFragments.brief;
251
254
  description = docFragments.description;
255
+ footer = docFragments.footer;
252
256
  fragments = docFragments.fragments;
253
257
  }
254
258
  const entries = fragments.filter((f) => f.type === "entry");
@@ -259,7 +263,9 @@ function or(...args) {
259
263
  else sections.push(fragment);
260
264
  }
261
265
  return {
266
+ brief,
262
267
  description,
268
+ footer,
263
269
  fragments: [...sections.map((s) => ({
264
270
  ...s,
265
271
  type: "section"
@@ -333,6 +339,7 @@ function longestMatch(...args) {
333
339
  },
334
340
  suggest: createExclusiveSuggest(parsers),
335
341
  getDocFragments(state, _defaultValue) {
342
+ let brief;
336
343
  let description;
337
344
  let footer;
338
345
  let fragments;
@@ -344,12 +351,14 @@ function longestMatch(...args) {
344
351
  kind: "available",
345
352
  state: result.next.state
346
353
  });
354
+ brief = docResult.brief;
347
355
  description = docResult.description;
348
356
  footer = docResult.footer;
349
357
  fragments = docResult.fragments;
350
358
  } else fragments = parsers.flatMap((p) => p.getDocFragments({ kind: "unavailable" }).fragments);
351
359
  }
352
360
  return {
361
+ brief,
353
362
  description,
354
363
  fragments,
355
364
  footer
package/dist/doc.d.cts CHANGED
@@ -60,6 +60,12 @@ type DocFragment = {
60
60
  * a final document page.
61
61
  */
62
62
  interface DocFragments {
63
+ /**
64
+ * An optional brief that provides a short summary for the collection
65
+ * of fragments.
66
+ * @since 0.7.12
67
+ */
68
+ readonly brief?: Message;
63
69
  /**
64
70
  * An optional description that applies to the entire collection of fragments.
65
71
  */
package/dist/doc.d.ts CHANGED
@@ -60,6 +60,12 @@ type DocFragment = {
60
60
  * a final document page.
61
61
  */
62
62
  interface DocFragments {
63
+ /**
64
+ * An optional brief that provides a short summary for the collection
65
+ * of fragments.
66
+ * @since 0.7.12
67
+ */
68
+ readonly brief?: Message;
63
69
  /**
64
70
  * An optional description that applies to the entire collection of fragments.
65
71
  */
package/dist/facade.cjs CHANGED
@@ -515,14 +515,59 @@ function run(parser, programName, args, options = {}) {
515
515
  else if (commandParsers.length === 2) helpGeneratorParser = require_constructs.longestMatch(commandParsers[0], commandParsers[1]);
516
516
  else helpGeneratorParser = require_constructs.longestMatch(...commandParsers);
517
517
  }
518
+ if (classified.commands.length > 0) {
519
+ let validationContext = {
520
+ buffer: [...classified.commands],
521
+ optionsTerminated: false,
522
+ state: helpGeneratorParser.initialState,
523
+ usage: helpGeneratorParser.usage
524
+ };
525
+ let commandsValid = true;
526
+ let validationError;
527
+ while (validationContext.buffer.length > 0) {
528
+ const stepResult = helpGeneratorParser.parse(validationContext);
529
+ if (!stepResult.success) {
530
+ commandsValid = false;
531
+ validationError = stepResult.error;
532
+ break;
533
+ }
534
+ if (stepResult.consumed.length < 1) {
535
+ commandsValid = false;
536
+ validationError = require_message.message`Unexpected option or subcommand: ${require_message.optionName(validationContext.buffer[0])}.`;
537
+ break;
538
+ }
539
+ validationContext = {
540
+ ...validationContext,
541
+ buffer: stepResult.next.buffer,
542
+ optionsTerminated: stepResult.next.optionsTerminated,
543
+ state: stepResult.next.state,
544
+ usage: stepResult.next.usage ?? validationContext.usage
545
+ };
546
+ }
547
+ if (!commandsValid && validationError != null) {
548
+ stderr(`Usage: ${indentLines(require_usage.formatUsage(programName, augmentedParser.usage, {
549
+ colors,
550
+ maxWidth: maxWidth == null ? void 0 : maxWidth - 7,
551
+ expandCommands: true
552
+ }), 7)}`);
553
+ const errorMessage = require_message.formatMessage(validationError, {
554
+ colors,
555
+ quotes: !colors
556
+ });
557
+ stderr(`Error: ${errorMessage}`);
558
+ return onError(1);
559
+ }
560
+ }
518
561
  const doc = require_parser.getDocPage(helpGeneratorParser, classified.commands);
519
562
  if (doc != null) {
520
563
  const isMetaCommandHelp = (completionName === "singular" || completionName === "both" ? requestedCommand === "completion" : false) || (completionName === "plural" || completionName === "both" ? requestedCommand === "completions" : false) || requestedCommand === "help" || requestedCommand === "version";
564
+ const isSubcommandHelp = classified.commands.length > 0;
565
+ const shouldOverride = !isMetaCommandHelp && !isSubcommandHelp;
521
566
  const augmentedDoc = {
522
567
  ...doc,
523
- brief: !isMetaCommandHelp ? brief ?? doc.brief : doc.brief,
524
- description: !isMetaCommandHelp ? description ?? doc.description : doc.description,
525
- footer: !isMetaCommandHelp ? footer ?? doc.footer : doc.footer
568
+ brief: shouldOverride ? brief ?? doc.brief : doc.brief ?? brief,
569
+ description: shouldOverride ? description ?? doc.description : doc.description ?? description,
570
+ footer: shouldOverride ? footer ?? doc.footer : doc.footer ?? footer
526
571
  };
527
572
  stdout(require_doc.formatDocPage(programName, augmentedDoc, {
528
573
  colors,
package/dist/facade.js CHANGED
@@ -515,14 +515,59 @@ function run(parser, programName, args, options = {}) {
515
515
  else if (commandParsers.length === 2) helpGeneratorParser = longestMatch(commandParsers[0], commandParsers[1]);
516
516
  else helpGeneratorParser = longestMatch(...commandParsers);
517
517
  }
518
+ if (classified.commands.length > 0) {
519
+ let validationContext = {
520
+ buffer: [...classified.commands],
521
+ optionsTerminated: false,
522
+ state: helpGeneratorParser.initialState,
523
+ usage: helpGeneratorParser.usage
524
+ };
525
+ let commandsValid = true;
526
+ let validationError;
527
+ while (validationContext.buffer.length > 0) {
528
+ const stepResult = helpGeneratorParser.parse(validationContext);
529
+ if (!stepResult.success) {
530
+ commandsValid = false;
531
+ validationError = stepResult.error;
532
+ break;
533
+ }
534
+ if (stepResult.consumed.length < 1) {
535
+ commandsValid = false;
536
+ validationError = message`Unexpected option or subcommand: ${optionName(validationContext.buffer[0])}.`;
537
+ break;
538
+ }
539
+ validationContext = {
540
+ ...validationContext,
541
+ buffer: stepResult.next.buffer,
542
+ optionsTerminated: stepResult.next.optionsTerminated,
543
+ state: stepResult.next.state,
544
+ usage: stepResult.next.usage ?? validationContext.usage
545
+ };
546
+ }
547
+ if (!commandsValid && validationError != null) {
548
+ stderr(`Usage: ${indentLines(formatUsage(programName, augmentedParser.usage, {
549
+ colors,
550
+ maxWidth: maxWidth == null ? void 0 : maxWidth - 7,
551
+ expandCommands: true
552
+ }), 7)}`);
553
+ const errorMessage = formatMessage(validationError, {
554
+ colors,
555
+ quotes: !colors
556
+ });
557
+ stderr(`Error: ${errorMessage}`);
558
+ return onError(1);
559
+ }
560
+ }
518
561
  const doc = getDocPage(helpGeneratorParser, classified.commands);
519
562
  if (doc != null) {
520
563
  const isMetaCommandHelp = (completionName === "singular" || completionName === "both" ? requestedCommand === "completion" : false) || (completionName === "plural" || completionName === "both" ? requestedCommand === "completions" : false) || requestedCommand === "help" || requestedCommand === "version";
564
+ const isSubcommandHelp = classified.commands.length > 0;
565
+ const shouldOverride = !isMetaCommandHelp && !isSubcommandHelp;
521
566
  const augmentedDoc = {
522
567
  ...doc,
523
- brief: !isMetaCommandHelp ? brief ?? doc.brief : doc.brief,
524
- description: !isMetaCommandHelp ? description ?? doc.description : doc.description,
525
- footer: !isMetaCommandHelp ? footer ?? doc.footer : doc.footer
568
+ brief: shouldOverride ? brief ?? doc.brief : doc.brief ?? brief,
569
+ description: shouldOverride ? description ?? doc.description : doc.description ?? description,
570
+ footer: shouldOverride ? footer ?? doc.footer : doc.footer ?? footer
526
571
  };
527
572
  stdout(formatDocPage(programName, augmentedDoc, {
528
573
  colors,
package/dist/parser.cjs CHANGED
@@ -159,7 +159,7 @@ function getDocPage(parser, args = []) {
159
159
  if (!result.success) break;
160
160
  context = result.next;
161
161
  } while (context.buffer.length > 0);
162
- const { description, fragments, footer } = parser.getDocFragments({
162
+ const { brief, description, fragments, footer } = parser.getDocFragments({
163
163
  kind: "available",
164
164
  state: context.state
165
165
  }, void 0);
@@ -185,6 +185,7 @@ function getDocPage(parser, args = []) {
185
185
  return {
186
186
  usage,
187
187
  sections,
188
+ ...brief != null && { brief },
188
189
  ...description != null && { description },
189
190
  ...footer != null && { footer }
190
191
  };
package/dist/parser.js CHANGED
@@ -159,7 +159,7 @@ function getDocPage(parser, args = []) {
159
159
  if (!result.success) break;
160
160
  context = result.next;
161
161
  } while (context.buffer.length > 0);
162
- const { description, fragments, footer } = parser.getDocFragments({
162
+ const { brief, description, fragments, footer } = parser.getDocFragments({
163
163
  kind: "available",
164
164
  state: context.state
165
165
  }, void 0);
@@ -185,6 +185,7 @@ function getDocPage(parser, args = []) {
185
185
  return {
186
186
  usage,
187
187
  sections,
188
+ ...brief != null && { brief },
188
189
  ...description != null && { description },
189
190
  ...footer != null && { footer }
190
191
  };
@@ -725,6 +725,7 @@ function command(name, parser, options = {}) {
725
725
  const innerFragments = parser.getDocFragments(innerState, defaultValue);
726
726
  return {
727
727
  ...innerFragments,
728
+ brief: innerFragments.brief ?? options.brief,
728
729
  description: innerFragments.description ?? options.description,
729
730
  footer: innerFragments.footer ?? options.footer
730
731
  };
@@ -725,6 +725,7 @@ function command(name, parser, options = {}) {
725
725
  const innerFragments = parser.getDocFragments(innerState, defaultValue);
726
726
  return {
727
727
  ...innerFragments,
728
+ brief: innerFragments.brief ?? options.brief,
728
729
  description: innerFragments.description ?? options.description,
729
730
  footer: innerFragments.footer ?? options.footer
730
731
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.8.9-dev.349+356beecf",
3
+ "version": "0.8.10",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",