IInquirer Reference
Complete API reference for user input collection
IInquirer Reference
The IInquirer interface provides methods for collecting user input during template generation.
Import
import { StartTemplateWithLambda, IInquirer, QuestionType } from '@atomicloud/cyan-sdk';
Overview
The i parameter in StartTemplateWithLambda is an IInquirer instance:
StartTemplateWithLambda(async (i, d) => {// i is IInquirerconst name = await i.text('Project name?', 'project.name', 'Enter name');});
Methods
In shorthand forms, the third parameter is a help/description string. In object forms, use desc for the same purpose.
text()
Collect text input from the user.
Shorthand Form
const name = await i.text('Project name?', // message'project.name', // id (key)'Enter project name' // description);// Returns: string
Object Form
const name = await i.text({type: QuestionType.Text,id: 'project.name',message: 'Project name?',desc: 'Enter project name',default: 'my-project',validate: (input) => {if (!input) return 'Name is required';if (input.length < 3) return 'Minimum 3 characters';return null;}});
select()
Single selection from a list.
Shorthand Form
const license = await i.select('License?', // message['MIT', 'Apache-2.0', 'GPL-3.0'], // options'project.license', // id'Choose a license' // description);// Returns: string (selected option)
Object Form
const license = await i.select({type: QuestionType.Select,id: 'project.license',message: 'License?',desc: 'Choose a license',options: ['MIT', 'Apache-2.0', 'GPL-3.0']});
confirm()
Boolean yes/no confirmation.
Shorthand Form
const typescript = await i.confirm('Use TypeScript?', // message'project.typescript', // id'Add TypeScript config' // description);// Returns: boolean
Object Form
const typescript = await i.confirm({type: QuestionType.Confirm,id: 'project.typescript',message: 'Use TypeScript?',desc: 'Add TypeScript configuration',default: true});
checkbox()
Multiple selection from a list.
Shorthand Form
const features = await i.checkbox('Select features?', // message['ESLint', 'Prettier', 'Jest', 'Docker'], // options'project.features', // id'Choose features to include' // description);// Returns: string[] (selected options)
Object Form
const features = await i.checkbox({type: QuestionType.Checkbox,id: 'project.features',message: 'Select features?',desc: 'Choose features to include',options: ['ESLint', 'Prettier', 'Jest', 'Docker']});
password()
Hidden text input for sensitive data.
Shorthand Form
const apiKey = await i.password('Enter API key', // message'secrets.apiKey', // id'Your API key' // description);// Returns: string (hidden input)
Object Form
const apiKey = await i.password({type: QuestionType.Password,id: 'secrets.apiKey',message: 'Enter API key',desc: 'Your secret API key',validate: (input) => {if (!input) return 'API key is required';if (input.length < 20) return 'API key seems too short';return null;}});
Passwords should never be stored in generated files. Use for runtime configuration only.
dateSelect()
Date selection.
Shorthand Form
const deadline = await i.dateSelect('Project deadline?', // message'project.deadline', // id'Select target date' // description);// Returns: string (ISO date format)
Object Form
const deadline = await i.dateSelect({type: QuestionType.DateSelect,id: 'project.deadline',message: 'Project deadline?',desc: 'Select target date',validate: (dateString) => {const date = new Date(dateString);if (date < new Date()) return 'Deadline must be in the future';return null;}});
dateSelect() returns a string in ISO date format, not a Date object. Convert with new Date(dateString) if needed.
QuestionType Enum
| Value | Type | Method |
|---|---|---|
0 | Text | text() |
1 | DateSelect | dateSelect() |
2 | Select | select() |
3 | Checkbox | checkbox() |
4 | Password | password() |
5 | Confirm | confirm() |
Object Form Properties
Properties vary by question type:
Common Properties
| Property | Type | Required | Description |
|---|---|---|---|
type | QuestionType | Yes | Question type enum |
id | string | Yes | Unique key for answer storage |
message | string | Yes | Question displayed to user |
desc | string | No | Help text / description |
Type-Specific Properties
| Property | Type | Available For | Description |
|---|---|---|---|
default | string | Text, Date | Default value |
default | boolean | Confirm | Default value |
initial | string | Text | Initial input value |
validate | (input) => string | null | Text, Password, Date | Validation function |
options | string[] | Select, Checkbox | Available choices |
errorMessage | string | Confirm | Custom error message |
confirmation | string | Password | Confirmation prompt text |
minDate | Date | Date | Minimum selectable date |
maxDate | Date | Date | Maximum selectable date |
Note: validate and default are only available for certain question types. Select, Checkbox, and Confirm do not support custom validation functions. Select and Checkbox also do not support default values.
Keys and Namespacing
The id parameter is the key that determines answer storage and reuse:
// Same key = same answerconst name1 = await i.text('Name?', 'project.name', '...');const name2 = await i.text('Confirm?', 'project.name', '...');// name1 === name2
Always namespace your keys to prevent collisions in composed templates. See How to Use Keys.
Related
- How to Use Keys - Keys and namespacing
- Validate Input - Validation patterns
- Default Values - Setting defaults