templates

package
v1.232.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CatalogStubs

func CatalogStubs(override string) (map[string]Configuration, error)

CatalogStubs returns lightweight Configuration entries (without Files) for the catalog, keyed by template name. They are display/selection placeholders; the caller hydrates the chosen template from its Source before generation.

func GetAvailableConfigurations

func GetAvailableConfigurations() (map[string]Configuration, error)

GetAvailableConfigurations loads available template configurations from the embedded templates filesystem. It scans the templates directory, loads each template configuration, and returns a map of template name to Configuration.

Returns:

  • map[string]Configuration: Map of template names to their configurations
  • error: Non-nil if reading the templates directory fails

The function returns an error only when the templates directory itself cannot be read. Individual template loading errors are silently skipped to allow partial success.

func HasScaffoldConfig

func HasScaffoldConfig(files []File) bool

HasScaffoldConfig checks if the configuration has a scaffold.yaml file.

Types

type CatalogEntry

type CatalogEntry struct {
	Name        string `yaml:"name"`
	Description string `yaml:"description"`
	Cloud       string `yaml:"cloud"`
	Tier        string `yaml:"tier"`
	Source      string `yaml:"source"`
	Version     string `yaml:"version"`
}

CatalogEntry describes a distributable scaffold template advertised by Atmos. Entries are resolved on demand: the list/select flows display them cheaply (no download) and only the selected template is fetched from its Source.

func LoadCatalog

func LoadCatalog() ([]CatalogEntry, error)

LoadCatalog parses the embedded scaffold catalog.

func (*CatalogEntry) ResolvedSource

func (e *CatalogEntry) ResolvedSource(override string) string

ResolvedSource returns the source to fetch this template from. When override is non-empty it points at a local base directory (override/<cloud>/<tier>) instead of the remote Source — used by CI to resolve templates from the working tree rather than the network. Otherwise the remote Source is pinned to defaultCatalogRef(). A full-commit-SHA ref fetches shallowly just like a branch ref would (see pkg/downloader's CustomGitGetter.cloneShallowCommit); no special-casing is needed here.

type Configuration

type Configuration struct {
	Name        string `yaml:"name"`
	Description string `yaml:"description"`
	TemplateID  string `yaml:"template_id"`
	Version     string `yaml:"version"`
	Source      string `yaml:"source"`
	TargetDir   string `yaml:"target_dir"`
	Files       []File `yaml:"files"`
	README      string `yaml:"readme"`
	// ResolvedRef is the immutable reference fetched for Source: a Git commit
	// SHA for Git sources (set by pkg/generator/source's resolveRemote) or a
	// manifest digest for OCI sources (set by resolveOCI). It is empty for
	// S3, HTTP, and local sources, which have no equivalent concept.
	// Runtime-only -- never part of a template's own manifest -- so it's
	// excluded from serialization. --update-strategy=rendered uses this to
	// pin a reproducible "before" state instead of relying on a ref string
	// that may name a mutable branch.
	ResolvedRef string `yaml:"-"`
	// LocalDir is the real, on-disk directory a remote source (oci://,
	// git::, https://, s3://) was fetched into (set by resolveOCI/
	// resolveRemote), valid for the lifetime of the generation run that
	// fetched it. Source itself gets overwritten with the original remote
	// reference string right after fetching, for display/provenance
	// purposes -- see resolveOCI's own comment on that overwrite -- so it
	// is no longer a real, resolvable path by the time a scaffold.yaml is
	// re-parsed later in the same run (e.g. by RunSetupForm). LocalDir
	// preserves the one that still is. Empty for a local-directory or
	// embedded template, neither of which has a separate fetch directory
	// distinct from Source. Runtime-only, like ResolvedRef -- excluded
	// from serialization, and never copied into a persisted project
	// record. Use IncludeSourceDir, not this field directly, to decide
	// what a template's own local !include targets resolve against.
	LocalDir string `yaml:"-"`
}

Configuration represents a template configuration loaded from the embedded filesystem. It contains metadata about a scaffold template including its name, description, and the collection of files to be generated. Key fields:

  • Name: Human-readable template name
  • Description: Brief description of the template's purpose
  • TemplateID: Unique identifier for the template
  • Version: Template version from scaffold.yaml metadata
  • Source: Where the template came from ("embedded", a local path, ...)
  • TargetDir: Default target directory for template output
  • Files: Collection of files/directories in this template
  • README: Optional README content for the template

func LoadConfigurationFromDir

func LoadConfigurationFromDir(name, dir string, opts ...LoadOption) (*Configuration, error)

LoadConfigurationFromDir loads a template configuration from a local directory on disk (e.g. a template referenced by `source:` in the `scaffold.templates` section of atmos.yaml). The directory is read with the same rules as embedded templates: scaffold.yaml provides metadata and the questionnaire, .tmpl files and atmos:template magic comments mark templates.

func (*Configuration) IncludeSourceDir added in v1.231.0

func (c *Configuration) IncludeSourceDir() string

IncludeSourceDir returns the directory a template's own local !include targets should resolve against -- which is deliberately not always Source (see LocalDir's own doc comment for why Source alone can't be trusted for this once a remote template has been fully hydrated, and SourceEmbedded's own doc comment for why the literal "embedded" string must never be treated as a real directory either):

  • LocalDir when set (a remote source: Source itself now holds the original remote reference string, not a real path).
  • A fixed, syntactically valid absolute directory that can never coincidentally exist, for an embedded template (Source holds the config.SourceEmbedded sentinel, not a real directory) -- so a local !include target fails cleanly instead of resolving against the process's CWD.
  • Source unchanged otherwise -- a local-directory template, where Source already is a real, resolvable directory.

type File

type File struct {
	Path        string      `yaml:"path"`
	Content     string      `yaml:"content"`
	IsDirectory bool        `yaml:"is_directory"`
	IsTemplate  bool        `yaml:"is_template"`
	Permissions os.FileMode `yaml:"permissions"`
}

File represents an embedded template file used by the generator. This struct is specifically for files loaded from the embedded filesystem (embed.FS) and differs from other File types in the codebase:

  • engine.File: Used for runtime template processing and file generation
  • types.File: Used for API/DTO models and general file representations

Use this File type when:

  • Working with generator templates loaded from embedded assets
  • Loading template configurations from the embedded filesystem
  • Representing files before they are processed by the templating engine

Key fields:

  • Path: Relative path within the template
  • Content: Raw file content (may contain template syntax if IsTemplate is true)
  • IsDirectory: Whether this represents a directory structure
  • IsTemplate: Whether content should be processed as a Go template
  • Permissions: Unix file permissions to apply when creating files

type LoadOption added in v1.229.0

type LoadOption func(*loadOptions)

LoadOption customizes how LoadConfigurationFromDir reads a template source directory.

func WithExcludePath added in v1.229.0

func WithExcludePath(absPath string) LoadOption

WithExcludePath excludes the top-level entry under dir that contains absPath from the template source walk, when absPath resolves inside dir. Used to keep a scaffold run's own resolved target directory -- when it lands inside a `source: "."` template's own tree -- from being re-copied into itself as template content on the next run. The whole shared top-level container is excluded, not just the literal target path: a template that nests multiple named outputs under one container directory (e.g. `generated/<name>`) would otherwise still leak OTHER, previously generated sibling directories back in as verbatim content, since only an exact-target-path exclusion wouldn't cover them. See tests/fixtures/scenarios/scaffold-matrix-freetext for the fixture that exposed this: repeated local `atmos test` runs compounded its own `generated/` output into itself, reaching 47,000+ self-nested directories before this fix.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL