@optique/inquirer 1.2.0-dev.2188 → 1.2.0-dev.2194
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/README.md
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
@optique/inquirer
|
|
2
2
|
=================
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
[Inquirer.js] prompt support for [Optique].
|
|
5
5
|
|
|
6
6
|
This package wraps any Optique parser with an interactive prompt that fires
|
|
7
7
|
when no CLI value is provided. The fallback priority is:
|
|
8
8
|
|
|
9
|
-
CLI arguments >
|
|
9
|
+
CLI arguments > Inquirer.js prompt.
|
|
10
10
|
|
|
11
11
|
Because interactive prompts are inherently asynchronous, the returned parser
|
|
12
12
|
always has `mode: "async"`.
|
|
13
13
|
|
|
14
|
-
[Optique]: https://optique.dev/
|
|
15
14
|
[Inquirer.js]: https://github.com/SBoudrias/Inquirer.js
|
|
15
|
+
[Optique]: https://optique.dev/
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
Installation
|
|
@@ -53,7 +53,7 @@ await run(parser);
|
|
|
53
53
|
~~~~
|
|
54
54
|
|
|
55
55
|
When `--name` and `--port` are provided on the command line, the prompts are
|
|
56
|
-
skipped. When they are absent, the user sees
|
|
56
|
+
skipped. When they are absent, the user sees Inquirer.js prompts.
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
Features
|
package/dist/index.cjs
CHANGED
|
@@ -22,10 +22,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
|
|
23
23
|
//#endregion
|
|
24
24
|
const __inquirer_prompts = __toESM(require("@inquirer/prompts"));
|
|
25
|
-
const __optique_core_annotations = __toESM(require("@optique/core/annotations"));
|
|
26
|
-
const __optique_core_extension = __toESM(require("@optique/core/extension"));
|
|
27
|
-
const __optique_core_fluent = __toESM(require("@optique/core/fluent"));
|
|
28
25
|
const __optique_core_message = __toESM(require("@optique/core/message"));
|
|
26
|
+
const __optique_prompt = __toESM(require("@optique/prompt"));
|
|
29
27
|
|
|
30
28
|
//#region src/index.ts
|
|
31
29
|
const promptFunctionsOverrideSymbol = Symbol.for("@optique/inquirer/prompt-functions");
|
|
@@ -71,406 +69,146 @@ function getPromptFunctions() {
|
|
|
71
69
|
function isExitPromptError(error) {
|
|
72
70
|
return typeof error === "object" && error != null && "name" in error && error.name === "ExitPromptError";
|
|
73
71
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
for (const key of Reflect.ownKeys(placeholderValue)) {
|
|
86
|
-
if (isArray && key === "length") continue;
|
|
87
|
-
keys.set(key, null);
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
success: true,
|
|
91
|
-
value: placeholderValue,
|
|
92
|
-
deferred: true,
|
|
93
|
-
deferredKeys: keys
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
function withAnnotatedInnerState(sourceState, innerState, run) {
|
|
97
|
-
const annotations = (0, __optique_core_annotations.getAnnotations)(sourceState);
|
|
98
|
-
if (annotations == null || innerState == null || typeof innerState !== "object" || (0, __optique_core_annotations.getAnnotations)(innerState) != null) return run(innerState);
|
|
99
|
-
const inheritedState = (0, __optique_core_extension.inheritAnnotations)(sourceState, innerState);
|
|
100
|
-
if (inheritedState !== innerState) return run(inheritedState);
|
|
101
|
-
return run((0, __optique_core_extension.withAnnotationView)(innerState, annotations));
|
|
102
|
-
}
|
|
72
|
+
const validPromptTypes = new Set([
|
|
73
|
+
"confirm",
|
|
74
|
+
"number",
|
|
75
|
+
"input",
|
|
76
|
+
"password",
|
|
77
|
+
"editor",
|
|
78
|
+
"select",
|
|
79
|
+
"rawlist",
|
|
80
|
+
"expand",
|
|
81
|
+
"checkbox"
|
|
82
|
+
]);
|
|
103
83
|
/**
|
|
104
84
|
* Wraps a parser with an interactive Inquirer.js prompt fallback.
|
|
105
85
|
*
|
|
106
|
-
* When the inner parser finds a value in the CLI arguments
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* The returned parser always has `mode: "async"` because Inquirer.js prompts
|
|
111
|
-
* are inherently asynchronous.
|
|
112
|
-
*
|
|
113
|
-
* Example:
|
|
114
|
-
*
|
|
115
|
-
* ```typescript
|
|
116
|
-
* import { option } from "@optique/core/primitives";
|
|
117
|
-
* import { string } from "@optique/core/valueparser";
|
|
118
|
-
* import { prompt } from "@optique/inquirer";
|
|
119
|
-
*
|
|
120
|
-
* const nameParser = prompt(option("--name", string()), {
|
|
121
|
-
* type: "input",
|
|
122
|
-
* message: "Enter your name:",
|
|
123
|
-
* });
|
|
124
|
-
* ```
|
|
86
|
+
* When the inner parser finds a value in the CLI arguments, that value is used
|
|
87
|
+
* directly. When no CLI value is found, an interactive prompt is shown to the
|
|
88
|
+
* user.
|
|
125
89
|
*
|
|
126
90
|
* @param parser Inner parser that reads CLI values.
|
|
127
91
|
* @param config Type-safe Inquirer.js prompt configuration.
|
|
128
92
|
* @returns A parser with interactive prompt fallback, always in async mode.
|
|
129
|
-
* @throws {Error} If prompt execution fails with an unexpected error or if
|
|
130
|
-
*
|
|
93
|
+
* @throws {Error} If prompt execution fails with an unexpected error or if the
|
|
94
|
+
* inner parser throws while parsing or completing.
|
|
131
95
|
* @since 1.0.0
|
|
132
96
|
*/
|
|
133
97
|
function prompt(parser, config) {
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
98
|
+
const promptWithAdapter = (0, __optique_prompt.createPromptAdapter)({
|
|
99
|
+
execute: (cfg) => executePromptRaw(cfg),
|
|
100
|
+
getDefaultValue: getConfigDefault
|
|
101
|
+
});
|
|
102
|
+
return promptWithAdapter(parser, config);
|
|
103
|
+
}
|
|
104
|
+
function getConfigDefault(config) {
|
|
105
|
+
if (config != null && typeof config === "object" && "default" in config) return config.default;
|
|
106
|
+
return void 0;
|
|
107
|
+
}
|
|
108
|
+
async function executePromptRaw(config) {
|
|
138
109
|
const cfg = config;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
return result;
|
|
171
|
-
}
|
|
172
|
-
const validPromptTypes = new Set([
|
|
173
|
-
"confirm",
|
|
174
|
-
"number",
|
|
175
|
-
"input",
|
|
176
|
-
"password",
|
|
177
|
-
"editor",
|
|
178
|
-
"select",
|
|
179
|
-
"rawlist",
|
|
180
|
-
"expand",
|
|
181
|
-
"checkbox"
|
|
182
|
-
]);
|
|
183
|
-
async function executePromptRaw() {
|
|
184
|
-
const prompts = getPromptFunctions();
|
|
185
|
-
try {
|
|
186
|
-
if (!validPromptTypes.has(cfg.type)) throw new TypeError(`Unsupported prompt type: ${cfg.type}`);
|
|
187
|
-
if ("prompter" in cfg && cfg.prompter != null) {
|
|
188
|
-
const value = await cfg.prompter();
|
|
189
|
-
if (cfg.type === "number" && value === void 0) return {
|
|
110
|
+
const prompts = getPromptFunctions();
|
|
111
|
+
try {
|
|
112
|
+
if (!validPromptTypes.has(cfg.type)) throw new TypeError(`Unsupported prompt type: ${String(cfg.type)}.`);
|
|
113
|
+
if ("prompter" in cfg && cfg.prompter != null) {
|
|
114
|
+
const value = await cfg.prompter();
|
|
115
|
+
if (cfg.type === "number" && value === void 0) return {
|
|
116
|
+
success: false,
|
|
117
|
+
error: __optique_core_message.message`No number provided.`
|
|
118
|
+
};
|
|
119
|
+
return {
|
|
120
|
+
success: true,
|
|
121
|
+
value
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
switch (cfg.type) {
|
|
125
|
+
case "confirm": return {
|
|
126
|
+
success: true,
|
|
127
|
+
value: await prompts.confirm({
|
|
128
|
+
message: cfg.message,
|
|
129
|
+
...cfg.default !== void 0 ? { default: cfg.default } : {}
|
|
130
|
+
})
|
|
131
|
+
};
|
|
132
|
+
case "number": {
|
|
133
|
+
const numResult = await prompts.number({
|
|
134
|
+
message: cfg.message,
|
|
135
|
+
...cfg.default !== void 0 ? { default: cfg.default } : {},
|
|
136
|
+
...cfg.min !== void 0 ? { min: cfg.min } : {},
|
|
137
|
+
...cfg.max !== void 0 ? { max: cfg.max } : {},
|
|
138
|
+
...cfg.step !== void 0 ? { step: cfg.step } : {}
|
|
139
|
+
});
|
|
140
|
+
if (numResult === void 0) return {
|
|
190
141
|
success: false,
|
|
191
142
|
error: __optique_core_message.message`No number provided.`
|
|
192
143
|
};
|
|
193
144
|
return {
|
|
194
145
|
success: true,
|
|
195
|
-
value
|
|
146
|
+
value: numResult
|
|
196
147
|
};
|
|
197
148
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
};
|
|
206
|
-
case "number": {
|
|
207
|
-
const numResult = await prompts.number({
|
|
208
|
-
message: cfg.message,
|
|
209
|
-
...cfg.default !== void 0 ? { default: cfg.default } : {},
|
|
210
|
-
...cfg.min !== void 0 ? { min: cfg.min } : {},
|
|
211
|
-
...cfg.max !== void 0 ? { max: cfg.max } : {},
|
|
212
|
-
...cfg.step !== void 0 ? { step: cfg.step } : {}
|
|
213
|
-
});
|
|
214
|
-
if (numResult === void 0) return {
|
|
215
|
-
success: false,
|
|
216
|
-
error: __optique_core_message.message`No number provided.`
|
|
217
|
-
};
|
|
218
|
-
return {
|
|
219
|
-
success: true,
|
|
220
|
-
value: numResult
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
case "input": return {
|
|
224
|
-
success: true,
|
|
225
|
-
value: await prompts.input({
|
|
226
|
-
message: cfg.message,
|
|
227
|
-
...cfg.default !== void 0 ? { default: cfg.default } : {},
|
|
228
|
-
...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
|
|
229
|
-
})
|
|
230
|
-
};
|
|
231
|
-
case "password": return {
|
|
232
|
-
success: true,
|
|
233
|
-
value: await prompts.password({
|
|
234
|
-
message: cfg.message,
|
|
235
|
-
...cfg.mask !== void 0 ? { mask: cfg.mask } : {},
|
|
236
|
-
...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
|
|
237
|
-
})
|
|
238
|
-
};
|
|
239
|
-
case "editor": return {
|
|
240
|
-
success: true,
|
|
241
|
-
value: await prompts.editor({
|
|
242
|
-
message: cfg.message,
|
|
243
|
-
...cfg.default !== void 0 ? { default: cfg.default } : {},
|
|
244
|
-
...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
|
|
245
|
-
})
|
|
246
|
-
};
|
|
247
|
-
case "select": return {
|
|
248
|
-
success: true,
|
|
249
|
-
value: await prompts.select({
|
|
250
|
-
message: cfg.message,
|
|
251
|
-
choices: normalizeChoices(cfg.choices),
|
|
252
|
-
...cfg.default !== void 0 ? { default: cfg.default } : {}
|
|
253
|
-
})
|
|
254
|
-
};
|
|
255
|
-
case "rawlist": return {
|
|
256
|
-
success: true,
|
|
257
|
-
value: await prompts.rawlist({
|
|
258
|
-
message: cfg.message,
|
|
259
|
-
choices: normalizeChoices(cfg.choices),
|
|
260
|
-
...cfg.default !== void 0 ? { default: cfg.default } : {}
|
|
261
|
-
})
|
|
262
|
-
};
|
|
263
|
-
case "expand": return {
|
|
264
|
-
success: true,
|
|
265
|
-
value: await prompts.expand({
|
|
266
|
-
message: cfg.message,
|
|
267
|
-
choices: cfg.choices,
|
|
268
|
-
...cfg.default !== void 0 ? { default: cfg.default } : {}
|
|
269
|
-
})
|
|
270
|
-
};
|
|
271
|
-
case "checkbox": return {
|
|
272
|
-
success: true,
|
|
273
|
-
value: await prompts.checkbox({
|
|
274
|
-
message: cfg.message,
|
|
275
|
-
choices: normalizeChoices(cfg.choices)
|
|
276
|
-
})
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
} catch (error) {
|
|
280
|
-
if (isExitPromptError(error)) return {
|
|
281
|
-
success: false,
|
|
282
|
-
error: __optique_core_message.message`Prompt cancelled.`
|
|
149
|
+
case "input": return {
|
|
150
|
+
success: true,
|
|
151
|
+
value: await prompts.input({
|
|
152
|
+
message: cfg.message,
|
|
153
|
+
...cfg.default !== void 0 ? { default: cfg.default } : {},
|
|
154
|
+
...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
|
|
155
|
+
})
|
|
283
156
|
};
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const promptedParser = {
|
|
292
|
-
mode: "async",
|
|
293
|
-
$valueType: parser.$valueType,
|
|
294
|
-
$stateType: parser.$stateType,
|
|
295
|
-
priority: parser.priority,
|
|
296
|
-
usage: parser.usage.length === 1 && parser.usage[0].type === "optional" ? parser.usage : [{
|
|
297
|
-
type: "optional",
|
|
298
|
-
terms: parser.usage
|
|
299
|
-
}],
|
|
300
|
-
leadingNames: parser.leadingNames,
|
|
301
|
-
acceptingAnyToken: parser.acceptingAnyToken,
|
|
302
|
-
shouldDeferCompletion(state) {
|
|
303
|
-
return !isPromptBindState(state) || !state.hasCliValue;
|
|
304
|
-
},
|
|
305
|
-
getSuggestRuntimeNodes(state, path) {
|
|
306
|
-
const innerState = isPromptBindState(state) ? state.cliState === void 0 ? parser.initialState : state.cliState : state;
|
|
307
|
-
return (0, __optique_core_extension.delegateSuggestNodes)(parser, promptedParser, state, path, innerState, "prepend");
|
|
308
|
-
},
|
|
309
|
-
initialState: {
|
|
310
|
-
[promptBindStateKey]: true,
|
|
311
|
-
hasCliValue: false
|
|
312
|
-
},
|
|
313
|
-
parse: (context) => {
|
|
314
|
-
const annotations = (0, __optique_core_annotations.getAnnotations)(context.state);
|
|
315
|
-
const innerState = isPromptBindState(context.state) ? context.state.hasCliValue ? context.state.cliState : parser.initialState : context.state;
|
|
316
|
-
const baseInnerContext = innerState !== context.state ? {
|
|
317
|
-
...context,
|
|
318
|
-
state: innerState
|
|
319
|
-
} : context;
|
|
320
|
-
const effectiveInnerState = annotations != null && innerState == null && (0, __optique_core_extension.getTraits)(parser).inheritsAnnotations === true ? (0, __optique_core_extension.injectAnnotations)(innerState, annotations) : innerState;
|
|
321
|
-
const processResult = (result$1) => {
|
|
322
|
-
if (result$1.success) {
|
|
323
|
-
const cliState = annotations != null && result$1.next.state != null && typeof result$1.next.state === "object" && (0, __optique_core_annotations.getAnnotations)(result$1.next.state) !== annotations ? (0, __optique_core_extension.injectAnnotations)(result$1.next.state, annotations) : result$1.next.state;
|
|
324
|
-
const cliConsumed = result$1.consumed.length > 0;
|
|
325
|
-
const nextState$1 = (0, __optique_core_extension.injectAnnotations)({
|
|
326
|
-
[promptBindStateKey]: true,
|
|
327
|
-
hasCliValue: cliConsumed,
|
|
328
|
-
cliState
|
|
329
|
-
}, annotations);
|
|
330
|
-
return {
|
|
331
|
-
success: true,
|
|
332
|
-
...result$1.provisional ? { provisional: true } : {},
|
|
333
|
-
next: {
|
|
334
|
-
...result$1.next,
|
|
335
|
-
state: nextState$1
|
|
336
|
-
},
|
|
337
|
-
consumed: result$1.consumed
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
if (result$1.consumed > 0) return result$1;
|
|
341
|
-
const nextState = (0, __optique_core_extension.injectAnnotations)({
|
|
342
|
-
[promptBindStateKey]: true,
|
|
343
|
-
hasCliValue: false
|
|
344
|
-
}, annotations);
|
|
345
|
-
return {
|
|
346
|
-
success: true,
|
|
347
|
-
next: {
|
|
348
|
-
...baseInnerContext,
|
|
349
|
-
state: nextState
|
|
350
|
-
},
|
|
351
|
-
consumed: []
|
|
352
|
-
};
|
|
157
|
+
case "password": return {
|
|
158
|
+
success: true,
|
|
159
|
+
value: await prompts.password({
|
|
160
|
+
message: cfg.message,
|
|
161
|
+
...cfg.mask !== void 0 ? { mask: cfg.mask } : {},
|
|
162
|
+
...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
|
|
163
|
+
})
|
|
353
164
|
};
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if (result instanceof Promise) return result.then(processResult);
|
|
362
|
-
return Promise.resolve(processResult(result));
|
|
363
|
-
},
|
|
364
|
-
complete: (state, exec) => {
|
|
365
|
-
if (isPromptBindState(state) && state.hasCliValue) {
|
|
366
|
-
const r = withAnnotatedInnerState(state, state.cliState, (annotatedInnerState) => parser.complete(annotatedInnerState, exec));
|
|
367
|
-
if (r instanceof Promise) return r;
|
|
368
|
-
return Promise.resolve(r);
|
|
369
|
-
}
|
|
370
|
-
const isProbe = exec != null && exec.phase !== "complete";
|
|
371
|
-
const annotations = (0, __optique_core_annotations.getAnnotations)(state);
|
|
372
|
-
const innerInitialState = parser.initialState;
|
|
373
|
-
const shouldInheritInitialStateAnnotations = annotations != null && (innerInitialState == null || typeof innerInitialState === "object");
|
|
374
|
-
const effectiveInitialState = shouldInheritInitialStateAnnotations ? (0, __optique_core_extension.inheritAnnotations)(state, innerInitialState) : innerInitialState;
|
|
375
|
-
const readPlaceholder = () => {
|
|
376
|
-
try {
|
|
377
|
-
return "placeholder" in parser ? parser.placeholder : void 0;
|
|
378
|
-
} catch {
|
|
379
|
-
return void 0;
|
|
380
|
-
}
|
|
165
|
+
case "editor": return {
|
|
166
|
+
success: true,
|
|
167
|
+
value: await prompts.editor({
|
|
168
|
+
message: cfg.message,
|
|
169
|
+
...cfg.default !== void 0 ? { default: cfg.default } : {},
|
|
170
|
+
...cfg.validate !== void 0 ? { validate: cfg.validate } : {}
|
|
171
|
+
})
|
|
381
172
|
};
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
})
|
|
389
|
-
return executePrompt();
|
|
173
|
+
case "select": return {
|
|
174
|
+
success: true,
|
|
175
|
+
value: await prompts.select({
|
|
176
|
+
message: cfg.message,
|
|
177
|
+
choices: normalizeChoices(cfg.choices),
|
|
178
|
+
...cfg.default !== void 0 ? { default: cfg.default } : {}
|
|
179
|
+
})
|
|
390
180
|
};
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
181
|
+
case "rawlist": return {
|
|
182
|
+
success: true,
|
|
183
|
+
value: await prompts.rawlist({
|
|
184
|
+
message: cfg.message,
|
|
185
|
+
choices: normalizeChoices(cfg.choices),
|
|
186
|
+
...cfg.default !== void 0 ? { default: cfg.default } : {}
|
|
187
|
+
})
|
|
188
|
+
};
|
|
189
|
+
case "expand": return {
|
|
190
|
+
success: true,
|
|
191
|
+
value: await prompts.expand({
|
|
192
|
+
message: cfg.message,
|
|
193
|
+
choices: cfg.choices,
|
|
194
|
+
...cfg.default !== void 0 ? { default: cfg.default } : {}
|
|
195
|
+
})
|
|
196
|
+
};
|
|
197
|
+
case "checkbox": return {
|
|
198
|
+
success: true,
|
|
199
|
+
value: await prompts.checkbox({
|
|
200
|
+
message: cfg.message,
|
|
201
|
+
choices: normalizeChoices(cfg.choices)
|
|
202
|
+
})
|
|
407
203
|
};
|
|
408
|
-
if (hasDeferHook) {
|
|
409
|
-
const innerR = withAnnotatedInnerState(state, effectiveInitialState, (annotatedInnerState) => parser.complete(annotatedInnerState, exec));
|
|
410
|
-
const handleDeferHookResult = (res) => {
|
|
411
|
-
if (res.success && res.value === void 0) return finalizePrompt();
|
|
412
|
-
if (!res.success) return finalizePrompt();
|
|
413
|
-
return Promise.resolve(res);
|
|
414
|
-
};
|
|
415
|
-
if (innerR instanceof Promise) return innerR.then(handleDeferHookResult);
|
|
416
|
-
return handleDeferHookResult(innerR);
|
|
417
|
-
}
|
|
418
|
-
const simParseR = withAnnotatedInnerState(state, effectiveInitialState, (annotatedState) => parser.parse({
|
|
419
|
-
buffer: [],
|
|
420
|
-
state: annotatedState,
|
|
421
|
-
optionsTerminated: false,
|
|
422
|
-
usage: parser.usage
|
|
423
|
-
}));
|
|
424
|
-
if (simParseR instanceof Promise) return simParseR.then(decideFromParse);
|
|
425
|
-
return decideFromParse(simParseR);
|
|
426
|
-
},
|
|
427
|
-
suggest: (context, prefix) => {
|
|
428
|
-
const innerState = isPromptBindState(context.state) ? context.state.cliState === void 0 ? parser.initialState : context.state.cliState : context.state;
|
|
429
|
-
const innerContext = innerState !== context.state ? {
|
|
430
|
-
...context,
|
|
431
|
-
state: innerState
|
|
432
|
-
} : context;
|
|
433
|
-
const innerResult = parser.suggest(innerContext, prefix);
|
|
434
|
-
return async function* () {
|
|
435
|
-
yield* innerResult;
|
|
436
|
-
}();
|
|
437
|
-
},
|
|
438
|
-
getDocFragments(state, upperDefaultValue) {
|
|
439
|
-
const configDefault = "default" in cfg ? cfg.default : void 0;
|
|
440
|
-
const defaultValue = upperDefaultValue ?? configDefault;
|
|
441
|
-
return parser.getDocFragments(state, defaultValue);
|
|
442
|
-
}
|
|
443
|
-
};
|
|
444
|
-
(0, __optique_core_extension.defineTraits)(promptedParser, { inheritsAnnotations: true });
|
|
445
|
-
if ("placeholder" in parser) Object.defineProperty(promptedParser, "placeholder", {
|
|
446
|
-
get() {
|
|
447
|
-
try {
|
|
448
|
-
return parser.placeholder;
|
|
449
|
-
} catch {
|
|
450
|
-
return void 0;
|
|
451
|
-
}
|
|
452
|
-
},
|
|
453
|
-
configurable: true,
|
|
454
|
-
enumerable: false
|
|
455
|
-
});
|
|
456
|
-
if (typeof parser.normalizeValue === "function") Object.defineProperty(promptedParser, "normalizeValue", {
|
|
457
|
-
value: parser.normalizeValue.bind(parser),
|
|
458
|
-
configurable: true,
|
|
459
|
-
enumerable: false
|
|
460
|
-
});
|
|
461
|
-
const dependencyMetadata = (0, __optique_core_extension.mapSourceMetadata)(parser, (source) => ({
|
|
462
|
-
...source,
|
|
463
|
-
extractSourceValue: (state) => {
|
|
464
|
-
if (!isPromptBindState(state)) return source.extractSourceValue(state);
|
|
465
|
-
return source.extractSourceValue(state.cliState ?? state);
|
|
466
204
|
}
|
|
467
|
-
})
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
205
|
+
} catch (error) {
|
|
206
|
+
if (isExitPromptError(error)) return {
|
|
207
|
+
success: false,
|
|
208
|
+
error: __optique_core_message.message`Prompt cancelled.`
|
|
209
|
+
};
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
474
212
|
}
|
|
475
213
|
/** Normalize choices to the format Inquirer.js expects. */
|
|
476
214
|
function normalizeChoices(choices) {
|
|
@@ -485,7 +223,8 @@ function normalizeChoices(choices) {
|
|
|
485
223
|
...c.name !== void 0 ? { name: c.name } : {},
|
|
486
224
|
..."description" in c && c.description !== void 0 ? { description: c.description } : {},
|
|
487
225
|
..."short" in c && c.short !== void 0 ? { short: c.short } : {},
|
|
488
|
-
..."disabled" in c && c.disabled !== void 0 ? { disabled: c.disabled } : {}
|
|
226
|
+
..."disabled" in c && c.disabled !== void 0 ? { disabled: c.disabled } : {},
|
|
227
|
+
..."checked" in c && c.checked !== void 0 ? { checked: c.checked } : {}
|
|
489
228
|
};
|
|
490
229
|
});
|
|
491
230
|
}
|