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 ¶
- Variables
- func Check(root string, outs []Planned) ([]string, error)
- func Dispatch(verb string) string
- func DispatchNote(tool, verb string) string
- func Mkdirs(r *os.Root, dir string, made *[]string) error
- func Preflight(r *os.Root, rel string) error
- func Render(fs embed.FS, templatePath string, data any) ([]byte, error)
- func Write(root string, outs []Planned) (written []string, err error)
- func WriteWith(root string, outs []Planned, beforeCreate func(rel string)) (written []string, err error)
- type Planned
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.