@optique/core 0.10.0-dev.369 → 0.10.0-dev.374

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
@@ -93,6 +93,35 @@ function formatDocPage(programName, page, options = {}) {
93
93
  const formattedDefault = options.colors ? `\x1b[2m${defaultText}\x1b[0m` : defaultText;
94
94
  description += formattedDefault;
95
95
  }
96
+ if (options.showChoices && entry.choices != null) {
97
+ const prefix = typeof options.showChoices === "object" ? options.showChoices.prefix ?? " (" : " (";
98
+ const suffix = typeof options.showChoices === "object" ? options.showChoices.suffix ?? ")" : ")";
99
+ const label = typeof options.showChoices === "object" ? options.showChoices.label ?? "choices: " : "choices: ";
100
+ const maxItems = typeof options.showChoices === "object" ? options.showChoices.maxItems ?? 8 : 8;
101
+ const terms = Array.isArray(entry.choices) ? entry.choices : [];
102
+ let truncatedTerms = terms;
103
+ let truncated = false;
104
+ if (maxItems < Infinity) {
105
+ let valueCount = 0;
106
+ let cutIndex = terms.length;
107
+ for (let i = 0; i < terms.length; i++) if (terms[i].type === "value") {
108
+ valueCount++;
109
+ if (valueCount > maxItems) {
110
+ cutIndex = i > 0 && terms[i - 1].type === "text" ? i - 1 : i;
111
+ truncated = true;
112
+ break;
113
+ }
114
+ }
115
+ if (truncated) truncatedTerms = [...terms.slice(0, cutIndex), require_message.text(", ...")];
116
+ }
117
+ const choicesDisplay = require_message.formatMessage(truncatedTerms, {
118
+ colors: options.colors ? { resetSuffix: "\x1B[2m" } : false,
119
+ quotes: false
120
+ });
121
+ const choicesText = `${prefix}${label}${choicesDisplay}${suffix}`;
122
+ const formattedChoices = options.colors ? `\x1b[2m${choicesText}\x1b[0m` : choicesText;
123
+ description += formattedChoices;
124
+ }
96
125
  output += `${" ".repeat(termIndent)}${ansiAwareRightPad(term, termWidth)} ${description === "" ? "" : indentLines(description, termIndent + termWidth + 2)}\n`;
97
126
  }
98
127
  }
@@ -142,14 +171,14 @@ function formatDocPage(programName, page, options = {}) {
142
171
  }
143
172
  return output;
144
173
  }
145
- function indentLines(text, indent) {
146
- return text.split("\n").join("\n" + " ".repeat(indent));
174
+ function indentLines(text$1, indent) {
175
+ return text$1.split("\n").join("\n" + " ".repeat(indent));
147
176
  }
148
- function ansiAwareRightPad(text, length, char = " ") {
177
+ function ansiAwareRightPad(text$1, length, char = " ") {
149
178
  const ansiEscapeCodeRegex = /\x1B\[[0-9;]*[a-zA-Z]/g;
150
- const strippedText = text.replace(ansiEscapeCodeRegex, "");
151
- if (strippedText.length >= length) return text;
152
- return text + char.repeat(length - strippedText.length);
179
+ const strippedText = text$1.replace(ansiEscapeCodeRegex, "");
180
+ if (strippedText.length >= length) return text$1;
181
+ return text$1 + char.repeat(length - strippedText.length);
153
182
  }
154
183
 
155
184
  //#endregion
package/dist/doc.d.cts CHANGED
@@ -25,6 +25,14 @@ interface DocEntry {
25
25
  * specified.
26
26
  */
27
27
  readonly default?: Message;
28
+ /**
29
+ * An optional list of valid choices for the entry, formatted as a
30
+ * comma-separated {@link Message}. When present and the `showChoices`
31
+ * formatting option is enabled, this is appended to the entry description.
32
+ *
33
+ * @since 0.10.0
34
+ */
35
+ readonly choices?: Message;
28
36
  }
29
37
  /**
30
38
  * A section in a document that groups related entries together.
@@ -114,6 +122,38 @@ interface ShowDefaultOptions {
114
122
  */
115
123
  readonly suffix?: string;
116
124
  }
125
+ /**
126
+ * Configuration for customizing choices display formatting.
127
+ *
128
+ * @since 0.10.0
129
+ */
130
+ interface ShowChoicesOptions {
131
+ /**
132
+ * Text to display before the choices list.
133
+ *
134
+ * @default `" ("`
135
+ */
136
+ readonly prefix?: string;
137
+ /**
138
+ * Text to display after the choices list.
139
+ *
140
+ * @default `")"`
141
+ */
142
+ readonly suffix?: string;
143
+ /**
144
+ * Label text to display before the individual choice values.
145
+ *
146
+ * @default `"choices: "`
147
+ */
148
+ readonly label?: string;
149
+ /**
150
+ * Maximum number of choice values to display before truncating with
151
+ * `...`. Set to `Infinity` to show all choices.
152
+ *
153
+ * @default `8`
154
+ */
155
+ readonly maxItems?: number;
156
+ }
117
157
  /**
118
158
  * Options for formatting a documentation page.
119
159
  */
@@ -161,6 +201,33 @@ interface DocPageFormatOptions {
161
201
  * ```
162
202
  */
163
203
  showDefault?: boolean | ShowDefaultOptions;
204
+ /**
205
+ * Whether and how to display valid choices for options and arguments
206
+ * backed by enumerated value parsers (e.g., `choice()`).
207
+ *
208
+ * - `boolean`: When `true`, displays choices using format
209
+ * `(choices: a, b, c)`
210
+ * - `ShowChoicesOptions`: Custom formatting with configurable prefix,
211
+ * suffix, label, and maximum number of items
212
+ *
213
+ * Choice values are automatically dimmed when `colors` is enabled.
214
+ *
215
+ * @default `false`
216
+ * @since 0.10.0
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * // Basic usage - shows "(choices: json, yaml, xml)"
221
+ * { showChoices: true }
222
+ *
223
+ * // Custom format - shows "{json | yaml | xml}"
224
+ * { showChoices: { prefix: " {", suffix: "}", label: "" } }
225
+ *
226
+ * // Limit displayed choices
227
+ * { showChoices: { maxItems: 3 } }
228
+ * ```
229
+ */
230
+ showChoices?: boolean | ShowChoicesOptions;
164
231
  }
165
232
  /**
166
233
  * Formats a documentation page into a human-readable string.
@@ -195,4 +262,4 @@ interface DocPageFormatOptions {
195
262
  */
196
263
  declare function formatDocPage(programName: string, page: DocPage, options?: DocPageFormatOptions): string;
197
264
  //#endregion
198
- export { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowDefaultOptions, formatDocPage };
265
+ export { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, formatDocPage };
package/dist/doc.d.ts CHANGED
@@ -25,6 +25,14 @@ interface DocEntry {
25
25
  * specified.
26
26
  */
27
27
  readonly default?: Message;
28
+ /**
29
+ * An optional list of valid choices for the entry, formatted as a
30
+ * comma-separated {@link Message}. When present and the `showChoices`
31
+ * formatting option is enabled, this is appended to the entry description.
32
+ *
33
+ * @since 0.10.0
34
+ */
35
+ readonly choices?: Message;
28
36
  }
29
37
  /**
30
38
  * A section in a document that groups related entries together.
@@ -114,6 +122,38 @@ interface ShowDefaultOptions {
114
122
  */
115
123
  readonly suffix?: string;
116
124
  }
125
+ /**
126
+ * Configuration for customizing choices display formatting.
127
+ *
128
+ * @since 0.10.0
129
+ */
130
+ interface ShowChoicesOptions {
131
+ /**
132
+ * Text to display before the choices list.
133
+ *
134
+ * @default `" ("`
135
+ */
136
+ readonly prefix?: string;
137
+ /**
138
+ * Text to display after the choices list.
139
+ *
140
+ * @default `")"`
141
+ */
142
+ readonly suffix?: string;
143
+ /**
144
+ * Label text to display before the individual choice values.
145
+ *
146
+ * @default `"choices: "`
147
+ */
148
+ readonly label?: string;
149
+ /**
150
+ * Maximum number of choice values to display before truncating with
151
+ * `...`. Set to `Infinity` to show all choices.
152
+ *
153
+ * @default `8`
154
+ */
155
+ readonly maxItems?: number;
156
+ }
117
157
  /**
118
158
  * Options for formatting a documentation page.
119
159
  */
@@ -161,6 +201,33 @@ interface DocPageFormatOptions {
161
201
  * ```
162
202
  */
163
203
  showDefault?: boolean | ShowDefaultOptions;
204
+ /**
205
+ * Whether and how to display valid choices for options and arguments
206
+ * backed by enumerated value parsers (e.g., `choice()`).
207
+ *
208
+ * - `boolean`: When `true`, displays choices using format
209
+ * `(choices: a, b, c)`
210
+ * - `ShowChoicesOptions`: Custom formatting with configurable prefix,
211
+ * suffix, label, and maximum number of items
212
+ *
213
+ * Choice values are automatically dimmed when `colors` is enabled.
214
+ *
215
+ * @default `false`
216
+ * @since 0.10.0
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * // Basic usage - shows "(choices: json, yaml, xml)"
221
+ * { showChoices: true }
222
+ *
223
+ * // Custom format - shows "{json | yaml | xml}"
224
+ * { showChoices: { prefix: " {", suffix: "}", label: "" } }
225
+ *
226
+ * // Limit displayed choices
227
+ * { showChoices: { maxItems: 3 } }
228
+ * ```
229
+ */
230
+ showChoices?: boolean | ShowChoicesOptions;
164
231
  }
165
232
  /**
166
233
  * Formats a documentation page into a human-readable string.
@@ -195,4 +262,4 @@ interface DocPageFormatOptions {
195
262
  */
196
263
  declare function formatDocPage(programName: string, page: DocPage, options?: DocPageFormatOptions): string;
197
264
  //#endregion
198
- export { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowDefaultOptions, formatDocPage };
265
+ export { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, formatDocPage };
package/dist/doc.js CHANGED
@@ -1,4 +1,4 @@
1
- import { formatMessage } from "./message.js";
1
+ import { formatMessage, text } from "./message.js";
2
2
  import { formatUsage, formatUsageTerm } from "./usage.js";
3
3
 
4
4
  //#region src/doc.ts
@@ -93,6 +93,35 @@ function formatDocPage(programName, page, options = {}) {
93
93
  const formattedDefault = options.colors ? `\x1b[2m${defaultText}\x1b[0m` : defaultText;
94
94
  description += formattedDefault;
95
95
  }
96
+ if (options.showChoices && entry.choices != null) {
97
+ const prefix = typeof options.showChoices === "object" ? options.showChoices.prefix ?? " (" : " (";
98
+ const suffix = typeof options.showChoices === "object" ? options.showChoices.suffix ?? ")" : ")";
99
+ const label = typeof options.showChoices === "object" ? options.showChoices.label ?? "choices: " : "choices: ";
100
+ const maxItems = typeof options.showChoices === "object" ? options.showChoices.maxItems ?? 8 : 8;
101
+ const terms = Array.isArray(entry.choices) ? entry.choices : [];
102
+ let truncatedTerms = terms;
103
+ let truncated = false;
104
+ if (maxItems < Infinity) {
105
+ let valueCount = 0;
106
+ let cutIndex = terms.length;
107
+ for (let i = 0; i < terms.length; i++) if (terms[i].type === "value") {
108
+ valueCount++;
109
+ if (valueCount > maxItems) {
110
+ cutIndex = i > 0 && terms[i - 1].type === "text" ? i - 1 : i;
111
+ truncated = true;
112
+ break;
113
+ }
114
+ }
115
+ if (truncated) truncatedTerms = [...terms.slice(0, cutIndex), text(", ...")];
116
+ }
117
+ const choicesDisplay = formatMessage(truncatedTerms, {
118
+ colors: options.colors ? { resetSuffix: "\x1B[2m" } : false,
119
+ quotes: false
120
+ });
121
+ const choicesText = `${prefix}${label}${choicesDisplay}${suffix}`;
122
+ const formattedChoices = options.colors ? `\x1b[2m${choicesText}\x1b[0m` : choicesText;
123
+ description += formattedChoices;
124
+ }
96
125
  output += `${" ".repeat(termIndent)}${ansiAwareRightPad(term, termWidth)} ${description === "" ? "" : indentLines(description, termIndent + termWidth + 2)}\n`;
97
126
  }
98
127
  }
@@ -142,14 +171,14 @@ function formatDocPage(programName, page, options = {}) {
142
171
  }
143
172
  return output;
144
173
  }
145
- function indentLines(text, indent) {
146
- return text.split("\n").join("\n" + " ".repeat(indent));
174
+ function indentLines(text$1, indent) {
175
+ return text$1.split("\n").join("\n" + " ".repeat(indent));
147
176
  }
148
- function ansiAwareRightPad(text, length, char = " ") {
177
+ function ansiAwareRightPad(text$1, length, char = " ") {
149
178
  const ansiEscapeCodeRegex = /\x1B\[[0-9;]*[a-zA-Z]/g;
150
- const strippedText = text.replace(ansiEscapeCodeRegex, "");
151
- if (strippedText.length >= length) return text;
152
- return text + char.repeat(length - strippedText.length);
179
+ const strippedText = text$1.replace(ansiEscapeCodeRegex, "");
180
+ if (strippedText.length >= length) return text$1;
181
+ return text$1 + char.repeat(length - strippedText.length);
153
182
  }
154
183
 
155
184
  //#endregion
package/dist/facade.cjs CHANGED
@@ -288,9 +288,26 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
288
288
  completion: require_primitives.constant(false),
289
289
  result: originalParser
290
290
  }));
291
+ const mainParserIndex = parsers.length - 1;
291
292
  if (parsers.length === 1) return parsers[0];
292
- else if (parsers.length === 2) return require_constructs.longestMatch(parsers[0], parsers[1]);
293
- else return require_constructs.longestMatch(...parsers);
293
+ let combined;
294
+ if (parsers.length === 2) combined = require_constructs.longestMatch(parsers[0], parsers[1]);
295
+ else combined = require_constructs.longestMatch(...parsers);
296
+ const topUsage = combined.usage[0];
297
+ if (topUsage?.type === "exclusive" && mainParserIndex > 0) {
298
+ const terms = [...topUsage.terms];
299
+ const [mainTerm] = terms.splice(mainParserIndex, 1);
300
+ const lenientCount = (helpParsers.helpOption ? 1 : 0) + (versionParsers.versionOption ? 1 : 0);
301
+ terms.splice(lenientCount, 0, mainTerm);
302
+ combined = {
303
+ ...combined,
304
+ usage: [{
305
+ ...topUsage,
306
+ terms
307
+ }]
308
+ };
309
+ }
310
+ return combined;
294
311
  }
295
312
  /**
296
313
  * Classifies the parsing result into a discriminated union for cleaner handling.
@@ -434,7 +451,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
434
451
  args = argsOrOptions;
435
452
  options = optionsParam ?? {};
436
453
  }
437
- const { colors, maxWidth, showDefault, aboveError = "usage", onError = () => {
454
+ const { colors, maxWidth, showDefault, showChoices, aboveError = "usage", onError = () => {
438
455
  throw new RunParserError("Failed to parse command line arguments.");
439
456
  }, stderr = console.error, stdout = console.log, brief, description, examples, author, bugs, footer } = options;
440
457
  const helpMode = options.help?.mode ?? "option";
@@ -602,7 +619,8 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
602
619
  stdout(require_doc.formatDocPage(programName, augmentedDoc, {
603
620
  colors,
604
621
  maxWidth,
605
- showDefault
622
+ showDefault,
623
+ showChoices
606
624
  }));
607
625
  }
608
626
  try {
@@ -632,7 +650,8 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
632
650
  stderr(require_doc.formatDocPage(programName, augmentedDoc, {
633
651
  colors,
634
652
  maxWidth,
635
- showDefault
653
+ showDefault,
654
+ showChoices
636
655
  }));
637
656
  }
638
657
  if (effectiveAboveError === "usage") stderr(`Usage: ${indentLines(require_usage.formatUsage(programName, augmentedParser.usage, {
package/dist/facade.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Message } from "./message.cjs";
2
- import { ShowDefaultOptions } from "./doc.cjs";
2
+ import { 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";
@@ -112,6 +112,21 @@ interface RunOptions<THelp, TError> {
112
112
  * @since 0.4.0
113
113
  */
114
114
  readonly showDefault?: boolean | ShowDefaultOptions;
115
+ /**
116
+ * Whether and how to display valid choices for options and arguments
117
+ * backed by enumerated value parsers (e.g., `choice()`).
118
+ *
119
+ * - `boolean`: When `true`, displays choices using format
120
+ * `(choices: a, b, c)`
121
+ * - `ShowChoicesOptions`: Custom formatting with configurable prefix,
122
+ * suffix, label, and maximum number of items
123
+ *
124
+ * Choice values are automatically dimmed when `colors` is enabled.
125
+ *
126
+ * @default `false`
127
+ * @since 0.10.0
128
+ */
129
+ readonly showChoices?: boolean | ShowChoicesOptions;
115
130
  /**
116
131
  * Help configuration. When provided, enables help functionality.
117
132
  */
package/dist/facade.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Message } from "./message.js";
2
- import { ShowDefaultOptions } from "./doc.js";
2
+ import { 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";
@@ -112,6 +112,21 @@ interface RunOptions<THelp, TError> {
112
112
  * @since 0.4.0
113
113
  */
114
114
  readonly showDefault?: boolean | ShowDefaultOptions;
115
+ /**
116
+ * Whether and how to display valid choices for options and arguments
117
+ * backed by enumerated value parsers (e.g., `choice()`).
118
+ *
119
+ * - `boolean`: When `true`, displays choices using format
120
+ * `(choices: a, b, c)`
121
+ * - `ShowChoicesOptions`: Custom formatting with configurable prefix,
122
+ * suffix, label, and maximum number of items
123
+ *
124
+ * Choice values are automatically dimmed when `colors` is enabled.
125
+ *
126
+ * @default `false`
127
+ * @since 0.10.0
128
+ */
129
+ readonly showChoices?: boolean | ShowChoicesOptions;
115
130
  /**
116
131
  * Help configuration. When provided, enables help functionality.
117
132
  */
package/dist/facade.js CHANGED
@@ -288,9 +288,26 @@ function combineWithHelpVersion(originalParser, helpParsers, versionParsers, com
288
288
  completion: constant(false),
289
289
  result: originalParser
290
290
  }));
291
+ const mainParserIndex = parsers.length - 1;
291
292
  if (parsers.length === 1) return parsers[0];
292
- else if (parsers.length === 2) return longestMatch(parsers[0], parsers[1]);
293
- else return longestMatch(...parsers);
293
+ let combined;
294
+ if (parsers.length === 2) combined = longestMatch(parsers[0], parsers[1]);
295
+ else combined = longestMatch(...parsers);
296
+ const topUsage = combined.usage[0];
297
+ if (topUsage?.type === "exclusive" && mainParserIndex > 0) {
298
+ const terms = [...topUsage.terms];
299
+ const [mainTerm] = terms.splice(mainParserIndex, 1);
300
+ const lenientCount = (helpParsers.helpOption ? 1 : 0) + (versionParsers.versionOption ? 1 : 0);
301
+ terms.splice(lenientCount, 0, mainTerm);
302
+ combined = {
303
+ ...combined,
304
+ usage: [{
305
+ ...topUsage,
306
+ terms
307
+ }]
308
+ };
309
+ }
310
+ return combined;
294
311
  }
295
312
  /**
296
313
  * Classifies the parsing result into a discriminated union for cleaner handling.
@@ -434,7 +451,7 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
434
451
  args = argsOrOptions;
435
452
  options = optionsParam ?? {};
436
453
  }
437
- const { colors, maxWidth, showDefault, aboveError = "usage", onError = () => {
454
+ const { colors, maxWidth, showDefault, showChoices, aboveError = "usage", onError = () => {
438
455
  throw new RunParserError("Failed to parse command line arguments.");
439
456
  }, stderr = console.error, stdout = console.log, brief, description, examples, author, bugs, footer } = options;
440
457
  const helpMode = options.help?.mode ?? "option";
@@ -602,7 +619,8 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
602
619
  stdout(formatDocPage(programName, augmentedDoc, {
603
620
  colors,
604
621
  maxWidth,
605
- showDefault
622
+ showDefault,
623
+ showChoices
606
624
  }));
607
625
  }
608
626
  try {
@@ -632,7 +650,8 @@ function runParser(parserOrProgram, programNameOrArgs, argsOrOptions, optionsPar
632
650
  stderr(formatDocPage(programName, augmentedDoc, {
633
651
  colors,
634
652
  maxWidth,
635
- showDefault
653
+ showDefault,
654
+ showChoices
636
655
  }));
637
656
  }
638
657
  if (effectiveAboveError === "usage") stderr(`Usage: ${indentLines(formatUsage(programName, augmentedParser.usage, {
package/dist/index.d.cts CHANGED
@@ -2,7 +2,7 @@ import { Annotations, ParseOptions, annotationKey, getAnnotations } from "./anno
2
2
  import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonempty.cjs";
3
3
  import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.cjs";
4
4
  import { OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.cjs";
5
- import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowDefaultOptions, formatDocPage } from "./doc.cjs";
5
+ import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, formatDocPage } from "./doc.cjs";
6
6
  import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, cidr, domain, email, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } 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";
@@ -12,4 +12,4 @@ import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, Mode
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, 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, 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
@@ -2,7 +2,7 @@ import { Annotations, ParseOptions, annotationKey, getAnnotations } from "./anno
2
2
  import { NonEmptyString, ensureNonEmptyString, isNonEmptyString } from "./nonempty.js";
3
3
  import { Message, MessageFormatOptions, MessageTerm, ValueSetOptions, commandLine, envVar, formatMessage, lineBreak, link, message, metavar, optionName, optionNames, text, value, valueSet, values } from "./message.js";
4
4
  import { OptionName, Usage, UsageFormatOptions, UsageTerm, UsageTermFormatOptions, extractArgumentMetavars, extractCommandNames, extractOptionNames, formatUsage, formatUsageTerm, normalizeUsage } from "./usage.js";
5
- import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowDefaultOptions, formatDocPage } from "./doc.js";
5
+ import { DocEntry, DocFragment, DocFragments, DocPage, DocPageFormatOptions, DocSection, ShowChoicesOptions, ShowDefaultOptions, formatDocPage } from "./doc.js";
6
6
  import { ChoiceOptions, ChoiceOptionsBase, ChoiceOptionsNumber, ChoiceOptionsString, CidrOptions, CidrValue, DomainOptions, EmailOptions, FloatOptions, HostnameOptions, IntegerOptionsBigInt, IntegerOptionsNumber, IpOptions, Ipv4Options, Ipv6Options, LocaleOptions, MacAddressOptions, PortOptionsBigInt, PortOptionsNumber, PortRangeOptionsBigInt, PortRangeOptionsNumber, PortRangeValueBigInt, PortRangeValueNumber, SocketAddressOptions, SocketAddressValue, StringOptions, UrlOptions, Uuid, UuidOptions, ValueParser, ValueParserResult, choice, cidr, domain, email, float, hostname, integer, ip, ipv4, ipv6, isValueParser, locale, macAddress, port, portRange, socketAddress, string, url, uuid } 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";
@@ -12,4 +12,4 @@ import { CombineModes, DocState, InferMode, InferValue, Mode, ModeIterable, Mode
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, 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, 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 };
@@ -464,6 +464,7 @@ function option(...args) {
464
464
  fragments: [],
465
465
  description: options.description
466
466
  };
467
+ const choicesMessage = valueParser?.choices != null && valueParser.choices.length > 0 ? require_message.valueSet(valueParser.choices.map((c) => valueParser.format(c)), { type: "unit" }) : void 0;
467
468
  const fragments = [{
468
469
  type: "entry",
469
470
  term: {
@@ -472,7 +473,8 @@ function option(...args) {
472
473
  metavar: valueParser?.metavar
473
474
  },
474
475
  description: options.description,
475
- default: defaultValue != null && valueParser != null ? require_message.message`${valueParser.format(defaultValue)}` : void 0
476
+ default: defaultValue != null && valueParser != null ? require_message.message`${valueParser.format(defaultValue)}` : void 0,
477
+ choices: choicesMessage
476
478
  }];
477
479
  return {
478
480
  fragments,
@@ -790,11 +792,13 @@ function argument(valueParser, options = {}) {
790
792
  fragments: [],
791
793
  description: options.description
792
794
  };
795
+ const choicesMessage = valueParser.choices != null && valueParser.choices.length > 0 ? require_message.valueSet(valueParser.choices.map((c) => valueParser.format(c)), { type: "unit" }) : void 0;
793
796
  const fragments = [{
794
797
  type: "entry",
795
798
  term,
796
799
  description: options.description,
797
- default: defaultValue == null ? void 0 : require_message.message`${valueParser.format(defaultValue)}`
800
+ default: defaultValue == null ? void 0 : require_message.message`${valueParser.format(defaultValue)}`,
801
+ choices: choicesMessage
798
802
  }];
799
803
  return {
800
804
  fragments,
@@ -1,4 +1,4 @@
1
- import { message, metavar, optionName, optionNames } from "./message.js";
1
+ import { message, metavar, optionName, optionNames, valueSet } from "./message.js";
2
2
  import { createDeferredParseState, createDependencySourceState, createPendingDependencySourceState, dependencyId, getDefaultValuesFunction, getDependencyIds, isDeferredParseState, isDependencySource, isDependencySourceState, isDerivedValueParser, isPendingDependencySourceState, suggestWithDependency } from "./dependency.js";
3
3
  import { extractCommandNames, extractOptionNames } from "./usage.js";
4
4
  import { DEFAULT_FIND_SIMILAR_OPTIONS, createErrorWithSuggestions, findSimilar } from "./suggestion.js";
@@ -464,6 +464,7 @@ function option(...args) {
464
464
  fragments: [],
465
465
  description: options.description
466
466
  };
467
+ const choicesMessage = valueParser?.choices != null && valueParser.choices.length > 0 ? valueSet(valueParser.choices.map((c) => valueParser.format(c)), { type: "unit" }) : void 0;
467
468
  const fragments = [{
468
469
  type: "entry",
469
470
  term: {
@@ -472,7 +473,8 @@ function option(...args) {
472
473
  metavar: valueParser?.metavar
473
474
  },
474
475
  description: options.description,
475
- default: defaultValue != null && valueParser != null ? message`${valueParser.format(defaultValue)}` : void 0
476
+ default: defaultValue != null && valueParser != null ? message`${valueParser.format(defaultValue)}` : void 0,
477
+ choices: choicesMessage
476
478
  }];
477
479
  return {
478
480
  fragments,
@@ -790,11 +792,13 @@ function argument(valueParser, options = {}) {
790
792
  fragments: [],
791
793
  description: options.description
792
794
  };
795
+ const choicesMessage = valueParser.choices != null && valueParser.choices.length > 0 ? valueSet(valueParser.choices.map((c) => valueParser.format(c)), { type: "unit" }) : void 0;
793
796
  const fragments = [{
794
797
  type: "entry",
795
798
  term,
796
799
  description: options.description,
797
- default: defaultValue == null ? void 0 : message`${valueParser.format(defaultValue)}`
800
+ default: defaultValue == null ? void 0 : message`${valueParser.format(defaultValue)}`,
801
+ choices: choicesMessage
798
802
  }];
799
803
  return {
800
804
  fragments,
@@ -23,6 +23,7 @@ function choice(choices, options = {}) {
23
23
  return {
24
24
  $mode: "sync",
25
25
  metavar,
26
+ choices,
26
27
  parse(input) {
27
28
  const parsed = Number(input);
28
29
  if (Number.isNaN(parsed)) return {
@@ -56,6 +57,7 @@ function choice(choices, options = {}) {
56
57
  return {
57
58
  $mode: "sync",
58
59
  metavar,
60
+ choices,
59
61
  parse(input) {
60
62
  const normalizedInput = stringOptions.caseInsensitive ? input.toLowerCase() : input;
61
63
  const index = normalizedValues.indexOf(normalizedInput);
@@ -59,6 +59,16 @@ interface ValueParser<M extends Mode = "sync", T = unknown> {
59
59
  * @since 0.6.0
60
60
  */
61
61
  suggest?(prefix: string): ModeIterable<M, Suggestion>;
62
+ /**
63
+ * An optional array of valid choices for this parser. When present,
64
+ * indicates that this parser accepts only a fixed set of values, which
65
+ * can be displayed in help output via the `showChoices` formatting option.
66
+ *
67
+ * This field is populated automatically by the {@link choice} function.
68
+ *
69
+ * @since 0.10.0
70
+ */
71
+ readonly choices?: readonly T[];
62
72
  }
63
73
  /**
64
74
  * Result type returned by {@link ValueParser#parse}.
@@ -59,6 +59,16 @@ interface ValueParser<M extends Mode = "sync", T = unknown> {
59
59
  * @since 0.6.0
60
60
  */
61
61
  suggest?(prefix: string): ModeIterable<M, Suggestion>;
62
+ /**
63
+ * An optional array of valid choices for this parser. When present,
64
+ * indicates that this parser accepts only a fixed set of values, which
65
+ * can be displayed in help output via the `showChoices` formatting option.
66
+ *
67
+ * This field is populated automatically by the {@link choice} function.
68
+ *
69
+ * @since 0.10.0
70
+ */
71
+ readonly choices?: readonly T[];
62
72
  }
63
73
  /**
64
74
  * Result type returned by {@link ValueParser#parse}.
@@ -23,6 +23,7 @@ function choice(choices, options = {}) {
23
23
  return {
24
24
  $mode: "sync",
25
25
  metavar,
26
+ choices,
26
27
  parse(input) {
27
28
  const parsed = Number(input);
28
29
  if (Number.isNaN(parsed)) return {
@@ -56,6 +57,7 @@ function choice(choices, options = {}) {
56
57
  return {
57
58
  $mode: "sync",
58
59
  metavar,
60
+ choices,
59
61
  parse(input) {
60
62
  const normalizedInput = stringOptions.caseInsensitive ? input.toLowerCase() : input;
61
63
  const index = normalizedValues.indexOf(normalizedInput);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.10.0-dev.369+ceed7dcf",
3
+ "version": "0.10.0-dev.374+981b7fab",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",