@optique/core 0.7.0-dev.130 → 0.7.0-dev.131

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.
@@ -106,7 +106,7 @@ function option(...args) {
106
106
  if (context.state.success && (valueParser != null || context.state.value)) return {
107
107
  success: false,
108
108
  consumed: 1,
109
- error: options.errors?.duplicate ? typeof options.errors.duplicate === "function" ? options.errors.duplicate(context.buffer[0]) : options.errors.duplicate : require_message.message`${context.buffer[0]} cannot be used multiple times.`
109
+ error: options.errors?.duplicate ? typeof options.errors.duplicate === "function" ? options.errors.duplicate(context.buffer[0]) : options.errors.duplicate : require_message.message`${require_message.optionName(context.buffer[0])} cannot be used multiple times.`
110
110
  };
111
111
  if (valueParser == null) return {
112
112
  success: true,
@@ -106,7 +106,7 @@ function option(...args) {
106
106
  if (context.state.success && (valueParser != null || context.state.value)) return {
107
107
  success: false,
108
108
  consumed: 1,
109
- error: options.errors?.duplicate ? typeof options.errors.duplicate === "function" ? options.errors.duplicate(context.buffer[0]) : options.errors.duplicate : message`${context.buffer[0]} cannot be used multiple times.`
109
+ error: options.errors?.duplicate ? typeof options.errors.duplicate === "function" ? options.errors.duplicate(context.buffer[0]) : options.errors.duplicate : message`${optionName(context.buffer[0])} cannot be used multiple times.`
110
110
  };
111
111
  if (valueParser == null) return {
112
112
  success: true,
@@ -16,25 +16,32 @@ function isValueParser(object) {
16
16
  * This parser validates that the input string matches one of
17
17
  * the specified values. If the input does not match any of the values,
18
18
  * it returns an error message indicating the valid options.
19
- * @param values An array of valid string values that this parser can accept.
19
+ * @param choices An array of valid string values that this parser can accept.
20
20
  * @param options Configuration options for the choice parser.
21
21
  * @returns A {@link ValueParser} that checks if the input matches one of the
22
22
  * specified values.
23
23
  */
24
- function choice(values, options = {}) {
25
- const normalizedValues = options.caseInsensitive ? values.map((v) => v.toLowerCase()) : values;
24
+ function choice(choices, options = {}) {
25
+ const normalizedValues = options.caseInsensitive ? choices.map((v) => v.toLowerCase()) : choices;
26
26
  return {
27
27
  metavar: options.metavar ?? "TYPE",
28
28
  parse(input) {
29
29
  const normalizedInput = options.caseInsensitive ? input.toLowerCase() : input;
30
30
  const index = normalizedValues.indexOf(normalizedInput);
31
- if (index < 0) return {
32
- success: false,
33
- error: options.errors?.invalidChoice ? typeof options.errors.invalidChoice === "function" ? options.errors.invalidChoice(input, values) : options.errors.invalidChoice : require_message.message`Expected one of ${values.join(", ")}, but got ${input}.`
34
- };
31
+ if (index < 0) {
32
+ let choicesList = [];
33
+ for (let i = 0; i < choices.length; i++) {
34
+ if (i > 0) choicesList = [...choicesList, ...require_message.message`, `];
35
+ choicesList = [...choicesList, ...require_message.message`${choices[i]}`];
36
+ }
37
+ return {
38
+ success: false,
39
+ error: options.errors?.invalidChoice ? typeof options.errors.invalidChoice === "function" ? options.errors.invalidChoice(input, choices) : options.errors.invalidChoice : require_message.message`Expected one of ${choicesList}, but got ${input}.`
40
+ };
41
+ }
35
42
  return {
36
43
  success: true,
37
- value: values[index]
44
+ value: choices[index]
38
45
  };
39
46
  },
40
47
  format(value) {
@@ -42,7 +49,7 @@ function choice(values, options = {}) {
42
49
  },
43
50
  suggest(prefix) {
44
51
  const normalizedPrefix = options.caseInsensitive ? prefix.toLowerCase() : prefix;
45
- return values.filter((value) => {
52
+ return choices.filter((value) => {
46
53
  const normalizedValue = options.caseInsensitive ? value.toLowerCase() : value;
47
54
  return normalizedValue.startsWith(normalizedPrefix);
48
55
  }).map((value) => ({
@@ -138,12 +138,12 @@ declare function isValueParser<T>(object: unknown): object is ValueParser<T>;
138
138
  * This parser validates that the input string matches one of
139
139
  * the specified values. If the input does not match any of the values,
140
140
  * it returns an error message indicating the valid options.
141
- * @param values An array of valid string values that this parser can accept.
141
+ * @param choices An array of valid string values that this parser can accept.
142
142
  * @param options Configuration options for the choice parser.
143
143
  * @returns A {@link ValueParser} that checks if the input matches one of the
144
144
  * specified values.
145
145
  */
146
- declare function choice<const T extends string>(values: readonly T[], options?: ChoiceOptions): ValueParser<T>;
146
+ declare function choice<const T extends string>(choices: readonly T[], options?: ChoiceOptions): ValueParser<T>;
147
147
  /**
148
148
  * Creates a {@link ValueParser} for strings.
149
149
  *
@@ -138,12 +138,12 @@ declare function isValueParser<T>(object: unknown): object is ValueParser<T>;
138
138
  * This parser validates that the input string matches one of
139
139
  * the specified values. If the input does not match any of the values,
140
140
  * it returns an error message indicating the valid options.
141
- * @param values An array of valid string values that this parser can accept.
141
+ * @param choices An array of valid string values that this parser can accept.
142
142
  * @param options Configuration options for the choice parser.
143
143
  * @returns A {@link ValueParser} that checks if the input matches one of the
144
144
  * specified values.
145
145
  */
146
- declare function choice<const T extends string>(values: readonly T[], options?: ChoiceOptions): ValueParser<T>;
146
+ declare function choice<const T extends string>(choices: readonly T[], options?: ChoiceOptions): ValueParser<T>;
147
147
  /**
148
148
  * Creates a {@link ValueParser} for strings.
149
149
  *
@@ -16,25 +16,32 @@ function isValueParser(object) {
16
16
  * This parser validates that the input string matches one of
17
17
  * the specified values. If the input does not match any of the values,
18
18
  * it returns an error message indicating the valid options.
19
- * @param values An array of valid string values that this parser can accept.
19
+ * @param choices An array of valid string values that this parser can accept.
20
20
  * @param options Configuration options for the choice parser.
21
21
  * @returns A {@link ValueParser} that checks if the input matches one of the
22
22
  * specified values.
23
23
  */
24
- function choice(values, options = {}) {
25
- const normalizedValues = options.caseInsensitive ? values.map((v) => v.toLowerCase()) : values;
24
+ function choice(choices, options = {}) {
25
+ const normalizedValues = options.caseInsensitive ? choices.map((v) => v.toLowerCase()) : choices;
26
26
  return {
27
27
  metavar: options.metavar ?? "TYPE",
28
28
  parse(input) {
29
29
  const normalizedInput = options.caseInsensitive ? input.toLowerCase() : input;
30
30
  const index = normalizedValues.indexOf(normalizedInput);
31
- if (index < 0) return {
32
- success: false,
33
- error: options.errors?.invalidChoice ? typeof options.errors.invalidChoice === "function" ? options.errors.invalidChoice(input, values) : options.errors.invalidChoice : message`Expected one of ${values.join(", ")}, but got ${input}.`
34
- };
31
+ if (index < 0) {
32
+ let choicesList = [];
33
+ for (let i = 0; i < choices.length; i++) {
34
+ if (i > 0) choicesList = [...choicesList, ...message`, `];
35
+ choicesList = [...choicesList, ...message`${choices[i]}`];
36
+ }
37
+ return {
38
+ success: false,
39
+ error: options.errors?.invalidChoice ? typeof options.errors.invalidChoice === "function" ? options.errors.invalidChoice(input, choices) : options.errors.invalidChoice : message`Expected one of ${choicesList}, but got ${input}.`
40
+ };
41
+ }
35
42
  return {
36
43
  success: true,
37
- value: values[index]
44
+ value: choices[index]
38
45
  };
39
46
  },
40
47
  format(value) {
@@ -42,7 +49,7 @@ function choice(values, options = {}) {
42
49
  },
43
50
  suggest(prefix) {
44
51
  const normalizedPrefix = options.caseInsensitive ? prefix.toLowerCase() : prefix;
45
- return values.filter((value) => {
52
+ return choices.filter((value) => {
46
53
  const normalizedValue = options.caseInsensitive ? value.toLowerCase() : value;
47
54
  return normalizedValue.startsWith(normalizedPrefix);
48
55
  }).map((value) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "0.7.0-dev.130+750c5ca1",
3
+ "version": "0.7.0-dev.131+dbb565c5",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",