@optique/core 1.0.0-dev.395 → 1.0.0-dev.401

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.
package/dist/doc.cjs CHANGED
@@ -3,6 +3,28 @@ const require_usage = require('./usage.cjs');
3
3
 
4
4
  //#region src/doc.ts
5
5
  /**
6
+ * Classifies a {@link DocSection} by its content type for use in the
7
+ * default smart sort.
8
+ *
9
+ * @returns `0` for command-only sections, `1` for mixed sections, `2` for
10
+ * option/argument/passthrough-only sections.
11
+ */
12
+ function classifySection(section) {
13
+ const hasCommand = section.entries.some((e) => e.term.type === "command");
14
+ const hasNonCommand = section.entries.some((e) => e.term.type !== "command");
15
+ if (hasCommand && !hasNonCommand) return 0;
16
+ if (hasCommand && hasNonCommand) return 1;
17
+ return 2;
18
+ }
19
+ /**
20
+ * The default section comparator: command-only sections come first, then
21
+ * mixed sections, then option/argument-only sections. Sections with the
22
+ * same score preserve their original relative order (stable sort).
23
+ */
24
+ function defaultSectionOrder(a, b) {
25
+ return classifySection(a) - classifySection(b);
26
+ }
27
+ /**
6
28
  * Formats a documentation page into a human-readable string.
7
29
  *
8
30
  * This function takes a structured {@link DocPage} and converts it into
@@ -64,7 +86,16 @@ function formatDocPage(programName, page, options = {}) {
64
86
  });
65
87
  output += "\n";
66
88
  }
67
- const sections = page.sections.toSorted((a, b) => a.title == null && b.title == null ? 0 : a.title == null ? -1 : 1);
89
+ const comparator = options.sectionOrder ?? defaultSectionOrder;
90
+ const sections = page.sections.map((s, i) => ({
91
+ section: s,
92
+ index: i
93
+ })).toSorted((a, b) => {
94
+ const cmp = comparator(a.section, b.section);
95
+ if (cmp !== 0) return cmp;
96
+ const titleCmp = (a.section.title == null ? 0 : 1) - (b.section.title == null ? 0 : 1);
97
+ return titleCmp !== 0 ? titleCmp : a.index - b.index;
98
+ }).map(({ section }) => section);
68
99
  for (const section of sections) {
69
100
  if (section.entries.length < 1) continue;
70
101
  output += "\n";
package/dist/doc.d.cts CHANGED
@@ -228,6 +228,28 @@ interface DocPageFormatOptions {
228
228
  * ```
229
229
  */
230
230
  showChoices?: boolean | ShowChoicesOptions;
231
+ /**
232
+ * A custom comparator function to control the order of sections in the
233
+ * help output. When provided, it is used instead of the default smart
234
+ * sort (command-only sections first, then mixed, then option/argument-only
235
+ * sections). Sections that compare equal (return `0`) preserve their
236
+ * original relative order (stable sort).
237
+ *
238
+ * @param a The first section to compare.
239
+ * @param b The second section to compare.
240
+ * @returns A negative number if `a` should appear before `b`, a positive
241
+ * number if `a` should appear after `b`, or `0` if they are equal.
242
+ * @since 1.0.0
243
+ *
244
+ * @example
245
+ * ```typescript
246
+ * // Sort sections alphabetically by title
247
+ * {
248
+ * sectionOrder: (a, b) => (a.title ?? "").localeCompare(b.title ?? "")
249
+ * }
250
+ * ```
251
+ */
252
+ sectionOrder?: (a: DocSection, b: DocSection) => number;
231
253
  }
232
254
  /**
233
255
  * Formats a documentation page into a human-readable string.
package/dist/doc.d.ts CHANGED
@@ -228,6 +228,28 @@ interface DocPageFormatOptions {
228
228
  * ```
229
229
  */
230
230
  showChoices?: boolean | ShowChoicesOptions;
231
+ /**
232
+ * A custom comparator function to control the order of sections in the
233
+ * help output. When provided, it is used instead of the default smart
234
+ * sort (command-only sections first, then mixed, then option/argument-only
235
+ * sections). Sections that compare equal (return `0`) preserve their
236
+ * original relative order (stable sort).
237
+ *
238
+ * @param a The first section to compare.
239
+ * @param b The second section to compare.
240
+ * @returns A negative number if `a` should appear before `b`, a positive
241
+ * number if `a` should appear after `b`, or `0` if they are equal.
242
+ * @since 1.0.0
243
+ *
244
+ * @example
245
+ * ```typescript
246
+ * // Sort sections alphabetically by title
247
+ * {
248
+ * sectionOrder: (a, b) => (a.title ?? "").localeCompare(b.title ?? "")
249
+ * }
250
+ * ```
251
+ */
252
+ sectionOrder?: (a: DocSection, b: DocSection) => number;
231
253
  }
232
254
  /**
233
255
  * Formats a documentation page into a human-readable string.
package/dist/doc.js CHANGED
@@ -3,6 +3,28 @@ import { formatUsage, formatUsageTerm } from "./usage.js";
3
3
 
4
4
  //#region src/doc.ts
5
5
  /**
6
+ * Classifies a {@link DocSection} by its content type for use in the
7
+ * default smart sort.
8
+ *
9
+ * @returns `0` for command-only sections, `1` for mixed sections, `2` for
10
+ * option/argument/passthrough-only sections.
11
+ */
12
+ function classifySection(section) {
13
+ const hasCommand = section.entries.some((e) => e.term.type === "command");
14
+ const hasNonCommand = section.entries.some((e) => e.term.type !== "command");
15
+ if (hasCommand && !hasNonCommand) return 0;
16
+ if (hasCommand && hasNonCommand) return 1;
17
+ return 2;
18
+ }
19
+ /**
20
+ * The default section comparator: command-only sections come first, then
21
+ * mixed sections, then option/argument-only sections. Sections with the
22
+ * same score preserve their original relative order (stable sort).
23
+ */
24
+ function defaultSectionOrder(a, b) {
25
+ return classifySection(a) - classifySection(b);
26
+ }
27
+ /**
6
28
  * Formats a documentation page into a human-readable string.
7
29
  *
8
30
  * This function takes a structured {@link DocPage} and converts it into
@@ -64,7 +86,16 @@ function formatDocPage(programName, page, options = {}) {
64
86
  });
65
87
  output += "\n";
66
88
  }
67
- const sections = page.sections.toSorted((a, b) => a.title == null && b.title == null ? 0 : a.title == null ? -1 : 1);
89
+ const comparator = options.sectionOrder ?? defaultSectionOrder;
90
+ const sections = page.sections.map((s, i) => ({
91
+ section: s,
92
+ index: i
93
+ })).toSorted((a, b) => {
94
+ const cmp = comparator(a.section, b.section);
95
+ if (cmp !== 0) return cmp;
96
+ const titleCmp = (a.section.title == null ? 0 : 1) - (b.section.title == null ? 0 : 1);
97
+ return titleCmp !== 0 ? titleCmp : a.index - b.index;
98
+ }).map(({ section }) => section);
68
99
  for (const section of sections) {
69
100
  if (section.entries.length < 1) continue;
70
101
  output += "\n";
package/dist/facade.cjs CHANGED
@@ -369,7 +369,7 @@ function classifyResult(result, args) {
369
369
  * Handles shell completion requests.
370
370
  * @since 0.6.0
371
371
  */
372
- function handleCompletion(completionArgs, programName, parser, completionParser, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName) {
372
+ function handleCompletion(completionArgs, programName, parser, completionParser, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName, sectionOrder) {
373
373
  const shellName = completionArgs[0] || "";
374
374
  const args = completionArgs.slice(1);
375
375
  const callOnError = (code) => {
@@ -392,7 +392,8 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
392
392
  const doc = require_parser.getDocPage(completionParser, ["completion"]);
393
393
  if (doc) stderr(require_doc.formatDocPage(programName, doc, {
394
394
  colors,
395
- maxWidth
395
+ maxWidth,
396
+ sectionOrder
396
397
  }));
397
398
  }
398
399
  if (parser.$mode === "async") return Promise.resolve(callOnError(1));
@@ -457,7 +458,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
457
458
  args = argsOrOptions;
458
459
  options = optionsParam ?? {};
459
460
  }
460
- const { colors, maxWidth, showDefault, showChoices, aboveError = "usage", onError = () => {
461
+ const { colors, maxWidth, showDefault, showChoices, sectionOrder, aboveError = "usage", onError = () => {
461
462
  throw new RunParserError("Failed to parse command line arguments.");
462
463
  }, stderr = console.error, stdout = console.log, brief, description, examples, author, bugs, footer } = options;
463
464
  const helpMode = options.help?.mode ?? "option";
@@ -500,7 +501,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
500
501
  } : createCompletionParser(completion, programName, availableShells, completionName, completionHelpVisibility);
501
502
  if (options.completion) {
502
503
  const hasHelpOption = args.includes("--help");
503
- if ((completionMode === "command" || completionMode === "both") && args.length >= 1 && ((completionName === "singular" || completionName === "both" ? args[0] === "completion" : false) || (completionName === "plural" || completionName === "both" ? args[0] === "completions" : false)) && !hasHelpOption) return handleCompletion(args.slice(1), programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName);
504
+ if ((completionMode === "command" || completionMode === "both") && args.length >= 1 && ((completionName === "singular" || completionName === "both" ? args[0] === "completion" : false) || (completionName === "plural" || completionName === "both" ? args[0] === "completions" : false)) && !hasHelpOption) return handleCompletion(args.slice(1), programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName, sectionOrder);
504
505
  if (completionMode === "option" || completionMode === "both") for (let i = 0; i < args.length; i++) {
505
506
  const arg = args[i];
506
507
  const singularMatch = completionName === "singular" || completionName === "both" ? arg.startsWith("--completion=") : false;
@@ -508,14 +509,14 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
508
509
  if (singularMatch || pluralMatch) {
509
510
  const shell = arg.slice(arg.indexOf("=") + 1);
510
511
  const completionArgs = args.slice(i + 1);
511
- return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName);
512
+ return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName, sectionOrder);
512
513
  } else {
513
514
  const singularMatchExact = completionName === "singular" || completionName === "both" ? arg === "--completion" : false;
514
515
  const pluralMatchExact = completionName === "plural" || completionName === "both" ? arg === "--completions" : false;
515
516
  if (singularMatchExact || pluralMatchExact) {
516
517
  const shell = i + 1 < args.length ? args[i + 1] : "";
517
518
  const completionArgs = i + 1 < args.length ? args.slice(i + 2) : [];
518
- return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName);
519
+ return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName, sectionOrder);
519
520
  }
520
521
  }
521
522
  }
@@ -636,7 +637,8 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
636
637
  colors,
637
638
  maxWidth,
638
639
  showDefault,
639
- showChoices
640
+ showChoices,
641
+ sectionOrder
640
642
  }));
641
643
  }
642
644
  try {
package/dist/facade.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Message } from "./message.cjs";
2
- import { ShowChoicesOptions, ShowDefaultOptions } from "./doc.cjs";
2
+ import { DocSection, ShowChoicesOptions, ShowDefaultOptions } from "./doc.cjs";
3
3
  import { InferMode, InferValue, Mode, ModeValue, Parser } from "./parser.cjs";
4
4
  import { ShellCompletion } from "./completion.cjs";
5
5
  import { ParserValuePlaceholder, SourceContext } from "./context.cjs";
@@ -148,6 +148,20 @@ interface RunOptions<THelp, TError> {
148
148
  * @since 0.10.0
149
149
  */
150
150
  readonly showChoices?: boolean | ShowChoicesOptions;
151
+ /**
152
+ * A custom comparator function to control the order of sections in the
153
+ * help output. When provided, it is used instead of the default smart
154
+ * sort (command-only sections first, then mixed, then option/argument-only
155
+ * sections). Sections that compare equal (return `0`) preserve their
156
+ * original relative order.
157
+ *
158
+ * @param a The first section to compare.
159
+ * @param b The second section to compare.
160
+ * @returns A negative number if `a` should appear before `b`, a positive
161
+ * number if `a` should appear after `b`, or `0` if they are equal.
162
+ * @since 1.0.0
163
+ */
164
+ readonly sectionOrder?: (a: DocSection, b: DocSection) => number;
151
165
  /**
152
166
  * Help configuration. When provided, enables help functionality.
153
167
  */
package/dist/facade.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Message } from "./message.js";
2
- import { ShowChoicesOptions, ShowDefaultOptions } from "./doc.js";
2
+ import { DocSection, ShowChoicesOptions, ShowDefaultOptions } from "./doc.js";
3
3
  import { InferMode, InferValue, Mode, ModeValue, Parser } from "./parser.js";
4
4
  import { ShellCompletion } from "./completion.js";
5
5
  import { ParserValuePlaceholder, SourceContext } from "./context.js";
@@ -148,6 +148,20 @@ interface RunOptions<THelp, TError> {
148
148
  * @since 0.10.0
149
149
  */
150
150
  readonly showChoices?: boolean | ShowChoicesOptions;
151
+ /**
152
+ * A custom comparator function to control the order of sections in the
153
+ * help output. When provided, it is used instead of the default smart
154
+ * sort (command-only sections first, then mixed, then option/argument-only
155
+ * sections). Sections that compare equal (return `0`) preserve their
156
+ * original relative order.
157
+ *
158
+ * @param a The first section to compare.
159
+ * @param b The second section to compare.
160
+ * @returns A negative number if `a` should appear before `b`, a positive
161
+ * number if `a` should appear after `b`, or `0` if they are equal.
162
+ * @since 1.0.0
163
+ */
164
+ readonly sectionOrder?: (a: DocSection, b: DocSection) => number;
151
165
  /**
152
166
  * Help configuration. When provided, enables help functionality.
153
167
  */
package/dist/facade.js CHANGED
@@ -369,7 +369,7 @@ function classifyResult(result, args) {
369
369
  * Handles shell completion requests.
370
370
  * @since 0.6.0
371
371
  */
372
- function handleCompletion(completionArgs, programName, parser, completionParser, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName) {
372
+ function handleCompletion(completionArgs, programName, parser, completionParser, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName, sectionOrder) {
373
373
  const shellName = completionArgs[0] || "";
374
374
  const args = completionArgs.slice(1);
375
375
  const callOnError = (code) => {
@@ -392,7 +392,8 @@ function handleCompletion(completionArgs, programName, parser, completionParser,
392
392
  const doc = getDocPage(completionParser, ["completion"]);
393
393
  if (doc) stderr(formatDocPage(programName, doc, {
394
394
  colors,
395
- maxWidth
395
+ maxWidth,
396
+ sectionOrder
396
397
  }));
397
398
  }
398
399
  if (parser.$mode === "async") return Promise.resolve(callOnError(1));
@@ -457,7 +458,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
457
458
  args = argsOrOptions;
458
459
  options = optionsParam ?? {};
459
460
  }
460
- const { colors, maxWidth, showDefault, showChoices, aboveError = "usage", onError = () => {
461
+ const { colors, maxWidth, showDefault, showChoices, sectionOrder, aboveError = "usage", onError = () => {
461
462
  throw new RunParserError("Failed to parse command line arguments.");
462
463
  }, stderr = console.error, stdout = console.log, brief, description, examples, author, bugs, footer } = options;
463
464
  const helpMode = options.help?.mode ?? "option";
@@ -500,7 +501,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
500
501
  } : createCompletionParser(completion, programName, availableShells, completionName, completionHelpVisibility);
501
502
  if (options.completion) {
502
503
  const hasHelpOption = args.includes("--help");
503
- if ((completionMode === "command" || completionMode === "both") && args.length >= 1 && ((completionName === "singular" || completionName === "both" ? args[0] === "completion" : false) || (completionName === "plural" || completionName === "both" ? args[0] === "completions" : false)) && !hasHelpOption) return handleCompletion(args.slice(1), programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName);
504
+ if ((completionMode === "command" || completionMode === "both") && args.length >= 1 && ((completionName === "singular" || completionName === "both" ? args[0] === "completion" : false) || (completionName === "plural" || completionName === "both" ? args[0] === "completions" : false)) && !hasHelpOption) return handleCompletion(args.slice(1), programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName, sectionOrder);
504
505
  if (completionMode === "option" || completionMode === "both") for (let i = 0; i < args.length; i++) {
505
506
  const arg = args[i];
506
507
  const singularMatch = completionName === "singular" || completionName === "both" ? arg.startsWith("--completion=") : false;
@@ -508,14 +509,14 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
508
509
  if (singularMatch || pluralMatch) {
509
510
  const shell = arg.slice(arg.indexOf("=") + 1);
510
511
  const completionArgs = args.slice(i + 1);
511
- return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName);
512
+ return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName, sectionOrder);
512
513
  } else {
513
514
  const singularMatchExact = completionName === "singular" || completionName === "both" ? arg === "--completion" : false;
514
515
  const pluralMatchExact = completionName === "plural" || completionName === "both" ? arg === "--completions" : false;
515
516
  if (singularMatchExact || pluralMatchExact) {
516
517
  const shell = i + 1 < args.length ? args[i + 1] : "";
517
518
  const completionArgs = i + 1 < args.length ? args.slice(i + 2) : [];
518
- return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName);
519
+ return handleCompletion([shell, ...completionArgs], programName, parser, completionParsers.completionCommand, stdout, stderr, onCompletion, onError, availableShells, colors, maxWidth, completionMode, completionName, sectionOrder);
519
520
  }
520
521
  }
521
522
  }
@@ -636,7 +637,8 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
636
637
  colors,
637
638
  maxWidth,
638
639
  showDefault,
639
- showChoices
640
+ showChoices,
641
+ sectionOrder
640
642
  }));
641
643
  }
642
644
  try {
package/dist/index.cjs CHANGED
@@ -47,6 +47,7 @@ exports.envVar = require_message.envVar;
47
47
  exports.extractArgumentMetavars = require_usage.extractArgumentMetavars;
48
48
  exports.extractCommandNames = require_usage.extractCommandNames;
49
49
  exports.extractOptionNames = require_usage.extractOptionNames;
50
+ exports.fail = require_primitives.fail;
50
51
  exports.fish = require_completion.fish;
51
52
  exports.flag = require_primitives.flag;
52
53
  exports.float = require_valueparser.float;
package/dist/index.d.cts CHANGED
@@ -7,9 +7,9 @@ import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsStr
7
7
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.cjs";
8
8
  import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.cjs";
9
9
  import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, PendingDependencySourceState, ResolvedDependency, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, getDefaultValuesFunction, getDependencyIds, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } from "./dependency.cjs";
10
- import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough } from "./primitives.cjs";
10
+ import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, option, passThrough } from "./primitives.cjs";
11
11
  import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, ModeValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.cjs";
12
12
  import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.cjs";
13
13
  import { ParserValuePlaceholder, SourceContext } from "./context.cjs";
14
14
  import { CompletionHelpVisibility, CompletionName, ExtractRequiredOptions, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.cjs";
15
- export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CompletionHelpVisibility, CompletionName, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
15
+ export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CompletionHelpVisibility, CompletionName, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
package/dist/index.d.ts CHANGED
@@ -7,9 +7,9 @@ import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsStr
7
7
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
8
8
  import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
9
9
  import { AnyDependencySource, CombineMode, CombinedDependencyMode, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, PendingDependencySourceState, ResolvedDependency, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, formatDependencyError, getDefaultValuesFunction, getDependencyIds, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, isWrappedDependencySource, parseWithDependency, pendingDependencySourceStateMarker, suggestWithDependency, transformsDependencyValue, transformsDependencyValueMarker, wrappedDependencySourceMarker } from "./dependency.js";
10
- import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough } from "./primitives.js";
10
+ import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, option, passThrough } from "./primitives.js";
11
11
  import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, ModeValue, Parser, ParserContext, ParserResult, Result, Suggestion, getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
12
12
  import { ShellCompletion, bash, fish, nu, pwsh, zsh } from "./completion.js";
13
13
  import { ParserValuePlaceholder, SourceContext } from "./context.js";
14
14
  import { CompletionHelpVisibility, CompletionName, ExtractRequiredOptions, RunOptions, RunParserError, RunWithOptions, SubstituteParserValue, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
15
- export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CompletionHelpVisibility, CompletionName, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
15
+ export { type Annotations, AnyDependencySource, ArgumentErrorOptions, ArgumentOptions, ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, CombineMode, CombineModes, CombinedDependencyMode, CommandErrorOptions, CommandOptions, CompletionHelpVisibility, CompletionName, ConditionalErrorOptions, ConditionalOptions, DeferredParseState, DependencyError, DependencyMode, DependencyRegistry, DependencySource, DependencySourceState, DependencyValue, DependencyValues, DeriveAsyncOptions, DeriveFromAsyncOptions, DeriveFromOptions, DeriveFromSyncOptions, DeriveOptions, DeriveSyncOptions, DerivedValueParser, DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, DocState, DomainOptions, DuplicateOptionError, EmailOptions, ExtractRequiredOptions, FlagErrorOptions, FlagOptions, FloatOptions, HostnameOptions, InferMode, InferValue, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, LongestMatchErrorOptions, LongestMatchOptions, MacAddressOptions, MergeOptions, type Message, type MessageFormatOptions, type MessageTerm, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, NonEmptyString, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionName, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, ParserValuePlaceholder, PassThroughFormat, PassThroughOptions, PendingDependencySourceState, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, ResolvedDependency, Result, RunOptions, RunParserError, RunWithOptions, ShellCompletion, ShowChoicesOptions, ShowDefaultOptions, SocketAddressOptions, SocketAddressValue, SourceContext, StringOptions, SubstituteParserValue, Suggestion, TupleOptions, UrlOptions, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, type ValueSetOptions, WithDefaultError, WithDefaultOptions, annotationKey, argument, bash, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
package/dist/index.js CHANGED
@@ -8,8 +8,8 @@ import { formatDocPage } from "./doc.js";
8
8
  import { WithDefaultError, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
9
9
  import { ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
10
10
  import { choice, cidr, domain, email, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } from "./valueparser.js";
11
- import { argument, command, constant, flag, option, passThrough } from "./primitives.js";
11
+ import { argument, command, constant, fail, flag, option, passThrough } from "./primitives.js";
12
12
  import { getDocPage, getDocPageAsync, getDocPageSync, parse, parseAsync, parseSync, suggest, suggestAsync, suggestSync } from "./parser.js";
13
13
  import { RunParserError, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync } from "./facade.js";
14
14
 
15
- export { DependencyRegistry, DuplicateOptionError, RunParserError, WithDefaultError, annotationKey, argument, bash, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
15
+ export { DependencyRegistry, DuplicateOptionError, RunParserError, WithDefaultError, annotationKey, argument, bash, choice, cidr, command, commandLine, concat, conditional, constant, createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, defaultValues, deferredParseMarker, dependency, dependencyId, dependencyIds, dependencySourceMarker, dependencySourceStateMarker, deriveFrom, deriveFromAsync, deriveFromSync, derivedValueParserMarker, domain, email, ensureNonEmptyString, envVar, extractArgumentMetavars, extractCommandNames, extractOptionNames, fail, fish, flag, float, formatDependencyError, formatDocPage, formatMessage, formatUsage, formatUsageTerm, getAnnotations, getDefaultValuesFunction, getDependencyIds, getDocPage, getDocPageAsync, getDocPageSync, group, hostname, integer, ip, ipv4, ipv6, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isNonEmptyString, isPendingDependencySourceState, isValueParser, isWrappedDependencySource, lineBreak, link, locale, longestMatch, macAddress, map, merge, message, metavar, multiple, nonEmpty, normalizeUsage, nu, object, option, optionName, optionNames, optional, or, parse, parseAsync, parseSync, parseWithDependency, passThrough, pendingDependencySourceStateMarker, port, portRange, pwsh, runParser, runParserAsync, runParserSync, runWith, runWithAsync, runWithSync, socketAddress, string, suggest, suggestAsync, suggestSync, suggestWithDependency, text, transformsDependencyValue, transformsDependencyValueMarker, tuple, url, uuid, value, valueSet, values, withDefault, wrappedDependencySourceMarker, zsh };
package/dist/parser.cjs CHANGED
@@ -424,6 +424,7 @@ exports.command = require_primitives.command;
424
424
  exports.concat = require_constructs.concat;
425
425
  exports.conditional = require_constructs.conditional;
426
426
  exports.constant = require_primitives.constant;
427
+ exports.fail = require_primitives.fail;
427
428
  exports.flag = require_primitives.flag;
428
429
  exports.getDocPage = getDocPage;
429
430
  exports.getDocPageAsync = getDocPageAsync;
package/dist/parser.d.cts CHANGED
@@ -6,7 +6,7 @@ import { DependencyRegistryLike } from "./registry-types.cjs";
6
6
  import { ValueParserResult } from "./valueparser.cjs";
7
7
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.cjs";
8
8
  import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.cjs";
9
- import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough } from "./primitives.cjs";
9
+ import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, option, passThrough } from "./primitives.cjs";
10
10
 
11
11
  //#region src/parser.d.ts
12
12
 
@@ -534,4 +534,4 @@ declare function getDocPage(parser: Parser<"sync", unknown, unknown>, args?: rea
534
534
  declare function getDocPage(parser: Parser<"async", unknown, unknown>, args?: readonly string[], options?: ParseOptions): Promise<DocPage | undefined>;
535
535
  declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>, args?: readonly string[], options?: ParseOptions): ModeValue<M, DocPage | undefined>;
536
536
  //#endregion
537
- export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
537
+ export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, fail, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
package/dist/parser.d.ts CHANGED
@@ -6,7 +6,7 @@ import { DependencyRegistryLike } from "./registry-types.js";
6
6
  import { ValueParserResult } from "./valueparser.js";
7
7
  import { ConditionalErrorOptions, ConditionalOptions, DuplicateOptionError, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OrErrorOptions, OrOptions, TupleOptions, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
8
8
  import { MultipleErrorOptions, MultipleOptions, WithDefaultError, WithDefaultOptions, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
9
- import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough } from "./primitives.js";
9
+ import { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, option, passThrough } from "./primitives.js";
10
10
 
11
11
  //#region src/parser.d.ts
12
12
 
@@ -534,4 +534,4 @@ declare function getDocPage(parser: Parser<"sync", unknown, unknown>, args?: rea
534
534
  declare function getDocPage(parser: Parser<"async", unknown, unknown>, args?: readonly string[], options?: ParseOptions): Promise<DocPage | undefined>;
535
535
  declare function getDocPage<M extends Mode>(parser: Parser<M, unknown, unknown>, args?: readonly string[], options?: ParseOptions): ModeValue<M, DocPage | undefined>;
536
536
  //#endregion
537
- export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
537
+ export { ArgumentErrorOptions, ArgumentOptions, CombineModes, CommandErrorOptions, CommandOptions, ConditionalErrorOptions, ConditionalOptions, DocState, DuplicateOptionError, FlagErrorOptions, FlagOptions, InferMode, InferValue, LongestMatchErrorOptions, LongestMatchOptions, MergeOptions, Mode, ModeIterable, ModeValue, MultipleErrorOptions, MultipleOptions, NoMatchContext, ObjectErrorOptions, ObjectOptions, OptionErrorOptions, OptionOptions, OptionState, OrErrorOptions, OrOptions, type ParseOptions, Parser, ParserContext, ParserResult, PassThroughFormat, PassThroughOptions, Result, Suggestion, TupleOptions, WithDefaultError, WithDefaultOptions, argument, command, concat, conditional, constant, fail, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
package/dist/parser.js CHANGED
@@ -3,7 +3,7 @@ import { message } from "./message.js";
3
3
  import { normalizeUsage } from "./usage.js";
4
4
  import { DuplicateOptionError, concat, conditional, group, longestMatch, merge, object, or, tuple } from "./constructs.js";
5
5
  import { WithDefaultError, map, multiple, nonEmpty, optional, withDefault } from "./modifiers.js";
6
- import { argument, command, constant, flag, option, passThrough } from "./primitives.js";
6
+ import { argument, command, constant, fail, flag, option, passThrough } from "./primitives.js";
7
7
 
8
8
  //#region src/parser.ts
9
9
  /**
@@ -417,4 +417,4 @@ function buildDocPage(parser, context, args) {
417
417
  }
418
418
 
419
419
  //#endregion
420
- export { DuplicateOptionError, WithDefaultError, argument, command, concat, conditional, constant, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
420
+ export { DuplicateOptionError, WithDefaultError, argument, command, concat, conditional, constant, fail, flag, getDocPage, getDocPageAsync, getDocPageSync, group, longestMatch, map, merge, multiple, nonEmpty, object, option, optional, or, parse, parseAsync, parseSync, passThrough, suggest, suggestAsync, suggestSync, tuple, withDefault };
@@ -53,6 +53,54 @@ function constant(value) {
53
53
  };
54
54
  }
55
55
  /**
56
+ * Creates a parser that always fails without consuming any input.
57
+ *
58
+ * This is the counterpart to {@link constant}: while `constant(value)` always
59
+ * succeeds, `fail<T>()` always fails. At the type level it is declared to
60
+ * produce a value of type `T`, so it composes seamlessly with other parsers
61
+ * that expect `Parser<"sync", T, …>`.
62
+ *
63
+ * The primary use case is as the inner parser for
64
+ * `bindConfig(fail<T>(), { … })` when a value should *only* come from a
65
+ * config file and has no corresponding CLI flag or argument. Because `fail()`
66
+ * always fails, `bindConfig` will always fall back to the config file (or the
67
+ * supplied default).
68
+ *
69
+ * @template T The type of value this parser is declared to produce.
70
+ * @returns A {@link Parser} that always fails at parse time and always fails at
71
+ * complete time.
72
+ * @since 1.0.0
73
+ */
74
+ function fail() {
75
+ return {
76
+ $valueType: [],
77
+ $stateType: [],
78
+ $mode: "sync",
79
+ priority: 0,
80
+ usage: [],
81
+ initialState: void 0,
82
+ parse(_context) {
83
+ return {
84
+ success: false,
85
+ consumed: 0,
86
+ error: require_message.message`No value provided.`
87
+ };
88
+ },
89
+ complete(_state) {
90
+ return {
91
+ success: false,
92
+ error: require_message.message`No value provided.`
93
+ };
94
+ },
95
+ suggest(_context, _prefix) {
96
+ return [];
97
+ },
98
+ getDocFragments(_state, _defaultValue) {
99
+ return { fragments: [] };
100
+ }
101
+ };
102
+ }
103
+ /**
56
104
  * Internal helper to get suggestions from a value parser, using dependency values
57
105
  * if the parser is a derived parser and dependency values are available.
58
106
  * @internal
@@ -1185,6 +1233,7 @@ function passThrough(options = {}) {
1185
1233
  exports.argument = argument;
1186
1234
  exports.command = command;
1187
1235
  exports.constant = constant;
1236
+ exports.fail = fail;
1188
1237
  exports.flag = flag;
1189
1238
  exports.option = option;
1190
1239
  exports.passThrough = passThrough;
@@ -18,6 +18,26 @@ type OptionState<T> = ValueParserResult<T> | DeferredParseState<T> | PendingDepe
18
18
  * @template T The type of the constant value produced by the parser.
19
19
  */
20
20
  declare function constant<const T>(value: T): Parser<"sync", T, T>;
21
+ /**
22
+ * Creates a parser that always fails without consuming any input.
23
+ *
24
+ * This is the counterpart to {@link constant}: while `constant(value)` always
25
+ * succeeds, `fail<T>()` always fails. At the type level it is declared to
26
+ * produce a value of type `T`, so it composes seamlessly with other parsers
27
+ * that expect `Parser<"sync", T, …>`.
28
+ *
29
+ * The primary use case is as the inner parser for
30
+ * `bindConfig(fail<T>(), { … })` when a value should *only* come from a
31
+ * config file and has no corresponding CLI flag or argument. Because `fail()`
32
+ * always fails, `bindConfig` will always fall back to the config file (or the
33
+ * supplied default).
34
+ *
35
+ * @template T The type of value this parser is declared to produce.
36
+ * @returns A {@link Parser} that always fails at parse time and always fails at
37
+ * complete time.
38
+ * @since 1.0.0
39
+ */
40
+ declare function fail<T>(): Parser<"sync", T, undefined>;
21
41
  /**
22
42
  * Options for the {@link option} parser.
23
43
  */
@@ -430,4 +450,4 @@ interface PassThroughOptions {
430
450
  */
431
451
  declare function passThrough(options?: PassThroughOptions): Parser<"sync", readonly string[], readonly string[]>;
432
452
  //#endregion
433
- export { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough };
453
+ export { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, option, passThrough };
@@ -18,6 +18,26 @@ type OptionState<T> = ValueParserResult<T> | DeferredParseState<T> | PendingDepe
18
18
  * @template T The type of the constant value produced by the parser.
19
19
  */
20
20
  declare function constant<const T>(value: T): Parser<"sync", T, T>;
21
+ /**
22
+ * Creates a parser that always fails without consuming any input.
23
+ *
24
+ * This is the counterpart to {@link constant}: while `constant(value)` always
25
+ * succeeds, `fail<T>()` always fails. At the type level it is declared to
26
+ * produce a value of type `T`, so it composes seamlessly with other parsers
27
+ * that expect `Parser<"sync", T, …>`.
28
+ *
29
+ * The primary use case is as the inner parser for
30
+ * `bindConfig(fail<T>(), { … })` when a value should *only* come from a
31
+ * config file and has no corresponding CLI flag or argument. Because `fail()`
32
+ * always fails, `bindConfig` will always fall back to the config file (or the
33
+ * supplied default).
34
+ *
35
+ * @template T The type of value this parser is declared to produce.
36
+ * @returns A {@link Parser} that always fails at parse time and always fails at
37
+ * complete time.
38
+ * @since 1.0.0
39
+ */
40
+ declare function fail<T>(): Parser<"sync", T, undefined>;
21
41
  /**
22
42
  * Options for the {@link option} parser.
23
43
  */
@@ -430,4 +450,4 @@ interface PassThroughOptions {
430
450
  */
431
451
  declare function passThrough(options?: PassThroughOptions): Parser<"sync", readonly string[], readonly string[]>;
432
452
  //#endregion
433
- export { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, flag, option, passThrough };
453
+ export { ArgumentErrorOptions, ArgumentOptions, CommandErrorOptions, CommandOptions, FlagErrorOptions, FlagOptions, OptionErrorOptions, OptionOptions, OptionState, PassThroughFormat, PassThroughOptions, argument, command, constant, fail, flag, option, passThrough };
@@ -53,6 +53,54 @@ function constant(value) {
53
53
  };
54
54
  }
55
55
  /**
56
+ * Creates a parser that always fails without consuming any input.
57
+ *
58
+ * This is the counterpart to {@link constant}: while `constant(value)` always
59
+ * succeeds, `fail<T>()` always fails. At the type level it is declared to
60
+ * produce a value of type `T`, so it composes seamlessly with other parsers
61
+ * that expect `Parser<"sync", T, …>`.
62
+ *
63
+ * The primary use case is as the inner parser for
64
+ * `bindConfig(fail<T>(), { … })` when a value should *only* come from a
65
+ * config file and has no corresponding CLI flag or argument. Because `fail()`
66
+ * always fails, `bindConfig` will always fall back to the config file (or the
67
+ * supplied default).
68
+ *
69
+ * @template T The type of value this parser is declared to produce.
70
+ * @returns A {@link Parser} that always fails at parse time and always fails at
71
+ * complete time.
72
+ * @since 1.0.0
73
+ */
74
+ function fail() {
75
+ return {
76
+ $valueType: [],
77
+ $stateType: [],
78
+ $mode: "sync",
79
+ priority: 0,
80
+ usage: [],
81
+ initialState: void 0,
82
+ parse(_context) {
83
+ return {
84
+ success: false,
85
+ consumed: 0,
86
+ error: message`No value provided.`
87
+ };
88
+ },
89
+ complete(_state) {
90
+ return {
91
+ success: false,
92
+ error: message`No value provided.`
93
+ };
94
+ },
95
+ suggest(_context, _prefix) {
96
+ return [];
97
+ },
98
+ getDocFragments(_state, _defaultValue) {
99
+ return { fragments: [] };
100
+ }
101
+ };
102
+ }
103
+ /**
56
104
  * Internal helper to get suggestions from a value parser, using dependency values
57
105
  * if the parser is a derived parser and dependency values are available.
58
106
  * @internal
@@ -1182,4 +1230,4 @@ function passThrough(options = {}) {
1182
1230
  }
1183
1231
 
1184
1232
  //#endregion
1185
- export { argument, command, constant, flag, option, passThrough };
1233
+ export { argument, command, constant, fail, flag, option, passThrough };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.395+ace61d13",
3
+ "version": "1.0.0-dev.401+5769648d",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",