inquirerer 4.5.2 → 4.6.0
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 +36 -0
- package/esm/prompt.js +8 -0
- package/package.json +2 -2
- package/prompt.js +8 -0
- package/question/types.d.ts +1 -0
package/README.md
CHANGED
|
@@ -146,8 +146,10 @@ interface BaseQuestion {
|
|
|
146
146
|
default?: any; // Default value
|
|
147
147
|
defaultFrom?: string; // Dynamic default from resolver (e.g., 'git.user.name')
|
|
148
148
|
setFrom?: string; // Auto-set value from resolver, bypassing prompt entirely
|
|
149
|
+
optionsFrom?: string; // Dynamic options from another answer's value
|
|
149
150
|
useDefault?: boolean; // Skip prompt and use default
|
|
150
151
|
required?: boolean; // Validation requirement
|
|
152
|
+
skipPrompt?: boolean; // Skip prompting entirely (field still in man pages / CLI flags)
|
|
151
153
|
validate?: (input: any, answers: any) => boolean | Validation;
|
|
152
154
|
sanitize?: (input: any, answers: any) => any;
|
|
153
155
|
pattern?: string; // Regex pattern for validation
|
|
@@ -156,6 +158,40 @@ interface BaseQuestion {
|
|
|
156
158
|
}
|
|
157
159
|
```
|
|
158
160
|
|
|
161
|
+
#### Skipping Prompts
|
|
162
|
+
|
|
163
|
+
Use `skipPrompt: true` to skip interactive prompting for a question entirely. The field is omitted from the answers object unless the user explicitly passes it via a CLI flag. This is useful for fields with backend-managed defaults where the CLI should not prompt, but should still allow overrides.
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
const questions: Question[] = [
|
|
167
|
+
{
|
|
168
|
+
type: 'text',
|
|
169
|
+
name: 'username',
|
|
170
|
+
message: 'Username',
|
|
171
|
+
required: true
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
type: 'text',
|
|
175
|
+
name: 'status',
|
|
176
|
+
message: 'Account status',
|
|
177
|
+
skipPrompt: true // Won't prompt, but user can pass --status active
|
|
178
|
+
}
|
|
179
|
+
];
|
|
180
|
+
|
|
181
|
+
const result = await prompter.prompt({}, questions);
|
|
182
|
+
// { username: 'john' } — status is not included
|
|
183
|
+
|
|
184
|
+
const result2 = await prompter.prompt({ status: 'active' }, questions);
|
|
185
|
+
// { username: 'john', status: 'active' } — CLI flag override works
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Key behaviors:
|
|
189
|
+
- The question still appears in generated man pages
|
|
190
|
+
- CLI flag overrides (e.g. `--status active`) still work
|
|
191
|
+
- The field is simply left out of the answers if not provided
|
|
192
|
+
- Different from `when`: `skipPrompt` is unconditional, while `when` depends on other answers
|
|
193
|
+
- Different from `useDefault`: `skipPrompt` does not apply a default value
|
|
194
|
+
|
|
159
195
|
### Non-Interactive Mode
|
|
160
196
|
|
|
161
197
|
When running in CI/CD or without a TTY, inquirerer automatically falls back to default values:
|
package/esm/prompt.js
CHANGED
|
@@ -360,6 +360,14 @@ export class Inquirerer {
|
|
|
360
360
|
ctx.nextQuestion();
|
|
361
361
|
continue;
|
|
362
362
|
}
|
|
363
|
+
// Skip prompt entirely if skipPrompt is set.
|
|
364
|
+
// The question still appears in man pages and CLI flag overrides still work
|
|
365
|
+
// (handled by the `question.name in obj` check above), but no interactive
|
|
366
|
+
// prompt is shown. The field is simply left out of the answers object.
|
|
367
|
+
if (question.skipPrompt) {
|
|
368
|
+
ctx.nextQuestion();
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
363
371
|
// Apply default value if applicable
|
|
364
372
|
// this is if useDefault is set, rare! not typical defaults which happen AFTER
|
|
365
373
|
// this is mostly to avoid a prompt for "hidden" options
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inquirerer",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"author": "Constructive <developers@constructive.io>",
|
|
5
5
|
"description": "TypeScript-first library for building beautiful CLI interfaces with interactive prompts",
|
|
6
6
|
"main": "index.js",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"makage": "0.1.10",
|
|
47
47
|
"string-width": "4.2.3"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "52e4d3ecdb5d323b70c2bb0269ff3ccd41cc85b9"
|
|
50
50
|
}
|
package/prompt.js
CHANGED
|
@@ -367,6 +367,14 @@ class Inquirerer {
|
|
|
367
367
|
ctx.nextQuestion();
|
|
368
368
|
continue;
|
|
369
369
|
}
|
|
370
|
+
// Skip prompt entirely if skipPrompt is set.
|
|
371
|
+
// The question still appears in man pages and CLI flag overrides still work
|
|
372
|
+
// (handled by the `question.name in obj` check above), but no interactive
|
|
373
|
+
// prompt is shown. The field is simply left out of the answers object.
|
|
374
|
+
if (question.skipPrompt) {
|
|
375
|
+
ctx.nextQuestion();
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
370
378
|
// Apply default value if applicable
|
|
371
379
|
// this is if useDefault is set, rare! not typical defaults which happen AFTER
|
|
372
380
|
// this is mostly to avoid a prompt for "hidden" options
|