Documentation
¶
Overview ¶
Package genplan describes what a generator would write before it writes anything: a plan of file changes that the CLI prints as a dry run, that the Dev Portal shows as a diff to approve, and that Apply writes (ADR-0021, ADR-0066).
A plan is made from the app as it is now. Applying it checks that every file it changes is still as the plan saw it, so a plan made against a stale working tree is refused instead of overwriting edits made since.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrExists reports a Create whose file already exists. ErrExists = errors.New("file already exists") // ErrStale reports a Modify whose file changed since the plan was made. ErrStale = errors.New("file changed since the plan was made") )
Errors of Apply.
Functions ¶
func Apply ¶
Apply writes the plan's changes into dir, after Check. Files are written through os.Root, so no path escapes the app (ADR-0029, threat 3).
func Check ¶
Check reports whether the plan can be applied to dir as it is now: files to create don't exist, and files to modify are as the plan saw them. Apply runs it first; the portal runs it to warn early.
Types ¶
type Change ¶
type Change struct {
Path string `json:"path"`
Kind Kind `json:"kind"`
// Content is the file after the change.
Content []byte `json:"-"`
// Before is the file before a Modify; nil for a Create.
Before []byte `json:"-"`
}
Change is one file a plan writes. Paths are slash-separated and relative to the app directory.
func (Change) MarshalJSON ¶
MarshalJSON encodes the content as strings, so a UI can show the diff.
func (*Change) UnmarshalJSON ¶
UnmarshalJSON is the inverse of MarshalJSON.
type Plan ¶
type Plan struct {
// Generator is the generator that made the plan: job, resource or
// migration.
Generator string `json:"generator"`
// Name is what was generated, as the developer named it.
Name string `json:"name"`
// Summary is the CLI's confirmation text: what the plan creates.
Summary string `json:"summary"`
// Changes are the files, in the order they are written.
Changes []Change `json:"changes"`
// Next are the steps to take after applying, one per line.
Next []string `json:"next"`
// Result is the generator's --json result, without the schema version.
Result any `json:"result,omitempty"`
}
Plan is everything a generator would write, with what to tell the developer about it.