LogoCyanPrint
TemplatesReferenceSDK Reference

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 IInquirer
const 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

ValueTypeMethod
0Texttext()
1DateSelectdateSelect()
2Selectselect()
3Checkboxcheckbox()
4Passwordpassword()
5Confirmconfirm()

Object Form Properties

Properties vary by question type:

Common Properties

PropertyTypeRequiredDescription
typeQuestionTypeYesQuestion type enum
idstringYesUnique key for answer storage
messagestringYesQuestion displayed to user
descstringNoHelp text / description

Type-Specific Properties

PropertyTypeAvailable ForDescription
defaultstringText, DateDefault value
defaultbooleanConfirmDefault value
initialstringTextInitial input value
validate(input) => string | nullText, Password, DateValidation function
optionsstring[]Select, CheckboxAvailable choices
errorMessagestringConfirmCustom error message
confirmationstringPasswordConfirmation prompt text
minDateDateDateMinimum selectable date
maxDateDateDateMaximum 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 answer
const 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.