archetypes

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package archetypes discovers user-supplied required-structure archetype schemas from a set of configured root directories.

An archetype is a Markdown schema file whose basename (without the ".md" extension) is the archetype name. Resolvers search roots in order; earlier roots shadow later roots with the same name.

Index

Constants

View Source
const DefaultRoot = "archetypes"

DefaultRoot is the directory used when no archetype roots are configured. It is applied when Resolver.Roots is empty.

Variables

This section is empty.

Functions

func ValidateRoot

func ValidateRoot(root string) error

ValidateRoot returns an error when root is empty, absolute, or a parent-traversal path. Archetype roots are expected to be relative to the project root so they cannot reach outside it.

func ValidateRoots

func ValidateRoots(roots []string) error

ValidateRoots applies ValidateRoot to every entry in roots. It returns the first error encountered, or nil.

Types

type Entry

type Entry struct {
	Name string // basename without ".md"
	Path string // path relative to the resolver's root directory
	Root string // root directory that contained this archetype
}

Entry describes a discovered archetype.

type Resolver

type Resolver struct {
	Roots   []string
	RootDir string
	FS      fs.FS
}

Resolver finds archetypes across a list of root directories.

Paths in Resolver are interpreted relative to RootDir. When RootDir is empty, Resolver uses paths as-is relative to the current working directory. When FS is non-nil, directory reads use it; otherwise os.DirFS(RootDir) is used. This allows tests to inject an in-memory filesystem without touching the working directory.

func (*Resolver) AbsPath

func (r *Resolver) AbsPath(name string) (string, error)

AbsPath returns the filesystem path of the named archetype, joined with RootDir when RootDir is set.

func (*Resolver) Content

func (r *Resolver) Content(name string) ([]byte, error)

Content returns the raw bytes of the named archetype schema.

func (*Resolver) EffectiveRoots

func (r *Resolver) EffectiveRoots() []string

EffectiveRoots returns the list of root directories actually searched, substituting the default when none are configured. Each returned path is joined with RootDir when RootDir is non-empty, so the result is suitable for user-facing diagnostics.

func (*Resolver) List

func (r *Resolver) List() []Entry

List returns every discovered archetype, sorted by name. When two roots contain an archetype with the same name, only the entry from the earlier root is returned. Files whose names do not qualify as archetype names (see isArchetypeName) are skipped — this keeps README.md, dotfiles, and underscore-prefixed scratch files out of the archetype namespace.

List silently ignores every readDir error so it can never return a partial result with an error set. Use ListWithErrors when callers need to distinguish "root does not exist" from "root could not be read".

func (*Resolver) ListWithErrors

func (r *Resolver) ListWithErrors() ([]Entry, []error)

ListWithErrors is like List but also returns every non-ErrNotExist error encountered while reading a root. The entry slice is always populated with the archetypes that were successfully discovered; errors are returned alongside so callers can decide whether to surface them as warnings or fail fast.

func (*Resolver) Lookup

func (r *Resolver) Lookup(name string) (Entry, error)

Lookup returns the archetype with the given name. Missing names produce an error whose message names the searched roots. Reserved names (see isArchetypeName) produce an "unknown archetype" error even if the file exists on disk.

Jump to

Keyboard shortcuts

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