Skip to main content

Globals

Beyond Context, every script has access to a small set of introspection globals and enum constants. None of them require require().

archetect

The archetect global describes the binary / process / platform — information that is identical across consecutive invocations. Per-invocation state (switches, answers) lives on archetype instead. All fields are also available inside templates.

FieldTypeDescription
archetect.versionstringFull version string (e.g., "3.0.0")
archetect.version_majorintegerMajor version number
archetect.version_minorintegerMinor version number
archetect.version_patchintegerPatch version number
archetect.is_offlinebooleantrue when launched in offline mode (--offline)
archetect.is_headlessbooleantrue when launched in headless mode (no interactive prompts)
archetect.locals_enabledbooleantrue when local checkouts are configured
archetect.envtablePlatform info (below)

archetect.env

FieldTypeDescription
osstringTarget OS (e.g., "linux", "macos", "windows")
archstringTarget architecture (e.g., "x86_64", "aarch64")
familystring"unix" or "windows"
is_unixbooleanfamily == "unix"
is_windowsbooleanfamily == "windows"
is_macosbooleanos == "macos"
if archetect.env.is_windows then
context:set("script-ext", "ps1")
else
context:set("script-ext", "sh")
end

archetype

The archetype global describes the currently-rendering archetype: manifest metadata plus the parameters supplied for this render. Also available inside templates.

MemberTypeDescription
archetype.descriptionstringDescription from the manifest
archetype.directorystringRoot directory path of the archetype
archetype.destinationstringAbsolute path where files are being rendered (tracks -d)
archetype.authorsstring[]Author list from the manifest
archetype.switchestableSwitches supplied to this invocation
archetype.answers()tableFresh table of the pre-supplied answers
archetype.mount_key()string?Catalog map-key when running as a staged library
archetype.is_library()booleantrue when executing inside a staged library
archetype.is_standalone()booleantrue when not mounted as a staged library
archetype.include_path(rel)stringMount-aware include path for templates

archetype.switches.is_enabled(name)

if archetype.switches.is_enabled("debug") then
log.info("debug switch enabled")
end

Returns true when the named switch was supplied to the current invocation (via -s name or a catalog entry). Note the dot call — switches is a plain table, not an object. There is no top-level switches global. See Switches & Conditionals.

archetype.answers()

local answers = archetype.answers()
if answers["organization"] then ... end

Returns a fresh table (each call) of the raw answers supplied by the CLI, answer files, or a parent archetype. Useful for advanced patterns where you need to inspect answers independently of a Context — normally the pre-loading done by Context.new() is all you need.

Library helpers: mount_key, is_library, is_standalone, include_path

These support archetypes that run as staged libraries — mounted by a parent's catalog entry with library: true. See Libraries.

archetype.mount_key() --> string | nil
archetype.is_library() --> boolean
archetype.is_standalone() --> boolean
archetype.include_path(rel) --> string
  • mount_key() returns the catalog map-key the library was mounted under. It returns nil from the parent's own script and from a library running standalone (e.g. via a direct archetect render).
  • is_library() is true exactly when mount_key() is non-nil; is_standalone() is its complement.
  • include_path(rel) builds a path for template {% include %} directives. In library mode it returns "<mount_key>/<rel>"; standalone it returns rel unchanged (a standalone library's includes/ is on the search path without a prefix).
-- In a library that publishes an include for its consumers:
context:set("editorconfig_include", archetype.include_path("editorconfig-rust.atl"))

Case, Cases, and CaseStyle

Case expansion turns one prompted value into a family of consistently-cased keys and values. Full guide: Casing.

Case.* constants

Case holds one CaseStyle constant per style:

ConstantExample output
Case.Snakemy_project
Case.PascalMyProject
Case.CamelmyProject
Case.Kebabmy-project
Case.TrainMy-Project
Case.ConstantMY_PROJECT
Case.TitleMy Project
Case.Lowermy project
Case.UpperMY PROJECT
Case.SentenceMy project
Case.Packagemy.project
Case.Directorymy/project
Case.CobolMY-PROJECT
Case.Pluralmy projects
Case.Singularmy project

CaseStyle:apply(input)

Every Case.* constant can transform a string directly:

local pascal = Case.Pascal:apply("order service") --> "OrderService"

Cases.* constructors

FunctionReturnsDescription
Cases.programming()CaseSpecSnake, Pascal, Camel, Kebab, Train, Constant
Cases.all()CaseSpecAll 13 auto styles: the programming six plus Title, Lower, Upper, Sentence, Package, Directory, Cobol (no Plural/Singular)
Cases.set(...)CaseSpecA custom set of Case.* styles
Cases.fixed(key, style)CaseSpecStore the value transformed by style under the exact key key
Cases.input(key)CaseSpecStore the raw, untransformed input under the exact key key

With auto styles (programming, all, set), both the key and the value are transformed per style. Prompting for "project-name" with Cases.programming() and an input of My Project stores:

KeyValue
project-nameMy Project
project_namemy_project
projectNamemyProject
ProjectNameMyProject
Project-NameMy-Project
PROJECT_NAMEMY_PROJECT

Combine constructors by passing a list:

context:prompt_text("Project Name:", "project-name", {
cases = { Cases.programming(), Cases.fixed("project-title", Case.Title) },
})

Existing

Policy enum for handling files that already exist at the destination, used as the if_exists option in rendering functions.

ConstantBehavior
Existing.OverwriteReplace existing files
Existing.PreserveKeep existing files unchanged (default)
Existing.PromptAsk the user what to do (interactive)
Existing.ErrorFail the render — useful for CI / idempotent pipelines
directory.render("contents", context, { if_exists = Existing.Overwrite })

Location

Path-resolution scope enum for file.exists / file.read, used as the within option.

ConstantResolves against
Location.ArchetypeThe archetype source root (default)
Location.DestinationThe render destination — honors -d. Use this to inspect the output tree.
Location.CwdThe actual process working directory. Diverges from Destination when -d is set.
if file.exists(".git", { within = Location.Destination }) then
log.info("destination is already a git repository")
end

exit()

exit()

Cleanly terminates the script. It does not raise a user-visible error — it signals successful completion. Use for early termination when nothing further needs to happen:

if not context:prompt_confirm("Continue?", "continue", { default = true }) then
output.print("Nothing to do.")
exit()
end