# 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`](#choices-prop) property.

## Example

The following template greets the user by name:

**template.json5**

```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:

```sh
croct 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`](#choices-prop) is set, the CLI displays a selection prompt instead of a free-text input:

**template.json5**

```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}."
    }
  ]
}
```

```sh
croct 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`: `string` (optional)

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

- `choices`: `Array<string>` (optional)

  A list of allowed values for the option.

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

## Explore

- [Options overview](/reference/cli/templates/options/overview): Learn how template options work.
- [Expressions](/reference/cli/templates/expressions): Learn how to use options in expressions.
