String option

Learn how to define text options for templates.

String options accept a text value. You can also restrict the input to a predefined list with the choices property.

Example

The following template greets the user by name:

template.json5
{  "$schema": "https://schema.croct.com/json/v1/template.json",  "title": "Greeting",  "description": "Prints a greeting.",  "options": {    "name": {      "type": "string",      "description": "The name to greet.",      "default": "World"    }  },  "actions": [    {      "name": "print",      "semantics": "info",      "message": "Hello, ${options.name}!"    }  ]}

You can pass the option directly as a flag:

npx croct@latest use template.json5 --name Alice

This prints Hello, Alice!. If you omit the flag, the CLI prompts for the value and falls back to the default World.

Restricted choices

When choices is set, the CLI displays a selection prompt instead of a free-text input:

template.json5
{  "$schema": "https://schema.croct.com/json/v1/template.json",  "title": "Choose color",  "description": "Prints the selected color.",  "options": {    "color": {      "type": "string",      "description": "The color to use.",      "choices": [        "red",        "green",        "blue"      ]    }  },  "actions": [    {      "name": "print",      "semantics": "info",      "message": "You chose ${options.color}."    }  ]}
npx croct@latest use template.json5 --color green

This prints You chose green..

Properties

The following list describes the properties for string options:

type
string

The option type. Always string for string options.

description
string

A description displayed when prompting the user.

default(optional)
string

The default value used when the user does not provide one.

choices(optional)
Array<string>

A list of allowed values for the option.

When specified, the CLI displays a selection prompt instead of a free-text input.