Skip to content
Edit this page

Questions

Defaults must have the question's declared type, including defaults produced by expressions. An incorrectly typed default is rejected before it can be rendered or recorded for a later update.

Questions collect the values a template needs. They are declared in template.toml under [questions.<name>].

[questions.project_name]
type = "string"
prompt = "Project name"
help = "Used for the package name and the README title"
Key Type Meaning
type string string, boolean, integer, float, choice, multi_choice, list.
min, max number Inclusive numeric bounds for integer or float.
min_length, max_length integer Inclusive Unicode character bounds for string.
min_items, max_items integer Inclusive item-count bounds for list.
item_min_length, item_max_length integer Inclusive Unicode character bounds for each list item.
prompt string Shown to the user. Defaults to the question's name.
help string A dimmed explanation beside the question; text entry moves to the next line.
default any / expression The pre-filled value.
when expression Ask only if this evaluates truthy.
default_when_skipped boolean Inject default into the context even when when is false.
choices array The offered choices, for choice and multi_choice.
choices_from string A reference to a list, instead of choices.
legacy table Old saved choice values mapped directly to current values. Choice kinds only.
min_choices integer Inclusive minimum selections for multi_choice, defaulting to zero.
max_choices integer Inclusive maximum selections for multi_choice, unlimited when omitted.
default_from string The prompt default: git:<key>, or an expression over the seed namespaces below.
fuzzy boolean Fuzzy search instead of substring typeahead in choice/multi_choice prompts. Defaults to false.
pattern string A regular expression every answer must match. string only.
message string What to say when pattern rejects an answer.
item_pattern string A regular expression each string in a list answer must match.
item_message string What to say when item_pattern rejects an item.

Renaming saved choice values

When retiring a choice value, declare its replacement on the question:

[questions.license]
type = "choice"
choices = ["MIT", "Apache-2.0"]
legacy = { mit = "MIT", apache = "Apache-2.0" }

update translates recorded answers before validation and rendering, then saves the current values in .config/git.tpl.toml as an unstaged edit. For multi_choice, each selected value is translated, preserving order and duplicates. Recorded comma-separated strings are converted to arrays before translation. Several old values can map to the same current value; selection bounds still count distinct values. Matching is exact, and maps refer to choice values, not display labels or question names. Explicit CLI/file answers, defaults and prompts must already use current values.

Map every supported historical spelling directly to its current value so users can skip template releases. Chains, cycles, self-maps, and legacy sources still offered as choices are rejected. Literal choices must include every target. With choices_from, unused targets may be filtered out, but any translated answer must be currently offered. Inactive questions and empty dynamic catalogues retain their normal skipping behavior. An inherited question override replaces the whole declaration, including legacy.

Dry runs and dirty previews perform the same translation without saving configuration. Failed validation leaves configuration and the rendered ref unchanged. See updating saved choices.

Types

[questions.project_name]
type = "string"
prompt = "Project name"
[questions.ci]
type = "boolean"
prompt = "Enable CI?"
default = true
[questions.port]
type = "integer"
prompt = "Port"
default = 8080
min = 1
max = 65535
[questions.timeout]
type = "float"
prompt = "Request timeout"
default = 2.5
min = 0.1
max = 60.0
[questions.license]
type = "choice"
prompt = "License"
choices = ["MIT", "Apache-2.0"]

Choices can carry labels and come from a data source — see Choices.

[questions.features]
type = "multi_choice"
prompt = "Features"
choices = ["serde", "async", "cli"]
default = ["serde"]

The answer is a list, so {% if 'serde' in features %} works in templates.

Optional min_choices and max_choices constrain the number of selections:

[questions.categories]
type = "multi_choice"
choices = ["command-line-utilities", "development-tools", "web-programming"]
min_choices = 0
max_choices = 2
default = []

Bounds are inclusive nonnegative integers and apply only to multi_choice. Omit either bound to leave that end unrestricted; max_choices = 0 permits only an empty answer. The minimum must not exceed the maximum or the number of distinct available choices. An upper bound larger than the catalogue is allowed. An empty dynamically filtered catalogue still skips the question, including when a minimum is set. Bounds count distinct selected strings: ["serde", "serde"] counts as one selection. Defaults, supplied answers and recorded answers retain their contents and order, including duplicates. Interactive catalogues offer each value once, keeping its first label, help text and position. This also applies to dynamically resolved choices.

Invalid interactive selections stay in the selector for correction. Defaults, supplied answers and recorded answers must satisfy the same bounds; an invalid count fails with tpl::eval::choice_count rather than truncating the answer. Bounds also apply to defaults injected by default_when_skipped.

[questions.modules]
type = "list"
prompt = "Module IDs"
default = []
item_pattern = "^[a-z0-9]+(-[a-z0-9]+)*$"
item_message = "use lowercase words and hyphens"

The answer is an ordered array of strings, with no predefined choices. Supply CLI answers as JSON arrays, e.g. --answer 'modules=["jira","confluence"]'. An empty array is valid unless min_items requires entries. Each item must be nonempty and is checked independently against item_pattern.

Types are enforced. For existing projects, update and dirty previews can migrate saved comma-separated strings to either array kind before applying the usual validation; see saved list migration. This compatibility rule does not apply to answer files or defaults. Supplying --answer port=nope for an integer question is an error naming the question, the value and the expected type — not a silent coercion to a string.

Primitive constraints

Every bound is inclusive; omit either end to leave it unrestricted. Integer questions require integer answers and integer bounds, with exact whole-number comparisons. Float questions accept integer and floating-point answers and bounds, compared as floating-point numbers. NaN and positive or negative infinity are rejected even without bounds. Typed strings such as "2.5" remain strings; only CLI text is parsed as the declared numeric type.

[questions.project_name]
type = "string"
min_length = 2
max_length = 64
pattern = "^[a-z][a-z0-9-]*$"

[questions.modules]
type = "list"
min_items = 1
max_items = 10
item_min_length = 2
item_max_length = 32
item_pattern = "^[a-z][a-z0-9-]*$"

String and item lengths count Unicode scalar values rather than UTF-8 bytes or grapheme clusters. For example, é has length one, while e followed by a combining accent has length two. Answers are not normalized or trimmed before counting. Length constraints and existing patterns must both pass. List counts include every entry in order, including duplicates; entries must still be nonempty strings. max_length must be greater than zero and at least min_length when both are set. max_items = 0 allows only an empty list.

Lengths and counts must be nonnegative integers, minimums must not exceed maximums, and constraints on incompatible question types are rejected when the manifest is loaded. List counts use min_items/max_items; min_choices/max_choices remain exclusive to multi_choice.

The same checks apply to interactive answers, CLI and answer-file input, selected literal or expression defaults, computed-derived defaults, recorded answers, and defaults injected by default_when_skipped. An unused default is not evaluated when an explicit answer is supplied. Interactive prompts explain invalid input and retry the current question or list item. Non-interactive failures identify the question and violated bound; values are never clamped or truncated. An update whose recorded answer no longer satisfies a constraint fails before changing the rendered ref or config.

List entry errors retry the current entry; blank completion below min_items requests more entries. At max_items, the list finishes once any remaining defaults have been explicitly removed with -. Non-interactive failures identify the question and violated bound: tpl::eval::numeric_bound, tpl::eval::string_length, tpl::eval::item_count, or tpl::eval::invalid_list for invalid entries.

Searching choices interactively

Choice and multi-choice prompts support case-insensitive substring typeahead by default. Type to filter labels, use Up/Down to move, and Enter to confirm. PageUp/PageDown jump through the current viewport of results, including filtered lists, and stop at the endpoints. Per-choice help is displayed but is not searched. Escape clears an active query first; with an empty query it cancels the prompt. Ctrl-C cancels a selection immediately.

Enable noncontiguous fuzzy matching on an individual question with fuzzy = true:

[questions.command]
type = "choice"
choices = ["cargo build", "cargo test"]
fuzzy = true

The same option works for data-driven lists:

[data.countries]
source = "data/countries.json"

[questions.country]
type = "choice"
choices_from = "data.countries"
fuzzy = true

For multi-choice questions, Space toggles the highlighted option rather than inserting a query space. Checked options remain checked when filtered out, and confirmed answers retain original choice order. Search changes presentation only: supplied answers, defaults and unattended rendering use the complete choice list. fuzzy = true on another question type is refused.

Interactive prompts require a terminal on stderr; redirecting stdout remains supported. For automation, use --answer, --answers-from, or --defaults instead of piping keystrokes. Text input, selections and confirmations use choisir's shared theme. Escape and Ctrl-C cancel text input and confirmations cleanly, including structured cancellation under --json. Boolean confirmations support Y/N shortcuts, arrow-key selection, and Enter to accept the selected default. Their Yes/No controls always appear below the question and its help, including when help is absent.

Help appears beside the question, dimmed and separated with -. Text entry moves below a help-bearing heading, while a question without help keeps input on the same line:

Crate name - Also the GitHub repository name. Lowercase, dash-separated.
›

GitHub owner › noirbizarre

A text default is a dimmed ghost preview after the input marker. Enter accepts it; typing replaces it, and deleting all typed input restores the preview. Whitespace-only submission also accepts the default. Choice descriptions appear beside their labels as label - help, dimmed independently of selection and search highlights. They remain excluded from search and accepted summaries; long descriptions are truncated to fit the terminal.

Conditional questions

when is an expression evaluated against everything resolved so far:

[questions.project_type]
type = "choice"
prompt = "Project type"
choices = ["library", "application"]

[questions.cli]
type = "boolean"
prompt = "Create a CLI?"
when = "{{ project_type == 'application' }}"
default = true

A question whose when is false is not asked, and has no value. It is absent from the context, not null or false.

Null values are preserved in data and computed results, but question types remain non-nullable. A null answer or a default expression returning none fails the applicable question's type validation. See null and absence.

That distinction is deliberate. In a template:

{% if cli is defined and cli %}
[[bin]]
name = "{{ package_name }}"
{% endif %}

cli is defined tells you the question was relevant; cli tells you the answer. Collapsing the two would make "not applicable" indistinguishable from "declined", and templates would render an empty [[bin]] section for libraries.

git tpl lint warns (tpl::lint::unguarded_gate) about a file that reads cli without this guard.

Keeping a default when skipped

Guarding every read is the right default, but for some questions the skipped case is never meant to differ from the default at the call sites that read it — migrating a template from a tool that keeps a skipped question's default in context is the common reason to reach for this. default_when_skipped = true opts a single question into that behaviour:

[questions.docs]
type = "boolean"
default = true

[questions.docs_accent]
type = "string"
when = "{{ docs }}"
default = "blue"
default_when_skipped = true
accent: {{ docs_accent }}

accent: blue for every answer set now, docs true or false — no guard needed at this call site, or any other that reads docs_accent bare.

The question is still not asked, and its default still does not count as an answer: it is absent from .config/git.tpl.toml, from the answers digest in the commit trailers, and from the dependency graph's notion of what was answered. Only what a file body sees when it reads the name bare changes.

That comes at a real cost, paid deliberately: docs_accent is defined is now true whether docs is or is not, so this gives up the "not applicable vs. declined" distinction the guard idiom above exists to preserve — for this one question. git tpl lint stops warning about a bare read of it, because it is no longer a trap.

Two cases this does not cover, deliberately, for a first cut:

  • A choice/multi_choice question whose choices_from filters to nothing. That is a different skip from a false when, handled the same way today (absent, not null) but not extended by this flag.
  • A [computed] value that reads a default_when_skipped question. It sees the injected default like any other reachable name — nothing extra to configure — but gatedness itself is not propagated through computed, the same limitation tpl::lint::unguarded_gate already has.

See ADR-025.

Dynamic defaults

A default may be an expression:

[questions.package_name]
type = "string"
prompt = "Package name"
default = "{{ project_name | lower | replace(' ', '-') }}"

It is evaluated at prompt time, after everything it references has been resolved. You see the computed value pre-filled and can accept or replace it.

Machine-seeded defaults

Some values are facts about the person or the project, not about the template. default_from pre-fills the prompt from them, so you press Enter and move on:

[questions.author]
type = "string"
default_from = "git:user.name"
default = "anonymous"

git:<key> is the shorthand for a Git configuration value. The longer form is an expression, which is what you want when the answer has to be derived rather than read:

[questions.project_slug]
type = "string"
default_from = "{{ remote.name | default(dir.name) | slugify }}"
default = "my-project"

That reads: the repository's name where the project is pushed; failing that, the directory it lives in; slugified either way. A project cloned from git@github.com:me/Git Tpl.git offers git-tpl, and one created locally in ~/src/My Project offers my-project.

What an expression may read

Five namespaces, and only five:

Namespace Contents
git The Git configuration, dotted keys nested: git.user.name, git.user.email.
dir dir.name — the project directory's own name.
remote remote.name, remote.owner, remote.slug, remote.host, remote.url.
now UTC calendar/time components and ISO strings; see datetime seeds.
user user.name — the current OS account's login name; see user seeds.

For git@github.com:acme/widgets.git, remote is:

remote.name widgets
remote.owner acme — the whole path above the name, so a nested GitLab subgroup arrives whole
remote.slug acme/widgets
remote.host github.com
remote.url the URL as configured, with any credentials removed

The remote described is the one tpl.remote names, which is origin unless you have said otherwise.

Anything absent — no remote configured, a Git key never set — is undefined rather than empty, so | default(...) fires and the next candidate is used. That is why there is no default_filter key and no list form: a fallback chain is a pipe, and it composes with slugify and every other filter without any new syntax.

There is deliberately no dir.path. An absolute path is the value most likely to end up pasted into a rendered file, and a rendered file that contains /home/ada is a file that differs on every machine. It would also put your home directory on screen at a prompt. dir.name is already sluggable, which is what it is wanted for.

Only string questions accept default_from, in either form — a seed is text. The expression is parsed, and its namespaces checked, when the manifest is loaded rather than when the prompt appears, so a typo is your problem on your first render and never your users'.

Runtime acquisition and expression evaluation wait until immediately before an actual prompt. A false when, an empty choice catalogue, a supplied answer, or a compatible recorded answer reused by switch skips them entirely. A type-compatible personal [defaults] value also wins without reading or evaluating default_from. The machine context for derived expressions is captured at the first prompt that needs it and shared by later prompts in the same render. Like other machine seeds, these require a project repository; standalone use without one falls back to default. An acquisition or runtime expression error is reported only when that seed is needed; syntax and namespace errors still fail when the manifest is loaded, even for skipped questions.

It seeds the prompt, never the context

If the question is not asked — --defaults, tpl.interactive false, CI — default_from is not read at all and default applies. This is true of every form: the directory, remote, and current datetime can vary just as user.name does, and none of them may reach a rendered file on their own. Otherwise the same template would render two different trees on two machines, and determinism is what the whole ref model rests on. The value only becomes part of the render once a human has accepted it, at which point it is recorded in .config/git.tpl.toml like any other answer — so the project stays reproducible for someone whose checkout, remote or identity is different.

Precedence, highest first:

--answer  >  --answers-from  >  answers in .config/git.tpl.toml (update only)
          >  [defaults] (only when asked)  >  default_from (only when asked)
          >  default

A source that is unset, empty, or an expression that renders to nothing, is simply absent: the question falls back to its default.

The user's own [defaults] sits above default_from and follows the same seeds-the-prompt-only rule. default_from is the template author's guess about where an answer usually comes from; [defaults] is the person at the keyboard saying it outright, so the person wins.

User seeds

Suggest the current OS account's login name:

[questions.username]
type = "string"
default_from = "{{ user.name | default('developer') }}"

user.name is the OS login name, not the account's full name or the Git display name in git.user.name. It is read through native account APIs and captured once with the other machine seeds. If lookup fails or the name is blank or not valid UTF-8, user.name is undefined and | default(...) applies. Otherwise the name is preserved verbatim; use a filter such as slugify when a derived form is needed. Like all machine seeds, this requires interactive prompting with a project repository. It becomes a recorded answer only after confirmation and is never an ambient value in rendering or ordinary defaults.

Datetime seeds

Suggest the current UTC year for a copyright question:

[questions.copyright_year]
type = "string"
default_from = "{{ now.year }}"

Then use Copyright {{ copyright_year }} in rendered files. Accepting the suggestion records an ordinary string answer in .config/git.tpl.toml. Later updates reuse that answer, even in a different year; this initializes a year rather than updating it annually. For non-interactive use, supply the answer explicitly or add a stable ordinary default.

All now fields describe one instant captured when the first derived seed is needed in that render:

Field Type Example / range
now.year Integer 2026
now.month Integer 1–12
now.day Integer 1–31
now.hour Integer 0–23
now.minute Integer 0–59
now.second Integer 0–59
now.date String 2026-11-27
now.time String 14:05:09Z
now.datetime String 2026-11-27T14:05:09Z

The ISO strings use whole-second precision, zero-padded components, and Z for UTC time. Numeric fields can be used in expressions, but the rendered seed is always text for a string question. now is available only in default_from, never as an ambient value in an ordinary default or rendered file. See ADR-056.

Validation

A string question can constrain what it accepts with a regular expression:

[questions.package_name]
type = "string"
pattern = "^[a-z][a-z0-9-]*$"
message = "must be lowercase and start with a letter"

At the prompt, an answer that does not match is rejected and the question is asked again — a typo costs you one line, not the six answers you have already given.

> Package name: My Package
  `My Package` is not a valid answer for `package_name`

message is optional. Without it the pattern itself is quoted, which is honest but rarely as useful as a sentence.

It is a pattern, not an expression. An arbitrary validator would be code running on a template's behalf, and templates cannot execute code — see Security. The syntax is the usual one minus backtracking: no lookaround and no backreferences, so a pattern costs time linear in the answer's length however it is written.

Checked wherever an answer arrives. Not only at the prompt: --answer, --answers-from and the answers already recorded in .config/git.tpl.toml are all matched against it. So a template that narrows a pattern fails the next update of a project holding a value it would no longer accept, exactly as a withdrawn choice does:

`My-Thing` is not a valid answer for `slug`

    help: must be lowercase and start with a letter
        if this answer was recorded by an earlier render, the template has
        since narrowed what it accepts — edit `slug` in `.config/git.tpl.toml`

Rendering from a value the template has disowned would produce a commit nobody asked for.

Two things are rejected when the manifest loads rather than at the prompt: a pattern on any question that is not a string, and a pattern that does not compile. A message with no pattern is rejected too — it is almost always a pattern that was removed, leaving behind a sentence nothing would ever show.

Choices

Two things are chosen independently: how many answers a question takes, and where its choices come from.

choices — written inline choices_from — a reference
type = "choice" one answer, fixed list one answer, resolved list
type = "multi_choice" several answers, fixed list several answers, resolved list

All four combinations work. There is no multi_choice_from, because type = "multi_choice" with choices_from already is that:

[data.catalogue]
source = "data/features.toml"

[questions.features]
type = "multi_choice"
prompt = "Features"
choices_from = "data.catalogue.all"
default = ["serde"]

Use choices or choices_from, not both.

Labels

A choice is a bare string, or a table:

[questions.license]
type = "choice"
prompt = "License"
choices = [
  "Unlicense",
  { value = "MIT", label = "MIT License", help = "Short and permissive" },
  { value = "Apache-2.0", label = "Apache License 2.0", help = "Patent grant" },
]
default = "MIT"
Key Meaning
value What is recorded as the answer. Required, and must be a string.
label What is shown. Defaults to the value.
help Shown beside the label, for a choice that needs explaining.

Only the value is ever an answer. It is what appears in .config/git.tpl.toml, what --answer license=MIT takes, and what a template sees in {{ license }}. A label is presentation and nothing else — so rewording one changes no rendered file, produces no commit, and gives nobody a merge to perform. Answering with the label is an error, not a second spelling.

A data source uses the same shape, so a list can move from the manifest into a data file without being rewritten:

# data/features.toml
[[all]]
value = "serde"
label = "Serialisation"
help = "Derive Serialize and Deserialize"

[[all]]
value = "async"
label = "Async runtime"

Extra keys in a data file are ignored — a licence list carrying url and osi_approved beside value is normal. In the manifest they are an error, because there an unrecognised key is a typo.

Filtering choices

Choices are filtered with computed values, which are evaluated before the question that uses them. There is no per-choice when: [computed] already does this, for both inline and referenced lists, and one mechanism is easier to reason about than two.

A list that depends on an earlier answer:

[questions.kind]
type = "choice"
prompt = "Project kind"
choices = ["library", "application"]

[computed]
servers = "{{ ['nginx', 'caddy'] if kind == 'application' else [] }}"

[questions.server]
type = "choice"
prompt = "Web server"
choices_from = "servers"

Filtering a data source on an earlier answer:

[data.pythons]
source = "data/python.toml"

[computed]
usable = "{{ data.pythons.versions | selectattr('value', 'ge', minimum) | list }}"

[questions.max_python]
type = "choice"
choices_from = "usable"

Reshaping data that does not use value and label:

[computed]
licences = "{{ data.licences.all | map(attribute='id') | list }}"

[questions.license]
type = "choice"
choices_from = "licences"

Keeping expressions in template.toml rather than in data files is deliberate. A data file supplies values; it never supplies logic. That matters most for remote data, which is not pinned by the template revision.

A filter that leaves nothing skips the question. An empty list means "this does not apply", so the question is not asked and has no value — exactly as a false when leaves it, and server is defined still tells the two apart. A literal choices = [] is a different thing: it can never be answered, so it is rejected when the manifest loads.

When a choice is withdrawn

Narrowing a filter can leave a project holding an answer the template no longer offers. That is reported, not silently discarded:

`ap` is not a valid choice for `region`

    help: choose one of: eu, us
        if this answer was recorded by an earlier render, the template no
        longer offers it — edit `region` in `.config/git.tpl.toml`

Dropping it quietly would change the rendered tree and commit without anyone having asked for it.

Referencing a list

choices_from is a dotted path into the context — a data source, a computed value or an earlier answer — and must resolve to an array. If it resolves to a map or a string, the error says so and names the path:

Failed to evaluate question `license`.

  Template:    rust-library
  Reference:   data.licenses.ids
  Reason:      expected an array of choices, got a table

Evaluation order

Question order is not the order you wrote them in. It is derived.

git-tpl parses every expression in the manifest — when, default, choices_from, [computed] entries, and data source paths — extracts the names each one references, and builds a dependency graph. That graph is topologically sorted, and questions are asked in the resulting order.

The consequence: you never have to think about ordering. Declare package_name before project_name if it reads better; git-tpl still asks project_name first, because package_name's default depends on it.

Within that constraint, ties are broken by declaration order, so the sequence is stable across runs.

With [extends]

A template with a parent (see [extends]) is asked its parent's questions first, in the parent's own declaration order, then its own new ones — "declaration order" above means the position in this merged sequence, not the position in either manifest alone. A question the child redeclares by name replaces the parent's entirely and keeps the parent's position: overriding [questions.license] to change its default does not move it later in the prompt sequence just because the child wrote it last.

Errors caught before any prompt

The graph is validated up front, so these fail before you are asked anything:

Cycles.

Cyclic dependency in template `rust-library`.

  answers.a → answers.b → answers.a

  A question's `when`, `default` or `choices_from` may only reference
  values resolved before it.

Unknown references.

Unknown reference in template `rust-library`.

  Question:    package_name
  Expression:  {{ projct_name | lower }}
  Unknown:     projct_name

  Did you mean `project_name`?

Both are load-time errors. Answering six questions and then being told the seventh is unresolvable would be the worst possible time to find out.

Supplying answers non-interactively

git tpl init ../template --answer project_name=demo --answer license=MIT

A supplied answer skips its prompt but still participates in the graph, so anything depending on it resolves normally. Values are parsed according to the question's declared type.

--defaults accepts every default without prompting; a question with no default and no supplied answer is then an error. default_from is ignored here, because nothing on the machine can answer a question on the user's behalf — see Machine-seeded defaults.

On update, answers come from .config/git.tpl.toml. A question added to the template since the last render has no recorded answer, and is prompted for — or, with --defaults, takes its default. Either way the answer is written back to .config/git.tpl.toml.