Skip to main content

Answer Files

Answers pre-resolve prompts so renders can run partially or fully unattended. For a guide, see Answers and Automation.

File Formats

Answer files (-A/--answer-file <path>, repeatable) are flat-to-nested maps of answer keys to values. The format is chosen by file extension:

ExtensionFormat
.yaml, .ymlYAML
.jsonJSON

Any other extension is rejected with an error. (TOML is not supported.)

# answers.yaml
project_name: billing-service
port: 8080
enable_telemetry: true
features: [auth, metrics]
db:
host: localhost
port: 5432

-a key=value Syntax

Individual answers are supplied with -a/--answer key=value (repeatable). The pair splits on the first =; the key must be non-empty, the value may be empty.

Typed Values

The value is parsed as YAML, giving CLI answers the same type semantics as answer files. If YAML parsing fails, the value falls back to a plain string.

InputParsed as
-a count=42Integer 42
-a ratio=1.5Float 1.5
-a active=trueBoolean true
-a value=nullNil
-a tags=[a, b, c]Array of strings
-a "db={host: localhost, port: 5432}"Map
-a name=hello worldString "hello world"
-a zip='"01234"'String "01234" (YAML-quoted — stays a string)
-a key=Empty string (not null)
tip

Unquoted all-digit values become integers — standard YAML behavior. If you need a string (ZIP codes, phone numbers), YAML-quote it: -a zip='"01234"'.

Dotted Keys

Keys may contain dots for nested map access. Intermediate maps are created as needed, and siblings are preserved:

archetect render <source> -a db.host=localhost -a db.port=5432
# → { db: { host: "localhost", port: 5432 } }

Precedence

Answers are assembled in layers; later layers overwrite earlier ones for the same key:

OrderSource
1 (lowest)answers: from the merged configuration (defaults, user config, project config) — includes the git-seeded author_* answers
2-A/--answer-file files, in the order given (later files win)
3-a/--answer key=value pairs
4 (highest)answers: on the catalog entry being rendered

At prompt time, resolution for each key proceeds:

  1. If an answer exists for the key, it is used — the prompt is skipped.
  2. Otherwise, if the key is covered by -d/--use-default <key> or -D/--use-defaults-all (or the catalog entry's use_defaults/use_defaults_all), the prompt's default value is used.
  3. Otherwise, the user is prompted interactively. In --headless mode, an unresolved required prompt is a hard error.

Round-Tripping a Context

Inside a script, tostring(ctx) yields the context's data as YAML — equivalent to format.to_yaml(ctx) — and the output is a valid Archetect answer file. This makes captured contexts replayable:

-- archetype.lua
log.debug(tostring(ctx)) -- print the fully-resolved context as YAML

Save that output to a file and re-run non-interactively:

archetect render <source> -A captured-context.yaml --headless

See Testing and Debugging for how to use this in archetype development.