Documentation
¶
Overview ¶
Package scaffold provides the shared write-confinement and template engine for scaffolding verbs across this repository (nova-tools#2498 S5).
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 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 Rule(root, name string) ([]string, error)
- func Verb(root, tool, verb string) ([]string, error)
- func Write(root string, outs []Planned) (written []string, err error)
- type Planned
Constants ¶
This section is empty.
Variables ¶
var BeforeCreate func(rel string)
BeforeCreate runs between the preflight and each file's creation. It is nil outside tests, which use it to race a file in where one is about to land.
Functions ¶
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 (rowan hold 6 on #3616, item 4).
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).