@optique/inquirer 1.2.0-dev.2187 → 1.2.0-dev.2192
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/README.md +4 -4
- package/dist/index.cjs +119 -380
- package/dist/index.d.cts +52 -170
- package/dist/index.d.ts +52 -170
- package/dist/index.js +119 -380
- package/package.json +7 -6
package/dist/index.d.cts
CHANGED
|
@@ -32,6 +32,15 @@ interface Choice {
|
|
|
32
32
|
*/
|
|
33
33
|
readonly disabled?: boolean | string;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* A choice item for the `checkbox` prompt type.
|
|
37
|
+
*
|
|
38
|
+
* @since 1.2.0
|
|
39
|
+
*/
|
|
40
|
+
interface CheckboxChoice extends Choice {
|
|
41
|
+
/** Whether the choice is initially selected. */
|
|
42
|
+
readonly checked?: boolean;
|
|
43
|
+
}
|
|
35
44
|
/**
|
|
36
45
|
* A choice item for the `expand` prompt type.
|
|
37
46
|
*
|
|
@@ -61,19 +70,11 @@ interface ExpandChoice {
|
|
|
61
70
|
*/
|
|
62
71
|
interface ConfirmConfig {
|
|
63
72
|
readonly type: "confirm";
|
|
64
|
-
/**
|
|
65
|
-
* The question to display to the user.
|
|
66
|
-
*/
|
|
73
|
+
/** The question to display to the user. */
|
|
67
74
|
readonly message: string;
|
|
68
|
-
/**
|
|
69
|
-
* Default answer when the user just presses Enter.
|
|
70
|
-
*/
|
|
75
|
+
/** Default answer when the user just presses Enter. */
|
|
71
76
|
readonly default?: boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Override the prompt execution. When provided, this function is called
|
|
74
|
-
* instead of launching an interactive Inquirer.js prompt. Useful for
|
|
75
|
-
* testing.
|
|
76
|
-
*/
|
|
77
|
+
/** Override the prompt execution. Useful for testing. */
|
|
77
78
|
readonly prompter?: () => Promise<boolean>;
|
|
78
79
|
}
|
|
79
80
|
/**
|
|
@@ -83,34 +84,17 @@ interface ConfirmConfig {
|
|
|
83
84
|
*/
|
|
84
85
|
interface NumberPromptConfig {
|
|
85
86
|
readonly type: "number";
|
|
86
|
-
/**
|
|
87
|
-
* The question to display to the user.
|
|
88
|
-
*/
|
|
87
|
+
/** The question to display to the user. */
|
|
89
88
|
readonly message: string;
|
|
90
|
-
/**
|
|
91
|
-
* Default number shown to the user.
|
|
92
|
-
*/
|
|
89
|
+
/** Default number shown to the user. */
|
|
93
90
|
readonly default?: number;
|
|
94
|
-
/**
|
|
95
|
-
* Minimum accepted value.
|
|
96
|
-
*/
|
|
91
|
+
/** Minimum accepted value. */
|
|
97
92
|
readonly min?: number;
|
|
98
|
-
/**
|
|
99
|
-
* Maximum accepted value.
|
|
100
|
-
*/
|
|
93
|
+
/** Maximum accepted value. */
|
|
101
94
|
readonly max?: number;
|
|
102
|
-
/**
|
|
103
|
-
* Granularity of valid values. Use `"any"` for arbitrary decimals.
|
|
104
|
-
*/
|
|
95
|
+
/** Granularity of valid values. Use `"any"` for arbitrary decimals. */
|
|
105
96
|
readonly step?: number | "any";
|
|
106
|
-
/**
|
|
107
|
-
* Override the prompt execution. When provided, this function is called
|
|
108
|
-
* instead of launching an interactive Inquirer.js prompt. Useful for
|
|
109
|
-
* testing.
|
|
110
|
-
*
|
|
111
|
-
* Return `undefined` to simulate the user leaving the field empty (which
|
|
112
|
-
* results in a parse failure).
|
|
113
|
-
*/
|
|
97
|
+
/** Override the prompt execution. Useful for testing. */
|
|
114
98
|
readonly prompter?: () => Promise<number | undefined>;
|
|
115
99
|
}
|
|
116
100
|
/**
|
|
@@ -120,24 +104,13 @@ interface NumberPromptConfig {
|
|
|
120
104
|
*/
|
|
121
105
|
interface InputConfig {
|
|
122
106
|
readonly type: "input";
|
|
123
|
-
/**
|
|
124
|
-
* The question to display to the user.
|
|
125
|
-
*/
|
|
107
|
+
/** The question to display to the user. */
|
|
126
108
|
readonly message: string;
|
|
127
|
-
/**
|
|
128
|
-
* Default text pre-filled in the prompt.
|
|
129
|
-
*/
|
|
109
|
+
/** Default text pre-filled in the prompt. */
|
|
130
110
|
readonly default?: string;
|
|
131
|
-
/**
|
|
132
|
-
* Validation function called when the user submits.
|
|
133
|
-
* Return `true` or a string error message.
|
|
134
|
-
*/
|
|
111
|
+
/** Validation function called when the user submits. */
|
|
135
112
|
readonly validate?: (value: string) => boolean | string | Promise<boolean | string>;
|
|
136
|
-
/**
|
|
137
|
-
* Override the prompt execution. When provided, this function is called
|
|
138
|
-
* instead of launching an interactive Inquirer.js prompt. Useful for
|
|
139
|
-
* testing.
|
|
140
|
-
*/
|
|
113
|
+
/** Override the prompt execution. Useful for testing. */
|
|
141
114
|
readonly prompter?: () => Promise<string>;
|
|
142
115
|
}
|
|
143
116
|
/**
|
|
@@ -147,54 +120,29 @@ interface InputConfig {
|
|
|
147
120
|
*/
|
|
148
121
|
interface PasswordConfig {
|
|
149
122
|
readonly type: "password";
|
|
150
|
-
/**
|
|
151
|
-
* The question to display to the user.
|
|
152
|
-
*/
|
|
123
|
+
/** The question to display to the user. */
|
|
153
124
|
readonly message: string;
|
|
154
|
-
/**
|
|
155
|
-
* If `true`, show `*` characters for each keystroke.
|
|
156
|
-
* If `false` or omitted, input is invisible.
|
|
157
|
-
*/
|
|
125
|
+
/** If `true`, show `*` characters for each keystroke. */
|
|
158
126
|
readonly mask?: boolean;
|
|
159
|
-
/**
|
|
160
|
-
* Validation function called when the user submits.
|
|
161
|
-
* Return `true` or a string error message.
|
|
162
|
-
*/
|
|
127
|
+
/** Validation function called when the user submits. */
|
|
163
128
|
readonly validate?: (value: string) => boolean | string | Promise<boolean | string>;
|
|
164
|
-
/**
|
|
165
|
-
* Override the prompt execution. When provided, this function is called
|
|
166
|
-
* instead of launching an interactive Inquirer.js prompt. Useful for
|
|
167
|
-
* testing.
|
|
168
|
-
*/
|
|
129
|
+
/** Override the prompt execution. Useful for testing. */
|
|
169
130
|
readonly prompter?: () => Promise<string>;
|
|
170
131
|
}
|
|
171
132
|
/**
|
|
172
133
|
* Configuration for an `editor` prompt (external editor).
|
|
173
134
|
*
|
|
174
|
-
* Opens the user's `$VISUAL` or `$EDITOR` for multi-line text input.
|
|
175
|
-
*
|
|
176
135
|
* @since 1.0.0
|
|
177
136
|
*/
|
|
178
137
|
interface EditorConfig {
|
|
179
138
|
readonly type: "editor";
|
|
180
|
-
/**
|
|
181
|
-
* The question to display to the user.
|
|
182
|
-
*/
|
|
139
|
+
/** The question to display to the user. */
|
|
183
140
|
readonly message: string;
|
|
184
|
-
/**
|
|
185
|
-
* Default content pre-filled in the editor.
|
|
186
|
-
*/
|
|
141
|
+
/** Default content pre-filled in the editor. */
|
|
187
142
|
readonly default?: string;
|
|
188
|
-
/**
|
|
189
|
-
* Validation function called when the editor is closed.
|
|
190
|
-
* Return `true` or a string error message.
|
|
191
|
-
*/
|
|
143
|
+
/** Validation function called when the editor is closed. */
|
|
192
144
|
readonly validate?: (value: string) => boolean | string | Promise<boolean | string>;
|
|
193
|
-
/**
|
|
194
|
-
* Override the prompt execution. When provided, this function is called
|
|
195
|
-
* instead of launching an interactive Inquirer.js prompt. Useful for
|
|
196
|
-
* testing.
|
|
197
|
-
*/
|
|
145
|
+
/** Override the prompt execution. Useful for testing. */
|
|
198
146
|
readonly prompter?: () => Promise<string>;
|
|
199
147
|
}
|
|
200
148
|
/**
|
|
@@ -204,24 +152,13 @@ interface EditorConfig {
|
|
|
204
152
|
*/
|
|
205
153
|
interface SelectConfig {
|
|
206
154
|
readonly type: "select";
|
|
207
|
-
/**
|
|
208
|
-
* The question to display to the user.
|
|
209
|
-
*/
|
|
155
|
+
/** The question to display to the user. */
|
|
210
156
|
readonly message: string;
|
|
211
|
-
/**
|
|
212
|
-
* Available choices. Plain strings and {@link Choice} objects can be mixed.
|
|
213
|
-
* Use `new Separator(...)` for visual dividers.
|
|
214
|
-
*/
|
|
157
|
+
/** Available choices. */
|
|
215
158
|
readonly choices: readonly (string | Choice | Separator)[];
|
|
216
|
-
/**
|
|
217
|
-
* Initially highlighted choice value.
|
|
218
|
-
*/
|
|
159
|
+
/** Initially highlighted choice value. */
|
|
219
160
|
readonly default?: string;
|
|
220
|
-
/**
|
|
221
|
-
* Override the prompt execution. When provided, this function is called
|
|
222
|
-
* instead of launching an interactive Inquirer.js prompt. Useful for
|
|
223
|
-
* testing.
|
|
224
|
-
*/
|
|
161
|
+
/** Override the prompt execution. Useful for testing. */
|
|
225
162
|
readonly prompter?: () => Promise<string>;
|
|
226
163
|
}
|
|
227
164
|
/**
|
|
@@ -231,23 +168,13 @@ interface SelectConfig {
|
|
|
231
168
|
*/
|
|
232
169
|
interface RawlistConfig {
|
|
233
170
|
readonly type: "rawlist";
|
|
234
|
-
/**
|
|
235
|
-
* The question to display to the user.
|
|
236
|
-
*/
|
|
171
|
+
/** The question to display to the user. */
|
|
237
172
|
readonly message: string;
|
|
238
|
-
/**
|
|
239
|
-
* Available choices. Plain strings and {@link Choice} objects can be mixed.
|
|
240
|
-
*/
|
|
173
|
+
/** Available choices. */
|
|
241
174
|
readonly choices: readonly (string | Choice)[];
|
|
242
|
-
/**
|
|
243
|
-
* Pre-selected choice value.
|
|
244
|
-
*/
|
|
175
|
+
/** Pre-selected choice value. */
|
|
245
176
|
readonly default?: string;
|
|
246
|
-
/**
|
|
247
|
-
* Override the prompt execution. When provided, this function is called
|
|
248
|
-
* instead of launching an interactive Inquirer.js prompt. Useful for
|
|
249
|
-
* testing.
|
|
250
|
-
*/
|
|
177
|
+
/** Override the prompt execution. Useful for testing. */
|
|
251
178
|
readonly prompter?: () => Promise<string>;
|
|
252
179
|
}
|
|
253
180
|
/**
|
|
@@ -257,49 +184,27 @@ interface RawlistConfig {
|
|
|
257
184
|
*/
|
|
258
185
|
interface ExpandConfig {
|
|
259
186
|
readonly type: "expand";
|
|
260
|
-
/**
|
|
261
|
-
* The question to display to the user.
|
|
262
|
-
*/
|
|
187
|
+
/** The question to display to the user. */
|
|
263
188
|
readonly message: string;
|
|
264
|
-
/**
|
|
265
|
-
* Available choices. Each choice requires a `key` field.
|
|
266
|
-
*/
|
|
189
|
+
/** Available choices. Each choice requires a `key` field. */
|
|
267
190
|
readonly choices: readonly ExpandChoice[];
|
|
268
|
-
/**
|
|
269
|
-
* Default choice key.
|
|
270
|
-
*/
|
|
191
|
+
/** Default choice key. */
|
|
271
192
|
readonly default?: string;
|
|
272
|
-
/**
|
|
273
|
-
* Override the prompt execution. When provided, this function is called
|
|
274
|
-
* instead of launching an interactive Inquirer.js prompt. Useful for
|
|
275
|
-
* testing.
|
|
276
|
-
*/
|
|
193
|
+
/** Override the prompt execution. Useful for testing. */
|
|
277
194
|
readonly prompter?: () => Promise<string>;
|
|
278
195
|
}
|
|
279
196
|
/**
|
|
280
197
|
* Configuration for a `checkbox` prompt (multi-select).
|
|
281
198
|
*
|
|
282
|
-
* Use with parsers that return `string[]`, typically via
|
|
283
|
-
* `multiple(option(...))`.
|
|
284
|
-
*
|
|
285
199
|
* @since 1.0.0
|
|
286
200
|
*/
|
|
287
201
|
interface CheckboxConfig {
|
|
288
202
|
readonly type: "checkbox";
|
|
289
|
-
/**
|
|
290
|
-
* The question to display to the user.
|
|
291
|
-
*/
|
|
203
|
+
/** The question to display to the user. */
|
|
292
204
|
readonly message: string;
|
|
293
|
-
/**
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
*/
|
|
297
|
-
readonly choices: readonly (string | Choice | Separator)[];
|
|
298
|
-
/**
|
|
299
|
-
* Override the prompt execution. When provided, this function is called
|
|
300
|
-
* instead of launching an interactive Inquirer.js prompt. Useful for
|
|
301
|
-
* testing.
|
|
302
|
-
*/
|
|
205
|
+
/** Available choices. */
|
|
206
|
+
readonly choices: readonly (string | CheckboxChoice | Separator)[];
|
|
207
|
+
/** Override the prompt execution. Useful for testing. */
|
|
303
208
|
readonly prompter?: () => Promise<readonly string[]>;
|
|
304
209
|
}
|
|
305
210
|
/**
|
|
@@ -311,13 +216,6 @@ type StringPromptConfig = InputConfig | PasswordConfig | EditorConfig | SelectCo
|
|
|
311
216
|
/**
|
|
312
217
|
* Type-safe prompt configuration for a given parser value type `T`.
|
|
313
218
|
*
|
|
314
|
-
* The available prompt types are constrained by the expected value type:
|
|
315
|
-
*
|
|
316
|
-
* - `boolean` or `boolean | undefined` → {@link ConfirmConfig}
|
|
317
|
-
* - `number` or `number | undefined` → {@link NumberPromptConfig}
|
|
318
|
-
* - `string` or `string | undefined` → {@link StringPromptConfig}
|
|
319
|
-
* - `readonly string[]` → {@link CheckboxConfig}
|
|
320
|
-
*
|
|
321
219
|
* @since 1.0.0
|
|
322
220
|
*/
|
|
323
221
|
type PromptConfig<T> = BasePromptConfig<Exclude<T, null | undefined>>;
|
|
@@ -325,33 +223,17 @@ type BasePromptConfig<T> = T extends boolean ? ConfirmConfig : T extends number
|
|
|
325
223
|
/**
|
|
326
224
|
* Wraps a parser with an interactive Inquirer.js prompt fallback.
|
|
327
225
|
*
|
|
328
|
-
* When the inner parser finds a value in the CLI arguments
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
* The returned parser always has `mode: "async"` because Inquirer.js prompts
|
|
333
|
-
* are inherently asynchronous.
|
|
334
|
-
*
|
|
335
|
-
* Example:
|
|
336
|
-
*
|
|
337
|
-
* ```typescript
|
|
338
|
-
* import { option } from "@optique/core/primitives";
|
|
339
|
-
* import { string } from "@optique/core/valueparser";
|
|
340
|
-
* import { prompt } from "@optique/inquirer";
|
|
341
|
-
*
|
|
342
|
-
* const nameParser = prompt(option("--name", string()), {
|
|
343
|
-
* type: "input",
|
|
344
|
-
* message: "Enter your name:",
|
|
345
|
-
* });
|
|
346
|
-
* ```
|
|
226
|
+
* When the inner parser finds a value in the CLI arguments, that value is used
|
|
227
|
+
* directly. When no CLI value is found, an interactive prompt is shown to the
|
|
228
|
+
* user.
|
|
347
229
|
*
|
|
348
230
|
* @param parser Inner parser that reads CLI values.
|
|
349
231
|
* @param config Type-safe Inquirer.js prompt configuration.
|
|
350
232
|
* @returns A parser with interactive prompt fallback, always in async mode.
|
|
351
|
-
* @throws {Error} If prompt execution fails with an unexpected error or if
|
|
352
|
-
*
|
|
233
|
+
* @throws {Error} If prompt execution fails with an unexpected error or if the
|
|
234
|
+
* inner parser throws while parsing or completing.
|
|
353
235
|
* @since 1.0.0
|
|
354
236
|
*/
|
|
355
237
|
declare function prompt<M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, config: PromptConfig<TValue>): FluentParser<"async", TValue, TState>;
|
|
356
238
|
//#endregion
|
|
357
|
-
export { CheckboxConfig, Choice, ConfirmConfig, EditorConfig, ExpandChoice, ExpandConfig, InputConfig, NumberPromptConfig, PasswordConfig, PromptConfig, RawlistConfig, SelectConfig, Separator, StringPromptConfig, prompt };
|
|
239
|
+
export { CheckboxChoice, CheckboxConfig, Choice, ConfirmConfig, EditorConfig, ExpandChoice, ExpandConfig, InputConfig, NumberPromptConfig, PasswordConfig, PromptConfig, RawlistConfig, SelectConfig, Separator, StringPromptConfig, prompt };
|
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,15 @@ interface Choice {
|
|
|
32
32
|
*/
|
|
33
33
|
readonly disabled?: boolean | string;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* A choice item for the `checkbox` prompt type.
|
|
37
|
+
*
|
|
38
|
+
* @since 1.2.0
|
|
39
|
+
*/
|
|
40
|
+
interface CheckboxChoice extends Choice {
|
|
41
|
+
/** Whether the choice is initially selected. */
|
|
42
|
+
readonly checked?: boolean;
|
|
43
|
+
}
|
|
35
44
|
/**
|
|
36
45
|
* A choice item for the `expand` prompt type.
|
|
37
46
|
*
|
|
@@ -61,19 +70,11 @@ interface ExpandChoice {
|
|
|
61
70
|
*/
|
|
62
71
|
interface ConfirmConfig {
|
|
63
72
|
readonly type: "confirm";
|
|
64
|
-
/**
|
|
65
|
-
* The question to display to the user.
|
|
66
|
-
*/
|
|
73
|
+
/** The question to display to the user. */
|
|
67
74
|
readonly message: string;
|
|
68
|
-
/**
|
|
69
|
-
* Default answer when the user just presses Enter.
|
|
70
|
-
*/
|
|
75
|
+
/** Default answer when the user just presses Enter. */
|
|
71
76
|
readonly default?: boolean;
|
|
72
|
-
/**
|
|
73
|
-
* Override the prompt execution. When provided, this function is called
|
|
74
|
-
* instead of launching an interactive Inquirer.js prompt. Useful for
|
|
75
|
-
* testing.
|
|
76
|
-
*/
|
|
77
|
+
/** Override the prompt execution. Useful for testing. */
|
|
77
78
|
readonly prompter?: () => Promise<boolean>;
|
|
78
79
|
}
|
|
79
80
|
/**
|
|
@@ -83,34 +84,17 @@ interface ConfirmConfig {
|
|
|
83
84
|
*/
|
|
84
85
|
interface NumberPromptConfig {
|
|
85
86
|
readonly type: "number";
|
|
86
|
-
/**
|
|
87
|
-
* The question to display to the user.
|
|
88
|
-
*/
|
|
87
|
+
/** The question to display to the user. */
|
|
89
88
|
readonly message: string;
|
|
90
|
-
/**
|
|
91
|
-
* Default number shown to the user.
|
|
92
|
-
*/
|
|
89
|
+
/** Default number shown to the user. */
|
|
93
90
|
readonly default?: number;
|
|
94
|
-
/**
|
|
95
|
-
* Minimum accepted value.
|
|
96
|
-
*/
|
|
91
|
+
/** Minimum accepted value. */
|
|
97
92
|
readonly min?: number;
|
|
98
|
-
/**
|
|
99
|
-
* Maximum accepted value.
|
|
100
|
-
*/
|
|
93
|
+
/** Maximum accepted value. */
|
|
101
94
|
readonly max?: number;
|
|
102
|
-
/**
|
|
103
|
-
* Granularity of valid values. Use `"any"` for arbitrary decimals.
|
|
104
|
-
*/
|
|
95
|
+
/** Granularity of valid values. Use `"any"` for arbitrary decimals. */
|
|
105
96
|
readonly step?: number | "any";
|
|
106
|
-
/**
|
|
107
|
-
* Override the prompt execution. When provided, this function is called
|
|
108
|
-
* instead of launching an interactive Inquirer.js prompt. Useful for
|
|
109
|
-
* testing.
|
|
110
|
-
*
|
|
111
|
-
* Return `undefined` to simulate the user leaving the field empty (which
|
|
112
|
-
* results in a parse failure).
|
|
113
|
-
*/
|
|
97
|
+
/** Override the prompt execution. Useful for testing. */
|
|
114
98
|
readonly prompter?: () => Promise<number | undefined>;
|
|
115
99
|
}
|
|
116
100
|
/**
|
|
@@ -120,24 +104,13 @@ interface NumberPromptConfig {
|
|
|
120
104
|
*/
|
|
121
105
|
interface InputConfig {
|
|
122
106
|
readonly type: "input";
|
|
123
|
-
/**
|
|
124
|
-
* The question to display to the user.
|
|
125
|
-
*/
|
|
107
|
+
/** The question to display to the user. */
|
|
126
108
|
readonly message: string;
|
|
127
|
-
/**
|
|
128
|
-
* Default text pre-filled in the prompt.
|
|
129
|
-
*/
|
|
109
|
+
/** Default text pre-filled in the prompt. */
|
|
130
110
|
readonly default?: string;
|
|
131
|
-
/**
|
|
132
|
-
* Validation function called when the user submits.
|
|
133
|
-
* Return `true` or a string error message.
|
|
134
|
-
*/
|
|
111
|
+
/** Validation function called when the user submits. */
|
|
135
112
|
readonly validate?: (value: string) => boolean | string | Promise<boolean | string>;
|
|
136
|
-
/**
|
|
137
|
-
* Override the prompt execution. When provided, this function is called
|
|
138
|
-
* instead of launching an interactive Inquirer.js prompt. Useful for
|
|
139
|
-
* testing.
|
|
140
|
-
*/
|
|
113
|
+
/** Override the prompt execution. Useful for testing. */
|
|
141
114
|
readonly prompter?: () => Promise<string>;
|
|
142
115
|
}
|
|
143
116
|
/**
|
|
@@ -147,54 +120,29 @@ interface InputConfig {
|
|
|
147
120
|
*/
|
|
148
121
|
interface PasswordConfig {
|
|
149
122
|
readonly type: "password";
|
|
150
|
-
/**
|
|
151
|
-
* The question to display to the user.
|
|
152
|
-
*/
|
|
123
|
+
/** The question to display to the user. */
|
|
153
124
|
readonly message: string;
|
|
154
|
-
/**
|
|
155
|
-
* If `true`, show `*` characters for each keystroke.
|
|
156
|
-
* If `false` or omitted, input is invisible.
|
|
157
|
-
*/
|
|
125
|
+
/** If `true`, show `*` characters for each keystroke. */
|
|
158
126
|
readonly mask?: boolean;
|
|
159
|
-
/**
|
|
160
|
-
* Validation function called when the user submits.
|
|
161
|
-
* Return `true` or a string error message.
|
|
162
|
-
*/
|
|
127
|
+
/** Validation function called when the user submits. */
|
|
163
128
|
readonly validate?: (value: string) => boolean | string | Promise<boolean | string>;
|
|
164
|
-
/**
|
|
165
|
-
* Override the prompt execution. When provided, this function is called
|
|
166
|
-
* instead of launching an interactive Inquirer.js prompt. Useful for
|
|
167
|
-
* testing.
|
|
168
|
-
*/
|
|
129
|
+
/** Override the prompt execution. Useful for testing. */
|
|
169
130
|
readonly prompter?: () => Promise<string>;
|
|
170
131
|
}
|
|
171
132
|
/**
|
|
172
133
|
* Configuration for an `editor` prompt (external editor).
|
|
173
134
|
*
|
|
174
|
-
* Opens the user's `$VISUAL` or `$EDITOR` for multi-line text input.
|
|
175
|
-
*
|
|
176
135
|
* @since 1.0.0
|
|
177
136
|
*/
|
|
178
137
|
interface EditorConfig {
|
|
179
138
|
readonly type: "editor";
|
|
180
|
-
/**
|
|
181
|
-
* The question to display to the user.
|
|
182
|
-
*/
|
|
139
|
+
/** The question to display to the user. */
|
|
183
140
|
readonly message: string;
|
|
184
|
-
/**
|
|
185
|
-
* Default content pre-filled in the editor.
|
|
186
|
-
*/
|
|
141
|
+
/** Default content pre-filled in the editor. */
|
|
187
142
|
readonly default?: string;
|
|
188
|
-
/**
|
|
189
|
-
* Validation function called when the editor is closed.
|
|
190
|
-
* Return `true` or a string error message.
|
|
191
|
-
*/
|
|
143
|
+
/** Validation function called when the editor is closed. */
|
|
192
144
|
readonly validate?: (value: string) => boolean | string | Promise<boolean | string>;
|
|
193
|
-
/**
|
|
194
|
-
* Override the prompt execution. When provided, this function is called
|
|
195
|
-
* instead of launching an interactive Inquirer.js prompt. Useful for
|
|
196
|
-
* testing.
|
|
197
|
-
*/
|
|
145
|
+
/** Override the prompt execution. Useful for testing. */
|
|
198
146
|
readonly prompter?: () => Promise<string>;
|
|
199
147
|
}
|
|
200
148
|
/**
|
|
@@ -204,24 +152,13 @@ interface EditorConfig {
|
|
|
204
152
|
*/
|
|
205
153
|
interface SelectConfig {
|
|
206
154
|
readonly type: "select";
|
|
207
|
-
/**
|
|
208
|
-
* The question to display to the user.
|
|
209
|
-
*/
|
|
155
|
+
/** The question to display to the user. */
|
|
210
156
|
readonly message: string;
|
|
211
|
-
/**
|
|
212
|
-
* Available choices. Plain strings and {@link Choice} objects can be mixed.
|
|
213
|
-
* Use `new Separator(...)` for visual dividers.
|
|
214
|
-
*/
|
|
157
|
+
/** Available choices. */
|
|
215
158
|
readonly choices: readonly (string | Choice | Separator)[];
|
|
216
|
-
/**
|
|
217
|
-
* Initially highlighted choice value.
|
|
218
|
-
*/
|
|
159
|
+
/** Initially highlighted choice value. */
|
|
219
160
|
readonly default?: string;
|
|
220
|
-
/**
|
|
221
|
-
* Override the prompt execution. When provided, this function is called
|
|
222
|
-
* instead of launching an interactive Inquirer.js prompt. Useful for
|
|
223
|
-
* testing.
|
|
224
|
-
*/
|
|
161
|
+
/** Override the prompt execution. Useful for testing. */
|
|
225
162
|
readonly prompter?: () => Promise<string>;
|
|
226
163
|
}
|
|
227
164
|
/**
|
|
@@ -231,23 +168,13 @@ interface SelectConfig {
|
|
|
231
168
|
*/
|
|
232
169
|
interface RawlistConfig {
|
|
233
170
|
readonly type: "rawlist";
|
|
234
|
-
/**
|
|
235
|
-
* The question to display to the user.
|
|
236
|
-
*/
|
|
171
|
+
/** The question to display to the user. */
|
|
237
172
|
readonly message: string;
|
|
238
|
-
/**
|
|
239
|
-
* Available choices. Plain strings and {@link Choice} objects can be mixed.
|
|
240
|
-
*/
|
|
173
|
+
/** Available choices. */
|
|
241
174
|
readonly choices: readonly (string | Choice)[];
|
|
242
|
-
/**
|
|
243
|
-
* Pre-selected choice value.
|
|
244
|
-
*/
|
|
175
|
+
/** Pre-selected choice value. */
|
|
245
176
|
readonly default?: string;
|
|
246
|
-
/**
|
|
247
|
-
* Override the prompt execution. When provided, this function is called
|
|
248
|
-
* instead of launching an interactive Inquirer.js prompt. Useful for
|
|
249
|
-
* testing.
|
|
250
|
-
*/
|
|
177
|
+
/** Override the prompt execution. Useful for testing. */
|
|
251
178
|
readonly prompter?: () => Promise<string>;
|
|
252
179
|
}
|
|
253
180
|
/**
|
|
@@ -257,49 +184,27 @@ interface RawlistConfig {
|
|
|
257
184
|
*/
|
|
258
185
|
interface ExpandConfig {
|
|
259
186
|
readonly type: "expand";
|
|
260
|
-
/**
|
|
261
|
-
* The question to display to the user.
|
|
262
|
-
*/
|
|
187
|
+
/** The question to display to the user. */
|
|
263
188
|
readonly message: string;
|
|
264
|
-
/**
|
|
265
|
-
* Available choices. Each choice requires a `key` field.
|
|
266
|
-
*/
|
|
189
|
+
/** Available choices. Each choice requires a `key` field. */
|
|
267
190
|
readonly choices: readonly ExpandChoice[];
|
|
268
|
-
/**
|
|
269
|
-
* Default choice key.
|
|
270
|
-
*/
|
|
191
|
+
/** Default choice key. */
|
|
271
192
|
readonly default?: string;
|
|
272
|
-
/**
|
|
273
|
-
* Override the prompt execution. When provided, this function is called
|
|
274
|
-
* instead of launching an interactive Inquirer.js prompt. Useful for
|
|
275
|
-
* testing.
|
|
276
|
-
*/
|
|
193
|
+
/** Override the prompt execution. Useful for testing. */
|
|
277
194
|
readonly prompter?: () => Promise<string>;
|
|
278
195
|
}
|
|
279
196
|
/**
|
|
280
197
|
* Configuration for a `checkbox` prompt (multi-select).
|
|
281
198
|
*
|
|
282
|
-
* Use with parsers that return `string[]`, typically via
|
|
283
|
-
* `multiple(option(...))`.
|
|
284
|
-
*
|
|
285
199
|
* @since 1.0.0
|
|
286
200
|
*/
|
|
287
201
|
interface CheckboxConfig {
|
|
288
202
|
readonly type: "checkbox";
|
|
289
|
-
/**
|
|
290
|
-
* The question to display to the user.
|
|
291
|
-
*/
|
|
203
|
+
/** The question to display to the user. */
|
|
292
204
|
readonly message: string;
|
|
293
|
-
/**
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
*/
|
|
297
|
-
readonly choices: readonly (string | Choice | Separator)[];
|
|
298
|
-
/**
|
|
299
|
-
* Override the prompt execution. When provided, this function is called
|
|
300
|
-
* instead of launching an interactive Inquirer.js prompt. Useful for
|
|
301
|
-
* testing.
|
|
302
|
-
*/
|
|
205
|
+
/** Available choices. */
|
|
206
|
+
readonly choices: readonly (string | CheckboxChoice | Separator)[];
|
|
207
|
+
/** Override the prompt execution. Useful for testing. */
|
|
303
208
|
readonly prompter?: () => Promise<readonly string[]>;
|
|
304
209
|
}
|
|
305
210
|
/**
|
|
@@ -311,13 +216,6 @@ type StringPromptConfig = InputConfig | PasswordConfig | EditorConfig | SelectCo
|
|
|
311
216
|
/**
|
|
312
217
|
* Type-safe prompt configuration for a given parser value type `T`.
|
|
313
218
|
*
|
|
314
|
-
* The available prompt types are constrained by the expected value type:
|
|
315
|
-
*
|
|
316
|
-
* - `boolean` or `boolean | undefined` → {@link ConfirmConfig}
|
|
317
|
-
* - `number` or `number | undefined` → {@link NumberPromptConfig}
|
|
318
|
-
* - `string` or `string | undefined` → {@link StringPromptConfig}
|
|
319
|
-
* - `readonly string[]` → {@link CheckboxConfig}
|
|
320
|
-
*
|
|
321
219
|
* @since 1.0.0
|
|
322
220
|
*/
|
|
323
221
|
type PromptConfig<T> = BasePromptConfig<Exclude<T, null | undefined>>;
|
|
@@ -325,33 +223,17 @@ type BasePromptConfig<T> = T extends boolean ? ConfirmConfig : T extends number
|
|
|
325
223
|
/**
|
|
326
224
|
* Wraps a parser with an interactive Inquirer.js prompt fallback.
|
|
327
225
|
*
|
|
328
|
-
* When the inner parser finds a value in the CLI arguments
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
* The returned parser always has `mode: "async"` because Inquirer.js prompts
|
|
333
|
-
* are inherently asynchronous.
|
|
334
|
-
*
|
|
335
|
-
* Example:
|
|
336
|
-
*
|
|
337
|
-
* ```typescript
|
|
338
|
-
* import { option } from "@optique/core/primitives";
|
|
339
|
-
* import { string } from "@optique/core/valueparser";
|
|
340
|
-
* import { prompt } from "@optique/inquirer";
|
|
341
|
-
*
|
|
342
|
-
* const nameParser = prompt(option("--name", string()), {
|
|
343
|
-
* type: "input",
|
|
344
|
-
* message: "Enter your name:",
|
|
345
|
-
* });
|
|
346
|
-
* ```
|
|
226
|
+
* When the inner parser finds a value in the CLI arguments, that value is used
|
|
227
|
+
* directly. When no CLI value is found, an interactive prompt is shown to the
|
|
228
|
+
* user.
|
|
347
229
|
*
|
|
348
230
|
* @param parser Inner parser that reads CLI values.
|
|
349
231
|
* @param config Type-safe Inquirer.js prompt configuration.
|
|
350
232
|
* @returns A parser with interactive prompt fallback, always in async mode.
|
|
351
|
-
* @throws {Error} If prompt execution fails with an unexpected error or if
|
|
352
|
-
*
|
|
233
|
+
* @throws {Error} If prompt execution fails with an unexpected error or if the
|
|
234
|
+
* inner parser throws while parsing or completing.
|
|
353
235
|
* @since 1.0.0
|
|
354
236
|
*/
|
|
355
237
|
declare function prompt<M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, config: PromptConfig<TValue>): FluentParser<"async", TValue, TState>;
|
|
356
238
|
//#endregion
|
|
357
|
-
export { CheckboxConfig, Choice, ConfirmConfig, EditorConfig, ExpandChoice, ExpandConfig, InputConfig, NumberPromptConfig, PasswordConfig, PromptConfig, RawlistConfig, SelectConfig, Separator, StringPromptConfig, prompt };
|
|
239
|
+
export { CheckboxChoice, CheckboxConfig, Choice, ConfirmConfig, EditorConfig, ExpandChoice, ExpandConfig, InputConfig, NumberPromptConfig, PasswordConfig, PromptConfig, RawlistConfig, SelectConfig, Separator, StringPromptConfig, prompt };
|