@optique/inquirer 1.3.0-dev.2468 → 1.3.0-dev.2469
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/index.cjs +23 -15
- package/dist/index.d.cts +54 -22
- package/dist/index.d.ts +54 -22
- package/dist/index.js +24 -16
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
}) : target, mod));
|
|
22
22
|
|
|
23
23
|
//#endregion
|
|
24
|
+
const node_process = __toESM(require("node:process"));
|
|
24
25
|
const __inquirer_prompts = __toESM(require("@inquirer/prompts"));
|
|
25
26
|
const __optique_core_message = __toESM(require("@optique/core/message"));
|
|
26
27
|
const __optique_prompt = __toESM(require("@optique/prompt"));
|
|
@@ -64,7 +65,7 @@ function getPromptFunctions() {
|
|
|
64
65
|
} : defaultPromptFunctions;
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
|
-
* Determines whether an error came from an interrupted Inquirer prompt.
|
|
68
|
+
* Determines whether an error came from an interrupted Inquirer.js prompt.
|
|
68
69
|
*/
|
|
69
70
|
function isExitPromptError(error) {
|
|
70
71
|
return typeof error === "object" && error != null && "name" in error && error.name === "ExitPromptError";
|
|
@@ -85,35 +86,40 @@ const validPromptTypes = new Set([
|
|
|
85
86
|
*
|
|
86
87
|
* When the inner parser finds a value in the CLI arguments, that value is used
|
|
87
88
|
* directly. When no CLI value is found, an interactive prompt is shown to the
|
|
88
|
-
* user.
|
|
89
|
+
* user. If the supplied signal is aborted, parsing rejects with the signal's
|
|
90
|
+
* reason.
|
|
89
91
|
*
|
|
90
92
|
* @param parser Inner parser that reads CLI values.
|
|
91
93
|
* @param config Type-safe Inquirer.js prompt configuration, or a
|
|
92
94
|
* configuration derived from dependency sources via
|
|
93
95
|
* `derivePromptConfig()`.
|
|
96
|
+
* @param options Shared validation, retry, and abort options for the
|
|
97
|
+
* interactive fallback.
|
|
94
98
|
* @returns A parser with interactive prompt fallback, always in async mode.
|
|
99
|
+
* @throws {RangeError} If `options.maxAttempts` is not a positive integer.
|
|
95
100
|
* @throws {Error} If prompt execution fails with an unexpected error or if the
|
|
96
101
|
* inner parser throws while parsing or completing.
|
|
97
102
|
* @since 1.0.0
|
|
103
|
+
* @since 1.3.0 Added the `options` parameter.
|
|
98
104
|
*/
|
|
99
|
-
function prompt(parser, config) {
|
|
105
|
+
function prompt(parser, config, options) {
|
|
100
106
|
const promptWithAdapter = (0, __optique_prompt.createPromptAdapter)({
|
|
101
107
|
execute: executePromptRaw,
|
|
102
108
|
getDefaultValue: getConfigDefault
|
|
103
109
|
});
|
|
104
|
-
return promptWithAdapter(parser, config);
|
|
110
|
+
return promptWithAdapter(parser, config, options);
|
|
105
111
|
}
|
|
106
112
|
function getConfigDefault(config) {
|
|
107
113
|
if (config != null && typeof config === "object" && "default" in config) return config.default;
|
|
108
114
|
return void 0;
|
|
109
115
|
}
|
|
110
|
-
async function executePromptRaw(config) {
|
|
116
|
+
async function executePromptRaw(config, context) {
|
|
111
117
|
const cfg = config;
|
|
112
118
|
const prompts = getPromptFunctions();
|
|
113
119
|
try {
|
|
114
120
|
if (!validPromptTypes.has(cfg.type)) throw new TypeError(`Unsupported prompt type: ${String(cfg.type)}.`);
|
|
115
121
|
if ("prompter" in cfg && cfg.prompter != null) {
|
|
116
|
-
const value = await cfg.prompter();
|
|
122
|
+
const value = await cfg.prompter(context);
|
|
117
123
|
if (cfg.type === "number" && value === void 0) return {
|
|
118
124
|
success: false,
|
|
119
125
|
error: __optique_core_message.message`No number provided.`
|
|
@@ -123,13 +129,15 @@ async function executePromptRaw(config) {
|
|
|
123
129
|
value
|
|
124
130
|
};
|
|
125
131
|
}
|
|
132
|
+
if (context.previousValidationMessage !== void 0) node_process.default.stderr.write((0, __optique_core_message.formatMessage)(context.previousValidationMessage) + "\n");
|
|
133
|
+
const inquirerContext = { ...context.signal === void 0 ? {} : { signal: context.signal } };
|
|
126
134
|
switch (cfg.type) {
|
|
127
135
|
case "confirm": return {
|
|
128
136
|
success: true,
|
|
129
137
|
value: await prompts.confirm({
|
|
130
138
|
message: cfg.message,
|
|
131
139
|
...cfg.default !== void 0 ? { default: cfg.default } : {}
|
|
132
|
-
})
|
|
140
|
+
}, inquirerContext)
|
|
133
141
|
};
|
|
134
142
|
case "number": {
|
|
135
143
|
const numResult = await prompts.number({
|
|
@@ -138,7 +146,7 @@ async function executePromptRaw(config) {
|
|
|
138
146
|
...cfg.min !== void 0 ? { min: cfg.min } : {},
|
|
139
147
|
...cfg.max !== void 0 ? { max: cfg.max } : {},
|
|
140
148
|
...cfg.step !== void 0 ? { step: cfg.step } : {}
|
|
141
|
-
});
|
|
149
|
+
}, inquirerContext);
|
|
142
150
|
if (numResult === void 0) return {
|
|
143
151
|
success: false,
|
|
144
152
|
error: __optique_core_message.message`No number provided.`
|
|
@@ -154,7 +162,7 @@ async function executePromptRaw(config) {
|
|
|
154
162
|
message: cfg.message,
|
|
155
163
|
...cfg.default !== void 0 ? { default: cfg.default } : {},
|
|
156
164
|
...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
|
|
157
|
-
})
|
|
165
|
+
}, inquirerContext)
|
|
158
166
|
};
|
|
159
167
|
case "password": return {
|
|
160
168
|
success: true,
|
|
@@ -162,7 +170,7 @@ async function executePromptRaw(config) {
|
|
|
162
170
|
message: cfg.message,
|
|
163
171
|
...cfg.mask !== void 0 ? { mask: cfg.mask } : {},
|
|
164
172
|
...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
|
|
165
|
-
})
|
|
173
|
+
}, inquirerContext)
|
|
166
174
|
};
|
|
167
175
|
case "editor": return {
|
|
168
176
|
success: true,
|
|
@@ -170,7 +178,7 @@ async function executePromptRaw(config) {
|
|
|
170
178
|
message: cfg.message,
|
|
171
179
|
...cfg.default !== void 0 ? { default: cfg.default } : {},
|
|
172
180
|
...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
|
|
173
|
-
})
|
|
181
|
+
}, inquirerContext)
|
|
174
182
|
};
|
|
175
183
|
case "select": return {
|
|
176
184
|
success: true,
|
|
@@ -178,7 +186,7 @@ async function executePromptRaw(config) {
|
|
|
178
186
|
message: cfg.message,
|
|
179
187
|
choices: normalizeChoices(cfg.choices),
|
|
180
188
|
...cfg.default !== void 0 ? { default: cfg.default } : {}
|
|
181
|
-
})
|
|
189
|
+
}, inquirerContext)
|
|
182
190
|
};
|
|
183
191
|
case "rawlist": return {
|
|
184
192
|
success: true,
|
|
@@ -186,7 +194,7 @@ async function executePromptRaw(config) {
|
|
|
186
194
|
message: cfg.message,
|
|
187
195
|
choices: normalizeChoices(cfg.choices),
|
|
188
196
|
...cfg.default !== void 0 ? { default: cfg.default } : {}
|
|
189
|
-
})
|
|
197
|
+
}, inquirerContext)
|
|
190
198
|
};
|
|
191
199
|
case "expand": return {
|
|
192
200
|
success: true,
|
|
@@ -194,14 +202,14 @@ async function executePromptRaw(config) {
|
|
|
194
202
|
message: cfg.message,
|
|
195
203
|
choices: cfg.choices,
|
|
196
204
|
...cfg.default !== void 0 ? { default: cfg.default } : {}
|
|
197
|
-
})
|
|
205
|
+
}, inquirerContext)
|
|
198
206
|
};
|
|
199
207
|
case "checkbox": return {
|
|
200
208
|
success: true,
|
|
201
209
|
value: await prompts.checkbox({
|
|
202
210
|
message: cfg.message,
|
|
203
211
|
choices: normalizeChoices(cfg.choices)
|
|
204
|
-
})
|
|
212
|
+
}, inquirerContext)
|
|
205
213
|
};
|
|
206
214
|
}
|
|
207
215
|
} catch (error) {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Separator } from "@inquirer/prompts";
|
|
2
2
|
import { FluentParser } from "@optique/core/fluent";
|
|
3
3
|
import { Mode, Parser } from "@optique/core/parser";
|
|
4
|
-
import { DerivePromptConfigContext, DerivePromptConfigOptions, DerivePromptConfigsContext, DerivePromptConfigsOptions, DerivedPromptConfig, DerivedPromptConfig as DerivedPromptConfig$1, PromptCondition, derivePromptConfig, isDerivedPromptConfig } from "@optique/prompt";
|
|
4
|
+
import { DerivePromptConfigContext, DerivePromptConfigOptions, DerivePromptConfigsContext, DerivePromptConfigsOptions, DerivedPromptConfig, DerivedPromptConfig as DerivedPromptConfig$1, PromptCondition, PromptExecutionContext, PromptExecutionContext as PromptExecutionContext$1, PromptOptions, PromptOptions as PromptOptions$1, PromptValidator, derivePromptConfig, isDerivedPromptConfig } from "@optique/prompt";
|
|
5
5
|
|
|
6
6
|
//#region src/index.d.ts
|
|
7
7
|
|
|
@@ -75,8 +75,11 @@ interface ConfirmConfig {
|
|
|
75
75
|
readonly message: string;
|
|
76
76
|
/** Default answer when the user just presses Enter. */
|
|
77
77
|
readonly default?: boolean;
|
|
78
|
-
/**
|
|
79
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Override the prompt execution. Useful for testing.
|
|
80
|
+
* @since 1.3.0 The callback receives the current attempt context.
|
|
81
|
+
*/
|
|
82
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<boolean>;
|
|
80
83
|
}
|
|
81
84
|
/**
|
|
82
85
|
* Configuration for a `number` prompt.
|
|
@@ -95,8 +98,11 @@ interface NumberPromptConfig {
|
|
|
95
98
|
readonly max?: number;
|
|
96
99
|
/** Granularity of valid values. Use `"any"` for arbitrary decimals. */
|
|
97
100
|
readonly step?: number | "any";
|
|
98
|
-
/**
|
|
99
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Override the prompt execution. Useful for testing.
|
|
103
|
+
* @since 1.3.0 The callback receives the current attempt context.
|
|
104
|
+
*/
|
|
105
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<number | undefined>;
|
|
100
106
|
}
|
|
101
107
|
/**
|
|
102
108
|
* Configuration for an `input` prompt (free-text string).
|
|
@@ -111,8 +117,11 @@ interface InputConfig {
|
|
|
111
117
|
readonly default?: string;
|
|
112
118
|
/** Validation function called when the user submits. */
|
|
113
119
|
readonly validate?: (value: string) => boolean | string | Promise<boolean | string>;
|
|
114
|
-
/**
|
|
115
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Override the prompt execution. Useful for testing.
|
|
122
|
+
* @since 1.3.0 The callback receives the current attempt context.
|
|
123
|
+
*/
|
|
124
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<string>;
|
|
116
125
|
}
|
|
117
126
|
/**
|
|
118
127
|
* Configuration for a `password` prompt (masked input).
|
|
@@ -127,8 +136,11 @@ interface PasswordConfig {
|
|
|
127
136
|
readonly mask?: boolean;
|
|
128
137
|
/** Validation function called when the user submits. */
|
|
129
138
|
readonly validate?: (value: string) => boolean | string | Promise<boolean | string>;
|
|
130
|
-
/**
|
|
131
|
-
|
|
139
|
+
/**
|
|
140
|
+
* Override the prompt execution. Useful for testing.
|
|
141
|
+
* @since 1.3.0 The callback receives the current attempt context.
|
|
142
|
+
*/
|
|
143
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<string>;
|
|
132
144
|
}
|
|
133
145
|
/**
|
|
134
146
|
* Configuration for an `editor` prompt (external editor).
|
|
@@ -143,8 +155,11 @@ interface EditorConfig {
|
|
|
143
155
|
readonly default?: string;
|
|
144
156
|
/** Validation function called when the editor is closed. */
|
|
145
157
|
readonly validate?: (value: string) => boolean | string | Promise<boolean | string>;
|
|
146
|
-
/**
|
|
147
|
-
|
|
158
|
+
/**
|
|
159
|
+
* Override the prompt execution. Useful for testing.
|
|
160
|
+
* @since 1.3.0 The callback receives the current attempt context.
|
|
161
|
+
*/
|
|
162
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<string>;
|
|
148
163
|
}
|
|
149
164
|
/**
|
|
150
165
|
* Configuration for a `select` prompt (arrow-key single-select).
|
|
@@ -159,8 +174,11 @@ interface SelectConfig {
|
|
|
159
174
|
readonly choices: readonly (string | Choice | Separator)[];
|
|
160
175
|
/** Initially highlighted choice value. */
|
|
161
176
|
readonly default?: string;
|
|
162
|
-
/**
|
|
163
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Override the prompt execution. Useful for testing.
|
|
179
|
+
* @since 1.3.0 The callback receives the current attempt context.
|
|
180
|
+
*/
|
|
181
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<string>;
|
|
164
182
|
}
|
|
165
183
|
/**
|
|
166
184
|
* Configuration for a `rawlist` prompt (numbered list).
|
|
@@ -175,8 +193,11 @@ interface RawlistConfig {
|
|
|
175
193
|
readonly choices: readonly (string | Choice)[];
|
|
176
194
|
/** Pre-selected choice value. */
|
|
177
195
|
readonly default?: string;
|
|
178
|
-
/**
|
|
179
|
-
|
|
196
|
+
/**
|
|
197
|
+
* Override the prompt execution. Useful for testing.
|
|
198
|
+
* @since 1.3.0 The callback receives the current attempt context.
|
|
199
|
+
*/
|
|
200
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<string>;
|
|
180
201
|
}
|
|
181
202
|
/**
|
|
182
203
|
* Configuration for an `expand` prompt (keyboard shortcut single-select).
|
|
@@ -191,8 +212,11 @@ interface ExpandConfig {
|
|
|
191
212
|
readonly choices: readonly ExpandChoice[];
|
|
192
213
|
/** Default choice key. */
|
|
193
214
|
readonly default?: string;
|
|
194
|
-
/**
|
|
195
|
-
|
|
215
|
+
/**
|
|
216
|
+
* Override the prompt execution. Useful for testing.
|
|
217
|
+
* @since 1.3.0 The callback receives the current attempt context.
|
|
218
|
+
*/
|
|
219
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<string>;
|
|
196
220
|
}
|
|
197
221
|
/**
|
|
198
222
|
* Configuration for a `checkbox` prompt (multi-select).
|
|
@@ -205,8 +229,11 @@ interface CheckboxConfig {
|
|
|
205
229
|
readonly message: string;
|
|
206
230
|
/** Available choices. */
|
|
207
231
|
readonly choices: readonly (string | CheckboxChoice | Separator)[];
|
|
208
|
-
/**
|
|
209
|
-
|
|
232
|
+
/**
|
|
233
|
+
* Override the prompt execution. Useful for testing.
|
|
234
|
+
* @since 1.3.0 The callback receives the current attempt context.
|
|
235
|
+
*/
|
|
236
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<readonly string[]>;
|
|
210
237
|
}
|
|
211
238
|
/**
|
|
212
239
|
* A union of all string-input prompt configurations.
|
|
@@ -239,17 +266,22 @@ type RuntimePromptConfig = ConfirmConfig | NumberPromptConfig | StringPromptConf
|
|
|
239
266
|
*
|
|
240
267
|
* When the inner parser finds a value in the CLI arguments, that value is used
|
|
241
268
|
* directly. When no CLI value is found, an interactive prompt is shown to the
|
|
242
|
-
* user.
|
|
269
|
+
* user. If the supplied signal is aborted, parsing rejects with the signal's
|
|
270
|
+
* reason.
|
|
243
271
|
*
|
|
244
272
|
* @param parser Inner parser that reads CLI values.
|
|
245
273
|
* @param config Type-safe Inquirer.js prompt configuration, or a
|
|
246
274
|
* configuration derived from dependency sources via
|
|
247
275
|
* `derivePromptConfig()`.
|
|
276
|
+
* @param options Shared validation, retry, and abort options for the
|
|
277
|
+
* interactive fallback.
|
|
248
278
|
* @returns A parser with interactive prompt fallback, always in async mode.
|
|
279
|
+
* @throws {RangeError} If `options.maxAttempts` is not a positive integer.
|
|
249
280
|
* @throws {Error} If prompt execution fails with an unexpected error or if the
|
|
250
281
|
* inner parser throws while parsing or completing.
|
|
251
282
|
* @since 1.0.0
|
|
283
|
+
* @since 1.3.0 Added the `options` parameter.
|
|
252
284
|
*/
|
|
253
|
-
declare function prompt<M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, config: PromptConfig<TValue> | DerivedPromptConfig$1<RuntimePromptConfig, NoInfer<TValue>>): FluentParser<"async", TValue, TState>;
|
|
285
|
+
declare function prompt<M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, config: PromptConfig<TValue> | DerivedPromptConfig$1<RuntimePromptConfig, NoInfer<TValue>>, options?: PromptOptions$1<NoInfer<TValue>>): FluentParser<"async", TValue, TState>;
|
|
254
286
|
//#endregion
|
|
255
|
-
export { CheckboxChoice, CheckboxConfig, Choice, ConfirmConfig, type DerivePromptConfigContext, type DerivePromptConfigOptions, type DerivePromptConfigsContext, type DerivePromptConfigsOptions, type DerivedPromptConfig, EditorConfig, ExpandChoice, ExpandConfig, InputConfig, NumberPromptConfig, PasswordConfig, PromptConfig, RawlistConfig, RuntimePromptConfig, SelectConfig, Separator, StringPromptConfig, derivePromptConfig, isDerivedPromptConfig, prompt };
|
|
287
|
+
export { CheckboxChoice, CheckboxConfig, Choice, ConfirmConfig, type DerivePromptConfigContext, type DerivePromptConfigOptions, type DerivePromptConfigsContext, type DerivePromptConfigsOptions, type DerivedPromptConfig, EditorConfig, ExpandChoice, ExpandConfig, InputConfig, NumberPromptConfig, PasswordConfig, PromptConfig, type PromptExecutionContext, type PromptOptions, type PromptValidator, RawlistConfig, RuntimePromptConfig, SelectConfig, Separator, StringPromptConfig, derivePromptConfig, isDerivedPromptConfig, prompt };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Separator } from "@inquirer/prompts";
|
|
2
|
-
import { DerivePromptConfigContext, DerivePromptConfigOptions, DerivePromptConfigsContext, DerivePromptConfigsOptions, DerivedPromptConfig, DerivedPromptConfig as DerivedPromptConfig$1, PromptCondition, derivePromptConfig, isDerivedPromptConfig } from "@optique/prompt";
|
|
2
|
+
import { DerivePromptConfigContext, DerivePromptConfigOptions, DerivePromptConfigsContext, DerivePromptConfigsOptions, DerivedPromptConfig, DerivedPromptConfig as DerivedPromptConfig$1, PromptCondition, PromptExecutionContext, PromptExecutionContext as PromptExecutionContext$1, PromptOptions, PromptOptions as PromptOptions$1, PromptValidator, derivePromptConfig, isDerivedPromptConfig } from "@optique/prompt";
|
|
3
3
|
import { FluentParser } from "@optique/core/fluent";
|
|
4
4
|
import { Mode, Parser } from "@optique/core/parser";
|
|
5
5
|
|
|
@@ -75,8 +75,11 @@ interface ConfirmConfig {
|
|
|
75
75
|
readonly message: string;
|
|
76
76
|
/** Default answer when the user just presses Enter. */
|
|
77
77
|
readonly default?: boolean;
|
|
78
|
-
/**
|
|
79
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Override the prompt execution. Useful for testing.
|
|
80
|
+
* @since 1.3.0 The callback receives the current attempt context.
|
|
81
|
+
*/
|
|
82
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<boolean>;
|
|
80
83
|
}
|
|
81
84
|
/**
|
|
82
85
|
* Configuration for a `number` prompt.
|
|
@@ -95,8 +98,11 @@ interface NumberPromptConfig {
|
|
|
95
98
|
readonly max?: number;
|
|
96
99
|
/** Granularity of valid values. Use `"any"` for arbitrary decimals. */
|
|
97
100
|
readonly step?: number | "any";
|
|
98
|
-
/**
|
|
99
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Override the prompt execution. Useful for testing.
|
|
103
|
+
* @since 1.3.0 The callback receives the current attempt context.
|
|
104
|
+
*/
|
|
105
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<number | undefined>;
|
|
100
106
|
}
|
|
101
107
|
/**
|
|
102
108
|
* Configuration for an `input` prompt (free-text string).
|
|
@@ -111,8 +117,11 @@ interface InputConfig {
|
|
|
111
117
|
readonly default?: string;
|
|
112
118
|
/** Validation function called when the user submits. */
|
|
113
119
|
readonly validate?: (value: string) => boolean | string | Promise<boolean | string>;
|
|
114
|
-
/**
|
|
115
|
-
|
|
120
|
+
/**
|
|
121
|
+
* Override the prompt execution. Useful for testing.
|
|
122
|
+
* @since 1.3.0 The callback receives the current attempt context.
|
|
123
|
+
*/
|
|
124
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<string>;
|
|
116
125
|
}
|
|
117
126
|
/**
|
|
118
127
|
* Configuration for a `password` prompt (masked input).
|
|
@@ -127,8 +136,11 @@ interface PasswordConfig {
|
|
|
127
136
|
readonly mask?: boolean;
|
|
128
137
|
/** Validation function called when the user submits. */
|
|
129
138
|
readonly validate?: (value: string) => boolean | string | Promise<boolean | string>;
|
|
130
|
-
/**
|
|
131
|
-
|
|
139
|
+
/**
|
|
140
|
+
* Override the prompt execution. Useful for testing.
|
|
141
|
+
* @since 1.3.0 The callback receives the current attempt context.
|
|
142
|
+
*/
|
|
143
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<string>;
|
|
132
144
|
}
|
|
133
145
|
/**
|
|
134
146
|
* Configuration for an `editor` prompt (external editor).
|
|
@@ -143,8 +155,11 @@ interface EditorConfig {
|
|
|
143
155
|
readonly default?: string;
|
|
144
156
|
/** Validation function called when the editor is closed. */
|
|
145
157
|
readonly validate?: (value: string) => boolean | string | Promise<boolean | string>;
|
|
146
|
-
/**
|
|
147
|
-
|
|
158
|
+
/**
|
|
159
|
+
* Override the prompt execution. Useful for testing.
|
|
160
|
+
* @since 1.3.0 The callback receives the current attempt context.
|
|
161
|
+
*/
|
|
162
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<string>;
|
|
148
163
|
}
|
|
149
164
|
/**
|
|
150
165
|
* Configuration for a `select` prompt (arrow-key single-select).
|
|
@@ -159,8 +174,11 @@ interface SelectConfig {
|
|
|
159
174
|
readonly choices: readonly (string | Choice | Separator)[];
|
|
160
175
|
/** Initially highlighted choice value. */
|
|
161
176
|
readonly default?: string;
|
|
162
|
-
/**
|
|
163
|
-
|
|
177
|
+
/**
|
|
178
|
+
* Override the prompt execution. Useful for testing.
|
|
179
|
+
* @since 1.3.0 The callback receives the current attempt context.
|
|
180
|
+
*/
|
|
181
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<string>;
|
|
164
182
|
}
|
|
165
183
|
/**
|
|
166
184
|
* Configuration for a `rawlist` prompt (numbered list).
|
|
@@ -175,8 +193,11 @@ interface RawlistConfig {
|
|
|
175
193
|
readonly choices: readonly (string | Choice)[];
|
|
176
194
|
/** Pre-selected choice value. */
|
|
177
195
|
readonly default?: string;
|
|
178
|
-
/**
|
|
179
|
-
|
|
196
|
+
/**
|
|
197
|
+
* Override the prompt execution. Useful for testing.
|
|
198
|
+
* @since 1.3.0 The callback receives the current attempt context.
|
|
199
|
+
*/
|
|
200
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<string>;
|
|
180
201
|
}
|
|
181
202
|
/**
|
|
182
203
|
* Configuration for an `expand` prompt (keyboard shortcut single-select).
|
|
@@ -191,8 +212,11 @@ interface ExpandConfig {
|
|
|
191
212
|
readonly choices: readonly ExpandChoice[];
|
|
192
213
|
/** Default choice key. */
|
|
193
214
|
readonly default?: string;
|
|
194
|
-
/**
|
|
195
|
-
|
|
215
|
+
/**
|
|
216
|
+
* Override the prompt execution. Useful for testing.
|
|
217
|
+
* @since 1.3.0 The callback receives the current attempt context.
|
|
218
|
+
*/
|
|
219
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<string>;
|
|
196
220
|
}
|
|
197
221
|
/**
|
|
198
222
|
* Configuration for a `checkbox` prompt (multi-select).
|
|
@@ -205,8 +229,11 @@ interface CheckboxConfig {
|
|
|
205
229
|
readonly message: string;
|
|
206
230
|
/** Available choices. */
|
|
207
231
|
readonly choices: readonly (string | CheckboxChoice | Separator)[];
|
|
208
|
-
/**
|
|
209
|
-
|
|
232
|
+
/**
|
|
233
|
+
* Override the prompt execution. Useful for testing.
|
|
234
|
+
* @since 1.3.0 The callback receives the current attempt context.
|
|
235
|
+
*/
|
|
236
|
+
readonly prompter?: (context: PromptExecutionContext$1) => Promise<readonly string[]>;
|
|
210
237
|
}
|
|
211
238
|
/**
|
|
212
239
|
* A union of all string-input prompt configurations.
|
|
@@ -239,17 +266,22 @@ type RuntimePromptConfig = ConfirmConfig | NumberPromptConfig | StringPromptConf
|
|
|
239
266
|
*
|
|
240
267
|
* When the inner parser finds a value in the CLI arguments, that value is used
|
|
241
268
|
* directly. When no CLI value is found, an interactive prompt is shown to the
|
|
242
|
-
* user.
|
|
269
|
+
* user. If the supplied signal is aborted, parsing rejects with the signal's
|
|
270
|
+
* reason.
|
|
243
271
|
*
|
|
244
272
|
* @param parser Inner parser that reads CLI values.
|
|
245
273
|
* @param config Type-safe Inquirer.js prompt configuration, or a
|
|
246
274
|
* configuration derived from dependency sources via
|
|
247
275
|
* `derivePromptConfig()`.
|
|
276
|
+
* @param options Shared validation, retry, and abort options for the
|
|
277
|
+
* interactive fallback.
|
|
248
278
|
* @returns A parser with interactive prompt fallback, always in async mode.
|
|
279
|
+
* @throws {RangeError} If `options.maxAttempts` is not a positive integer.
|
|
249
280
|
* @throws {Error} If prompt execution fails with an unexpected error or if the
|
|
250
281
|
* inner parser throws while parsing or completing.
|
|
251
282
|
* @since 1.0.0
|
|
283
|
+
* @since 1.3.0 Added the `options` parameter.
|
|
252
284
|
*/
|
|
253
|
-
declare function prompt<M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, config: PromptConfig<TValue> | DerivedPromptConfig$1<RuntimePromptConfig, NoInfer<TValue>>): FluentParser<"async", TValue, TState>;
|
|
285
|
+
declare function prompt<M extends Mode, TValue, TState>(parser: Parser<M, TValue, TState>, config: PromptConfig<TValue> | DerivedPromptConfig$1<RuntimePromptConfig, NoInfer<TValue>>, options?: PromptOptions$1<NoInfer<TValue>>): FluentParser<"async", TValue, TState>;
|
|
254
286
|
//#endregion
|
|
255
|
-
export { CheckboxChoice, CheckboxConfig, Choice, ConfirmConfig, type DerivePromptConfigContext, type DerivePromptConfigOptions, type DerivePromptConfigsContext, type DerivePromptConfigsOptions, type DerivedPromptConfig, EditorConfig, ExpandChoice, ExpandConfig, InputConfig, NumberPromptConfig, PasswordConfig, PromptConfig, RawlistConfig, RuntimePromptConfig, SelectConfig, Separator, StringPromptConfig, derivePromptConfig, isDerivedPromptConfig, prompt };
|
|
287
|
+
export { CheckboxChoice, CheckboxConfig, Choice, ConfirmConfig, type DerivePromptConfigContext, type DerivePromptConfigOptions, type DerivePromptConfigsContext, type DerivePromptConfigsOptions, type DerivedPromptConfig, EditorConfig, ExpandChoice, ExpandConfig, InputConfig, NumberPromptConfig, PasswordConfig, PromptConfig, type PromptExecutionContext, type PromptOptions, type PromptValidator, RawlistConfig, RuntimePromptConfig, SelectConfig, Separator, StringPromptConfig, derivePromptConfig, isDerivedPromptConfig, prompt };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import process from "node:process";
|
|
1
2
|
import { Separator, checkbox, confirm, editor, expand, input, number, password, rawlist, select } from "@inquirer/prompts";
|
|
2
|
-
import { message } from "@optique/core/message";
|
|
3
|
+
import { formatMessage, message } from "@optique/core/message";
|
|
3
4
|
import { createPromptAdapter, derivePromptConfig, isDerivedPromptConfig } from "@optique/prompt";
|
|
4
5
|
|
|
5
6
|
//#region src/index.ts
|
|
@@ -41,7 +42,7 @@ function getPromptFunctions() {
|
|
|
41
42
|
} : defaultPromptFunctions;
|
|
42
43
|
}
|
|
43
44
|
/**
|
|
44
|
-
* Determines whether an error came from an interrupted Inquirer prompt.
|
|
45
|
+
* Determines whether an error came from an interrupted Inquirer.js prompt.
|
|
45
46
|
*/
|
|
46
47
|
function isExitPromptError(error) {
|
|
47
48
|
return typeof error === "object" && error != null && "name" in error && error.name === "ExitPromptError";
|
|
@@ -62,35 +63,40 @@ const validPromptTypes = new Set([
|
|
|
62
63
|
*
|
|
63
64
|
* When the inner parser finds a value in the CLI arguments, that value is used
|
|
64
65
|
* directly. When no CLI value is found, an interactive prompt is shown to the
|
|
65
|
-
* user.
|
|
66
|
+
* user. If the supplied signal is aborted, parsing rejects with the signal's
|
|
67
|
+
* reason.
|
|
66
68
|
*
|
|
67
69
|
* @param parser Inner parser that reads CLI values.
|
|
68
70
|
* @param config Type-safe Inquirer.js prompt configuration, or a
|
|
69
71
|
* configuration derived from dependency sources via
|
|
70
72
|
* `derivePromptConfig()`.
|
|
73
|
+
* @param options Shared validation, retry, and abort options for the
|
|
74
|
+
* interactive fallback.
|
|
71
75
|
* @returns A parser with interactive prompt fallback, always in async mode.
|
|
76
|
+
* @throws {RangeError} If `options.maxAttempts` is not a positive integer.
|
|
72
77
|
* @throws {Error} If prompt execution fails with an unexpected error or if the
|
|
73
78
|
* inner parser throws while parsing or completing.
|
|
74
79
|
* @since 1.0.0
|
|
80
|
+
* @since 1.3.0 Added the `options` parameter.
|
|
75
81
|
*/
|
|
76
|
-
function prompt(parser, config) {
|
|
82
|
+
function prompt(parser, config, options) {
|
|
77
83
|
const promptWithAdapter = createPromptAdapter({
|
|
78
84
|
execute: executePromptRaw,
|
|
79
85
|
getDefaultValue: getConfigDefault
|
|
80
86
|
});
|
|
81
|
-
return promptWithAdapter(parser, config);
|
|
87
|
+
return promptWithAdapter(parser, config, options);
|
|
82
88
|
}
|
|
83
89
|
function getConfigDefault(config) {
|
|
84
90
|
if (config != null && typeof config === "object" && "default" in config) return config.default;
|
|
85
91
|
return void 0;
|
|
86
92
|
}
|
|
87
|
-
async function executePromptRaw(config) {
|
|
93
|
+
async function executePromptRaw(config, context) {
|
|
88
94
|
const cfg = config;
|
|
89
95
|
const prompts = getPromptFunctions();
|
|
90
96
|
try {
|
|
91
97
|
if (!validPromptTypes.has(cfg.type)) throw new TypeError(`Unsupported prompt type: ${String(cfg.type)}.`);
|
|
92
98
|
if ("prompter" in cfg && cfg.prompter != null) {
|
|
93
|
-
const value = await cfg.prompter();
|
|
99
|
+
const value = await cfg.prompter(context);
|
|
94
100
|
if (cfg.type === "number" && value === void 0) return {
|
|
95
101
|
success: false,
|
|
96
102
|
error: message`No number provided.`
|
|
@@ -100,13 +106,15 @@ async function executePromptRaw(config) {
|
|
|
100
106
|
value
|
|
101
107
|
};
|
|
102
108
|
}
|
|
109
|
+
if (context.previousValidationMessage !== void 0) process.stderr.write(formatMessage(context.previousValidationMessage) + "\n");
|
|
110
|
+
const inquirerContext = { ...context.signal === void 0 ? {} : { signal: context.signal } };
|
|
103
111
|
switch (cfg.type) {
|
|
104
112
|
case "confirm": return {
|
|
105
113
|
success: true,
|
|
106
114
|
value: await prompts.confirm({
|
|
107
115
|
message: cfg.message,
|
|
108
116
|
...cfg.default !== void 0 ? { default: cfg.default } : {}
|
|
109
|
-
})
|
|
117
|
+
}, inquirerContext)
|
|
110
118
|
};
|
|
111
119
|
case "number": {
|
|
112
120
|
const numResult = await prompts.number({
|
|
@@ -115,7 +123,7 @@ async function executePromptRaw(config) {
|
|
|
115
123
|
...cfg.min !== void 0 ? { min: cfg.min } : {},
|
|
116
124
|
...cfg.max !== void 0 ? { max: cfg.max } : {},
|
|
117
125
|
...cfg.step !== void 0 ? { step: cfg.step } : {}
|
|
118
|
-
});
|
|
126
|
+
}, inquirerContext);
|
|
119
127
|
if (numResult === void 0) return {
|
|
120
128
|
success: false,
|
|
121
129
|
error: message`No number provided.`
|
|
@@ -131,7 +139,7 @@ async function executePromptRaw(config) {
|
|
|
131
139
|
message: cfg.message,
|
|
132
140
|
...cfg.default !== void 0 ? { default: cfg.default } : {},
|
|
133
141
|
...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
|
|
134
|
-
})
|
|
142
|
+
}, inquirerContext)
|
|
135
143
|
};
|
|
136
144
|
case "password": return {
|
|
137
145
|
success: true,
|
|
@@ -139,7 +147,7 @@ async function executePromptRaw(config) {
|
|
|
139
147
|
message: cfg.message,
|
|
140
148
|
...cfg.mask !== void 0 ? { mask: cfg.mask } : {},
|
|
141
149
|
...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
|
|
142
|
-
})
|
|
150
|
+
}, inquirerContext)
|
|
143
151
|
};
|
|
144
152
|
case "editor": return {
|
|
145
153
|
success: true,
|
|
@@ -147,7 +155,7 @@ async function executePromptRaw(config) {
|
|
|
147
155
|
message: cfg.message,
|
|
148
156
|
...cfg.default !== void 0 ? { default: cfg.default } : {},
|
|
149
157
|
...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
|
|
150
|
-
})
|
|
158
|
+
}, inquirerContext)
|
|
151
159
|
};
|
|
152
160
|
case "select": return {
|
|
153
161
|
success: true,
|
|
@@ -155,7 +163,7 @@ async function executePromptRaw(config) {
|
|
|
155
163
|
message: cfg.message,
|
|
156
164
|
choices: normalizeChoices(cfg.choices),
|
|
157
165
|
...cfg.default !== void 0 ? { default: cfg.default } : {}
|
|
158
|
-
})
|
|
166
|
+
}, inquirerContext)
|
|
159
167
|
};
|
|
160
168
|
case "rawlist": return {
|
|
161
169
|
success: true,
|
|
@@ -163,7 +171,7 @@ async function executePromptRaw(config) {
|
|
|
163
171
|
message: cfg.message,
|
|
164
172
|
choices: normalizeChoices(cfg.choices),
|
|
165
173
|
...cfg.default !== void 0 ? { default: cfg.default } : {}
|
|
166
|
-
})
|
|
174
|
+
}, inquirerContext)
|
|
167
175
|
};
|
|
168
176
|
case "expand": return {
|
|
169
177
|
success: true,
|
|
@@ -171,14 +179,14 @@ async function executePromptRaw(config) {
|
|
|
171
179
|
message: cfg.message,
|
|
172
180
|
choices: cfg.choices,
|
|
173
181
|
...cfg.default !== void 0 ? { default: cfg.default } : {}
|
|
174
|
-
})
|
|
182
|
+
}, inquirerContext)
|
|
175
183
|
};
|
|
176
184
|
case "checkbox": return {
|
|
177
185
|
success: true,
|
|
178
186
|
value: await prompts.checkbox({
|
|
179
187
|
message: cfg.message,
|
|
180
188
|
choices: normalizeChoices(cfg.choices)
|
|
181
|
-
})
|
|
189
|
+
}, inquirerContext)
|
|
182
190
|
};
|
|
183
191
|
}
|
|
184
192
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@optique/inquirer",
|
|
3
|
-
"version": "1.3.0-dev.
|
|
3
|
+
"version": "1.3.0-dev.2469",
|
|
4
4
|
"description": "Inquirer.js prompt support for Optique",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"CLI",
|
|
@@ -62,13 +62,13 @@
|
|
|
62
62
|
"sideEffects": false,
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@inquirer/prompts": "^8.3.0",
|
|
65
|
-
"@optique/core": "1.3.0-dev.
|
|
66
|
-
"@optique/prompt": "1.3.0-dev.
|
|
65
|
+
"@optique/core": "1.3.0-dev.2469+77a16530",
|
|
66
|
+
"@optique/prompt": "1.3.0-dev.2469+77a16530"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@optique/config": "1.3.0-dev.
|
|
70
|
-
"@optique/env": "1.3.0-dev.
|
|
71
|
-
"@optique/run": "1.3.0-dev.
|
|
69
|
+
"@optique/config": "1.3.0-dev.2469+77a16530",
|
|
70
|
+
"@optique/env": "1.3.0-dev.2469+77a16530",
|
|
71
|
+
"@optique/run": "1.3.0-dev.2469+77a16530",
|
|
72
72
|
"@types/node": "^24.0.0",
|
|
73
73
|
"fast-check": "^4.7.0",
|
|
74
74
|
"tsdown": "^0.13.0",
|