genplan

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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

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

func Apply(dir string, p Plan) error

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

func Check(dir string, p Plan) error

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.

func Describe

func Describe(p Plan) string

Describe returns the plan's changes as the CLI lists them: one path per line, prefixed with what happens to it.

func Diff added in v0.2.0

func Diff(p Plan) string

Diff returns the plan's changes as a unified diff, the way orb gen --diff prints them: a created file is all additions, a modified file shows its changed lines with three lines of context.

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

func (c Change) MarshalJSON() ([]byte, error)

MarshalJSON encodes the content as strings, so a UI can show the diff.

func (*Change) UnmarshalJSON

func (c *Change) UnmarshalJSON(data []byte) error

UnmarshalJSON is the inverse of MarshalJSON.

type Kind

type Kind string

Kind is what a change does to its file.

const (
	// Create writes a file that must not exist yet.
	Create Kind = "create"
	// Modify replaces a file's content; Before holds what it replaces.
	Modify Kind = "modify"
)

Kinds of change.

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.

func (Plan) Paths

func (p Plan) Paths() []string

Paths lists the files the plan writes, in order.

Jump to

Keyboard shortcuts

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