@optique/inquirer 1.0.0-dev.0 → 1.0.0-dev.461

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 ADDED
@@ -0,0 +1,81 @@
1
+ @optique/inquirer
2
+ =================
3
+
4
+ Interactive prompt support for [Optique] via [Inquirer.js].
5
+
6
+ This package wraps any Optique parser with an interactive prompt that fires
7
+ when no CLI value is provided. The fallback priority is:
8
+
9
+ CLI arguments > interactive prompt.
10
+
11
+ Because interactive prompts are inherently asynchronous, the returned parser
12
+ always has `$mode: "async"`.
13
+
14
+ [Optique]: https://optique.dev/
15
+ [Inquirer.js]: https://github.com/SBoudrias/Inquirer.js
16
+
17
+
18
+ Installation
19
+ ------------
20
+
21
+ ~~~~ bash
22
+ deno add jsr:@optique/inquirer
23
+ npm add @optique/inquirer
24
+ pnpm add @optique/inquirer
25
+ yarn add @optique/inquirer
26
+ bun add @optique/inquirer
27
+ ~~~~
28
+
29
+
30
+ Quick start
31
+ -----------
32
+
33
+ ~~~~ typescript
34
+ import { object } from "@optique/core/constructs";
35
+ import { option } from "@optique/core/primitives";
36
+ import { integer, string } from "@optique/core/valueparser";
37
+ import { prompt } from "@optique/inquirer";
38
+ import { run } from "@optique/run";
39
+
40
+ const parser = object({
41
+ name: prompt(option("--name", string()), {
42
+ type: "input",
43
+ message: "Enter your name:",
44
+ }),
45
+ port: prompt(option("--port", integer()), {
46
+ type: "number",
47
+ message: "Enter the port number:",
48
+ default: 3000,
49
+ }),
50
+ });
51
+
52
+ await run(parser);
53
+ ~~~~
54
+
55
+ When `--name` and `--port` are provided on the command line, the prompts are
56
+ skipped. When they are absent, the user sees interactive prompts.
57
+
58
+
59
+ Features
60
+ --------
61
+
62
+ - *Ten prompt types*: `input`, `password`, `number`, `confirm`, `select`,
63
+ `rawlist`, `expand`, `checkbox`, `editor`, and a custom `prompter` for
64
+ testing
65
+ - *Transparent composition* with `bindEnv()` and `bindConfig()` — the
66
+ prompt fires only when no higher-priority source supplies a value
67
+ - *Prompt-only values* via `prompt(fail<T>(), …)` when a value should not
68
+ be exposed as a CLI option
69
+ - *TTY-free testing* via the `prompter` escape hatch on every config type
70
+
71
+
72
+ Documentation
73
+ -------------
74
+
75
+ For full documentation, visit <https://optique.dev/integrations/inquirer>.
76
+
77
+
78
+ License
79
+ -------
80
+
81
+ MIT License. See [LICENSE](../../LICENSE) for details.
package/dist/index.cjs CHANGED
@@ -173,9 +173,13 @@ function prompt(parser, config) {
173
173
  parse: (context) => {
174
174
  const annotations = (0, __optique_core_annotations.getAnnotations)(context.state);
175
175
  const innerState = isPromptBindState(context.state) ? context.state.hasCliValue ? context.state.cliState : parser.initialState : context.state;
176
- const innerContext = innerState !== context.state ? {
176
+ const innerStateWithAnnotations = annotations != null && (innerState == null || typeof innerState === "object" && !(__optique_core_annotations.annotationKey in innerState)) ? {
177
+ ...innerState != null && typeof innerState === "object" ? innerState : {},
178
+ [__optique_core_annotations.annotationKey]: annotations
179
+ } : innerState;
180
+ const innerContext = innerStateWithAnnotations !== context.state ? {
177
181
  ...context,
178
- state: innerState
182
+ state: innerStateWithAnnotations
179
183
  } : context;
180
184
  const processResult = (result$1) => {
181
185
  if (result$1.success) {
@@ -226,9 +230,21 @@ function prompt(parser, config) {
226
230
  promptCache = null;
227
231
  return cached;
228
232
  }
229
- promptCache = executePrompt();
233
+ const innerState = parser.initialState;
234
+ const r = parser.complete(innerState);
235
+ const fallback = (res) => res.success ? Promise.resolve(res) : executePrompt();
236
+ promptCache = r instanceof Promise ? r.then(fallback) : fallback(r);
230
237
  return promptCache;
231
238
  }
239
+ const cliState = isPromptBindState(state) ? state.cliState : void 0;
240
+ const cliStateHasAnnotations = cliState != null && typeof cliState === "object" && __optique_core_annotations.annotationKey in cliState;
241
+ if (cliStateHasAnnotations) {
242
+ const innerState = cliState;
243
+ const r = parser.complete(innerState);
244
+ const fallback = (res) => res.success ? Promise.resolve(res) : executePrompt();
245
+ if (r instanceof Promise) return r.then(fallback);
246
+ return fallback(r);
247
+ }
232
248
  return executePrompt();
233
249
  },
234
250
  suggest: (context, prefix) => {
package/dist/index.js CHANGED
@@ -150,9 +150,13 @@ function prompt(parser, config) {
150
150
  parse: (context) => {
151
151
  const annotations = getAnnotations(context.state);
152
152
  const innerState = isPromptBindState(context.state) ? context.state.hasCliValue ? context.state.cliState : parser.initialState : context.state;
153
- const innerContext = innerState !== context.state ? {
153
+ const innerStateWithAnnotations = annotations != null && (innerState == null || typeof innerState === "object" && !(annotationKey in innerState)) ? {
154
+ ...innerState != null && typeof innerState === "object" ? innerState : {},
155
+ [annotationKey]: annotations
156
+ } : innerState;
157
+ const innerContext = innerStateWithAnnotations !== context.state ? {
154
158
  ...context,
155
- state: innerState
159
+ state: innerStateWithAnnotations
156
160
  } : context;
157
161
  const processResult = (result$1) => {
158
162
  if (result$1.success) {
@@ -203,9 +207,21 @@ function prompt(parser, config) {
203
207
  promptCache = null;
204
208
  return cached;
205
209
  }
206
- promptCache = executePrompt();
210
+ const innerState = parser.initialState;
211
+ const r = parser.complete(innerState);
212
+ const fallback = (res) => res.success ? Promise.resolve(res) : executePrompt();
213
+ promptCache = r instanceof Promise ? r.then(fallback) : fallback(r);
207
214
  return promptCache;
208
215
  }
216
+ const cliState = isPromptBindState(state) ? state.cliState : void 0;
217
+ const cliStateHasAnnotations = cliState != null && typeof cliState === "object" && annotationKey in cliState;
218
+ if (cliStateHasAnnotations) {
219
+ const innerState = cliState;
220
+ const r = parser.complete(innerState);
221
+ const fallback = (res) => res.success ? Promise.resolve(res) : executePrompt();
222
+ if (r instanceof Promise) return r.then(fallback);
223
+ return fallback(r);
224
+ }
209
225
  return executePrompt();
210
226
  },
211
227
  suggest: (context, prefix) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/inquirer",
3
- "version": "1.0.0-dev.0",
3
+ "version": "1.0.0-dev.461+42812276",
4
4
  "description": "Interactive prompt support for Optique via Inquirer.js",
5
5
  "keywords": [
6
6
  "CLI",
@@ -56,12 +56,13 @@
56
56
  "sideEffects": false,
57
57
  "dependencies": {
58
58
  "@inquirer/prompts": "^8.3.0",
59
- "@optique/core": "1.0.0"
59
+ "@optique/core": "1.0.0-dev.461+42812276"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/node": "^20.19.9",
63
63
  "tsdown": "^0.13.0",
64
- "typescript": "^5.8.3"
64
+ "typescript": "^5.8.3",
65
+ "@optique/env": "1.0.0-dev.461+42812276"
65
66
  },
66
67
  "scripts": {
67
68
  "build": "tsdown",