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