scaffold

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 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 (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

Constants

This section is empty.

Variables

View Source
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

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 (rowan hold 6 on #3616, item 4).

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 Rule

func Rule(root, name string) ([]string, error)

Rule writes a new class rule skeleton into root.

func Verb

func Verb(root, tool, verb string) ([]string, error)

Verb writes a new CLI verb skeleton into root.

func Write

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

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

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.

Jump to

Keyboard shortcuts

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