Array option
Learn how to define list options for templates.
Array options accept a list of values, such as dependencies to install or components to import.
Example
The following template greets a list of people:
template.json5
{ "$schema": "https://schema.croct.com/json/v1/template.json", "title": "Greeting", "description": "Greets a list of people.", "options": { "names": { "type": "array", "description": "The names to greet.", "default": ["World"] } }, "actions": [ { "name": "print", "semantics": "info", "message": "Hello, ${options.names.join(', ')}!" } ]}You can pass the values as a JSON array:
npm
npx croct@latest use template.json5 --names '["Alice", "Bob"]'This prints Hello, Alice, Bob!.
Array values support expression methods like .length, .join(), .includes(), and index access (options.names[0]).
Properties
The following list describes the properties for array options:
- typestring
The option type. Always array for array options.
- descriptionstring
A description displayed when prompting the user.
- default(optional)Array<any>
The default value used when the user does not provide one.