scenv-inquirer 0.3.3 → 0.4.1

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 CHANGED
@@ -1,8 +1,8 @@
1
1
  # scenv-inquirer
2
2
 
3
- Inquirer-based prompts for [scenv](https://www.npmjs.com/package/scenv): variable prompts and save/context callbacks.
3
+ Inquirer-based prompts for [scenv](https://www.npmjs.com/package/scenv): variable prompts (and optional default prompt callback).
4
4
 
5
- Use with scenv when you want interactive prompts for variable values and for "save to context?" / "which context?" flows.
5
+ Use with scenv when you want interactive prompts for variable values. Saving is controlled by scenv's `saveContextTo` config (path or context name); there are no "save?" or "which context?" callbacks in scenv.
6
6
 
7
7
  ## Install
8
8
 
@@ -18,7 +18,7 @@ npm install scenv scenv-inquirer inquirer
18
18
 
19
19
  ### Variable prompt
20
20
 
21
- Use `prompt()` as the `prompt` option for a variable. Scenv calls it with `(name, defaultValue)` when it needs to ask the user.
21
+ Use `prompt()` as the `prompt` option for a variable. Scenv calls it with `(name, defaultValue)` when it needs to ask the user. **Scenv does not prompt by default** — enable prompting via config (e.g. `configure({ prompt: "fallback" })`, `SCENV_PROMPT=fallback`, or `prompt` in `scenv.config.json`).
22
22
 
23
23
  ```ts
24
24
  import { scenv } from "scenv";
@@ -29,7 +29,8 @@ const apiUrl = scenv("API URL", {
29
29
  prompt: prompt(),
30
30
  });
31
31
 
32
- const url = await apiUrl.get(); // prompts via inquirer if no env/context/default
32
+ configure({ prompt: "fallback" }); // or "always" / "no-env"
33
+ const url = await apiUrl.get(); // prompts via inquirer if no env/context
33
34
  ```
34
35
 
35
36
  ### Default prompt for all variables
@@ -45,11 +46,7 @@ configure({ callbacks: { defaultPrompt: prompt() } });
45
46
 
46
47
  Variable-level `prompt` overrides this default.
47
48
 
48
- ### Save and context callbacks
49
-
50
- `askWhetherToSave()` and `askContext()` return functions for scenv's `onAskWhetherToSave` and `onAskContext` callbacks. Use them when `shouldSavePrompt` is `ask` or when `saveContextTo: "ask"`.
51
-
52
- **`callbacks()`** wires all of the above in one go:
49
+ **`callbacks()`** returns an object you can pass to `configure()` so all variables use inquirer when they need a value:
53
50
 
54
51
  ```ts
55
52
  import { configure } from "scenv";
@@ -60,20 +57,14 @@ configure(callbacks());
60
57
  configure({ ...yourConfig, ...callbacks() });
61
58
  ```
62
59
 
63
- This sets:
64
-
65
- - **defaultPrompt** – inquirer for variable values when no value is resolved
66
- - **onAskWhetherToSave** – "Save '{name}' for next time?" (y/n). Only used when `shouldSavePrompt` is "ask".
67
- - **onAskContext** – "Save to which context?" (list or new). Used when `saveContextTo` is "ask" or when saving after prompt and destination is "ask".
60
+ This sets **defaultPrompt** so variable values are prompted via inquirer when no value is resolved from set/env/context. You must still enable prompting in scenv (e.g. `configure({ prompt: "fallback" })`).
68
61
 
69
62
  ## API
70
63
 
71
64
  | Export | Description |
72
65
  |--------|-------------|
73
66
  | `prompt()` | Returns `(name, defaultValue) => Promise<T>` for use as variable `prompt` or `callbacks.defaultPrompt`. |
74
- | `askWhetherToSave()` | Returns `onAskWhetherToSave`: asks whether to save (y/n). Where to save is handled by `saveContextTo` or `onAskContext`. |
75
- | `askContext()` | Returns `onAskContext`: asks which context to save to. |
76
- | `callbacks()` | Returns `{ callbacks: { defaultPrompt, onAskWhetherToSave, onAskContext } }`. |
67
+ | `callbacks()` | Returns `{ callbacks: { defaultPrompt } }` for use with `configure()`. |
77
68
 
78
69
  ## License
79
70
 
package/dist/index.cjs CHANGED
@@ -30,8 +30,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- askContext: () => askContext,
34
- askWhetherToSave: () => askWhetherToSave,
35
33
  callbacks: () => callbacks,
36
34
  prompt: () => prompt
37
35
  });
@@ -51,53 +49,11 @@ function prompt() {
51
49
  return value;
52
50
  });
53
51
  }
54
- function askWhetherToSave() {
55
- return async (name, _value) => {
56
- const { save } = await import_inquirer.default.prompt([
57
- {
58
- type: "confirm",
59
- name: "save",
60
- message: `Save "${name}" for next time?`,
61
- default: true
62
- }
63
- ]);
64
- return save;
65
- };
66
- }
67
- function askContext() {
68
- return async (name, contextNames) => {
69
- const choices = [...contextNames];
70
- if (choices.length === 0) choices.push("default");
71
- choices.push("(new context)");
72
- const { context } = await import_inquirer.default.prompt([
73
- {
74
- type: "list",
75
- name: "context",
76
- message: `Save "${name}" to which context?`,
77
- choices
78
- }
79
- ]);
80
- if (context === "(new context)") {
81
- const { newContext } = await import_inquirer.default.prompt([
82
- { type: "input", name: "newContext", message: "Context name:", default: "default" }
83
- ]);
84
- return newContext.trim() || "default";
85
- }
86
- return context;
87
- };
88
- }
89
52
  function callbacks() {
90
- const cbs = {
91
- defaultPrompt: prompt(),
92
- onAskWhetherToSave: askWhetherToSave(),
93
- onAskContext: askContext()
94
- };
95
- return { callbacks: cbs };
53
+ return { callbacks: { defaultPrompt: prompt() } };
96
54
  }
97
55
  // Annotate the CommonJS export names for ESM import in node:
98
56
  0 && (module.exports = {
99
- askContext,
100
- askWhetherToSave,
101
57
  callbacks,
102
58
  prompt
103
59
  });
package/dist/index.d.cts CHANGED
@@ -4,9 +4,9 @@ import { ScenvCallbacks, DefaultPromptFn } from 'scenv';
4
4
  * Returns an inquirer-based prompt function for use with scenv variables. Use as the
5
5
  * variable's `prompt` option or as `callbacks.defaultPrompt`. Scenv calls it with the
6
6
  * variable name and default value when prompting; this shows an inquirer input prompt.
7
- * Returned value is a string; use a validator (e.g. scenv-zod) for type coercion.
7
+ * Returned value is a string; use a parser (e.g. scenv-zod) for type coercion.
8
8
  *
9
- * @typeParam T - Value type (default string). Cast or validate in your validator.
9
+ * @typeParam T - Value type (default string). Cast or parse in your parser.
10
10
  * @returns A function `(name, defaultValue) => Promise<T>` suitable for scenv's prompt or defaultPrompt.
11
11
  *
12
12
  * @example
@@ -15,29 +15,10 @@ import { ScenvCallbacks, DefaultPromptFn } from 'scenv';
15
15
  */
16
16
  declare function prompt<T = string>(): DefaultPromptFn;
17
17
  /**
18
- * Returns a function suitable for scenv's {@link ScenvCallbacks.onAskWhetherToSave} callback.
19
- * Uses inquirer confirm to ask "Save '{name}' for next time?" (y/n). Where to save is
20
- * determined by config.saveContextTo or the onAskContext callback when saveContextTo is "ask".
21
- * Only called when {@link ScenvConfig.shouldSavePrompt} is "ask" and the user was just prompted. ("always" saves without asking.)
18
+ * Returns an object with the defaultPrompt callback for scenv. Pass to {@link configure}
19
+ * to use inquirer for variable prompts. Variable-level `prompt` overrides defaultPrompt.
22
20
  *
23
- * @returns A function `(name, value) => Promise<boolean>`: true to save, false to skip.
24
- */
25
- declare function askWhetherToSave(): NonNullable<ScenvCallbacks["onAskWhetherToSave"]>;
26
- /**
27
- * Returns a function suitable for scenv's {@link ScenvCallbacks.onAskContext} callback.
28
- * Uses inquirer list to choose a context from contextNames, with a "(new context)" option
29
- * that prompts for a new name. Used when {@link ScenvConfig.saveContextTo} is "ask" or
30
- * when saving after a prompt and the destination is "ask".
31
- *
32
- * @returns A function `(name, contextNames) => Promise<string>` that returns the chosen context name.
33
- */
34
- declare function askContext(): NonNullable<ScenvCallbacks["onAskContext"]>;
35
- /**
36
- * Returns an object with all inquirer-based callbacks for scenv. Pass to {@link configure}
37
- * to use inquirer for variable prompts, "save for next time?", and "which context?".
38
- * Variable-level `prompt` overrides defaultPrompt.
39
- *
40
- * @returns `{ callbacks: { defaultPrompt, onAskWhetherToSave, onAskContext } }` – spread into configure() or merge with other config.
21
+ * @returns `{ callbacks: { defaultPrompt } }` spread into configure() or merge with other config.
41
22
  *
42
23
  * @example
43
24
  * import { configure } from "scenv";
@@ -49,4 +30,4 @@ declare function callbacks(): {
49
30
  callbacks: ScenvCallbacks;
50
31
  };
51
32
 
52
- export { askContext, askWhetherToSave, callbacks, prompt };
33
+ export { callbacks, prompt };
package/dist/index.d.ts CHANGED
@@ -4,9 +4,9 @@ import { ScenvCallbacks, DefaultPromptFn } from 'scenv';
4
4
  * Returns an inquirer-based prompt function for use with scenv variables. Use as the
5
5
  * variable's `prompt` option or as `callbacks.defaultPrompt`. Scenv calls it with the
6
6
  * variable name and default value when prompting; this shows an inquirer input prompt.
7
- * Returned value is a string; use a validator (e.g. scenv-zod) for type coercion.
7
+ * Returned value is a string; use a parser (e.g. scenv-zod) for type coercion.
8
8
  *
9
- * @typeParam T - Value type (default string). Cast or validate in your validator.
9
+ * @typeParam T - Value type (default string). Cast or parse in your parser.
10
10
  * @returns A function `(name, defaultValue) => Promise<T>` suitable for scenv's prompt or defaultPrompt.
11
11
  *
12
12
  * @example
@@ -15,29 +15,10 @@ import { ScenvCallbacks, DefaultPromptFn } from 'scenv';
15
15
  */
16
16
  declare function prompt<T = string>(): DefaultPromptFn;
17
17
  /**
18
- * Returns a function suitable for scenv's {@link ScenvCallbacks.onAskWhetherToSave} callback.
19
- * Uses inquirer confirm to ask "Save '{name}' for next time?" (y/n). Where to save is
20
- * determined by config.saveContextTo or the onAskContext callback when saveContextTo is "ask".
21
- * Only called when {@link ScenvConfig.shouldSavePrompt} is "ask" and the user was just prompted. ("always" saves without asking.)
18
+ * Returns an object with the defaultPrompt callback for scenv. Pass to {@link configure}
19
+ * to use inquirer for variable prompts. Variable-level `prompt` overrides defaultPrompt.
22
20
  *
23
- * @returns A function `(name, value) => Promise<boolean>`: true to save, false to skip.
24
- */
25
- declare function askWhetherToSave(): NonNullable<ScenvCallbacks["onAskWhetherToSave"]>;
26
- /**
27
- * Returns a function suitable for scenv's {@link ScenvCallbacks.onAskContext} callback.
28
- * Uses inquirer list to choose a context from contextNames, with a "(new context)" option
29
- * that prompts for a new name. Used when {@link ScenvConfig.saveContextTo} is "ask" or
30
- * when saving after a prompt and the destination is "ask".
31
- *
32
- * @returns A function `(name, contextNames) => Promise<string>` that returns the chosen context name.
33
- */
34
- declare function askContext(): NonNullable<ScenvCallbacks["onAskContext"]>;
35
- /**
36
- * Returns an object with all inquirer-based callbacks for scenv. Pass to {@link configure}
37
- * to use inquirer for variable prompts, "save for next time?", and "which context?".
38
- * Variable-level `prompt` overrides defaultPrompt.
39
- *
40
- * @returns `{ callbacks: { defaultPrompt, onAskWhetherToSave, onAskContext } }` – spread into configure() or merge with other config.
21
+ * @returns `{ callbacks: { defaultPrompt } }` spread into configure() or merge with other config.
41
22
  *
42
23
  * @example
43
24
  * import { configure } from "scenv";
@@ -49,4 +30,4 @@ declare function callbacks(): {
49
30
  callbacks: ScenvCallbacks;
50
31
  };
51
32
 
52
- export { askContext, askWhetherToSave, callbacks, prompt };
33
+ export { callbacks, prompt };
package/dist/index.js CHANGED
@@ -14,52 +14,10 @@ function prompt() {
14
14
  return value;
15
15
  });
16
16
  }
17
- function askWhetherToSave() {
18
- return async (name, _value) => {
19
- const { save } = await inquirer.prompt([
20
- {
21
- type: "confirm",
22
- name: "save",
23
- message: `Save "${name}" for next time?`,
24
- default: true
25
- }
26
- ]);
27
- return save;
28
- };
29
- }
30
- function askContext() {
31
- return async (name, contextNames) => {
32
- const choices = [...contextNames];
33
- if (choices.length === 0) choices.push("default");
34
- choices.push("(new context)");
35
- const { context } = await inquirer.prompt([
36
- {
37
- type: "list",
38
- name: "context",
39
- message: `Save "${name}" to which context?`,
40
- choices
41
- }
42
- ]);
43
- if (context === "(new context)") {
44
- const { newContext } = await inquirer.prompt([
45
- { type: "input", name: "newContext", message: "Context name:", default: "default" }
46
- ]);
47
- return newContext.trim() || "default";
48
- }
49
- return context;
50
- };
51
- }
52
17
  function callbacks() {
53
- const cbs = {
54
- defaultPrompt: prompt(),
55
- onAskWhetherToSave: askWhetherToSave(),
56
- onAskContext: askContext()
57
- };
58
- return { callbacks: cbs };
18
+ return { callbacks: { defaultPrompt: prompt() } };
59
19
  }
60
20
  export {
61
- askContext,
62
- askWhetherToSave,
63
21
  callbacks,
64
22
  prompt
65
23
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scenv-inquirer",
3
- "version": "0.3.3",
3
+ "version": "0.4.1",
4
4
  "description": "Inquirer prompt for scenv variables",
5
5
  "repository": {"type": "git", "url": "https://github.com/PKWadsy/scenv"},
6
6
  "publishConfig": {"access": "public", "provenance": true},