Help us shape the future of Go! Take the 2026 Go Developer Survey

scaffold

package
v1.6.8 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package scaffold provides the shared write-confinement and template engine for scaffolding verbs across this repository.

Every output goes through os.OpenRoot(root), so no path resolves outside --root; a preflight walks each output path with Lstat and refuses a symlink anywhere on it, a file where a directory goes, and an existing file. Only fs.ErrNotExist counts as free; any other lookup error is reported and nothing is written. Each file is created O_CREATE|O_EXCL, so a file or dangling symlink raced in after the preflight is refused. A failure part-way cleans up whatever this run created.

Index

Constants

This section is empty.

Variables

View Source
var BeforeCreate func(rel string)

BeforeCreate is Write's production default hook: it runs between the preflight and each file's creation, and is nil. A test that races a file in gets its own hook as a parameter of WriteWith instead of swapping this.

Functions

func Check

func Check(root string, outs []Planned) ([]string, error)

Check is Write's dry run: the same preflight over every planned file, and the paths Write would lay down, with nothing written.

func Dispatch

func Dispatch(verb string) string

Dispatch is the case a scaffolded verb needs in its tool's dispatch switch, calling the function verb.go.tmpl declares. new-verb prints it and never edits the switch itself.

func DispatchNote

func DispatchNote(tool, verb string) string

DispatchNote is what new-verb prints after the files it wrote: where the case goes, then the case itself, indented as it sits in the switch.

func Mkdirs

func Mkdirs(r *os.Root, dir string, made *[]string) error

Mkdirs creates dir and its missing parents inside r, one element at a time, recording each created directory. An element already present must be a real directory.

func Preflight

func Preflight(r *os.Root, rel string) error

Preflight walks rel one element at a time with Lstat so no symlink is followed: a symlink anywhere on the path is refused, as is a file where a directory goes and a final file that already exists. The first element that does not exist ends the walk.

func Render

func Render(fs embed.FS, templatePath string, data any) ([]byte, error)

Render executes a template from fs with custom delims [[ ]] to prevent clashes with Go source syntax. If the target is Go source, it passes it through format.Source (gofmt).

func Write

func Write(root string, outs []Planned) (written []string, err error)

Write lays the planned files into root, confined strictly to it, with the BeforeCreate hook.

func WriteWith

func WriteWith(root string, outs []Planned, beforeCreate func(rel string)) (written []string, err error)

WriteWith is Write with the caller's own before-create hook, run between the preflight and each file's creation; a nil hook writes nothing between. The hook is the per-test seam for racing a collision in beside a planned file, so no test assigns the package-level BeforeCreate.

Types

type Planned

type Planned struct {
	Rel  string
	Data []byte
}

Planned is one rendered file and where it lands, slash-separated and relative to the checkout root.

func RuleFiles

func RuleFiles(root, name string) ([]Planned, error)

RuleFiles renders a new class rule skeleton for root without writing it: what Write lays down, and what Check walks for a dry run.

func VerbFiles

func VerbFiles(root, tool, verb string) ([]Planned, error)

VerbFiles renders a new CLI verb skeleton for root without writing it: what Write lays down, and what Check walks for a dry run.

Jump to

Keyboard shortcuts

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