patch

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create added in v0.2.0

func Create(ctx context.Context, res resource.Resource, fields []resource.Field, patches []resource.Field, editor EditorFunc) ([]resource.Field, error)

Create applies patches to fields for creation using the provided editor function. It serializes fields to YAML, calls the editor, and updates patch.Set values based on changes.

func Edit added in v0.2.0

func Edit(ctx context.Context, res resource.Resource, fields []resource.Field, patches []resource.Field, editor EditorFunc) ([]resource.Field, error)

Edit applies patches to fields using the provided editor function. It serializes fields to YAML, calls the editor, and updates patch.Set values based on changes.

func FilterCreateFields added in v0.2.0

func FilterCreateFields(fields []resource.Field) []resource.Field

FilterCreateFields filters to fields that have a pending create patch.

func FilterDisplayableCreateFields added in v0.2.0

func FilterDisplayableCreateFields(fields []resource.Field) []resource.Field

FilterDisplayableCreateFields filters fields for visual creation display. Includes all fields that have a Create patch (even with zero values, so users can fill them in).

func FilterDisplayableEditFields added in v0.2.0

func FilterDisplayableEditFields(fields []resource.Field) []resource.Field

FilterDisplayableEditFields filters fields for visual editing display. Includes fields that have an Edit patch and a non-nil Value to show.

func FilterEditFields added in v0.2.0

func FilterEditFields(fields []resource.Field) []resource.Field

FilterEditFields filters to fields that have a pending edit patch.

func MergePatches added in v0.2.0

func MergePatches(dest, src []resource.Field) []resource.Field

MergePatches merges patch values from src into dest fields. For each field in dest, if src contains a patch at the same path, the src patch value overrides the dest patch value. Fields in src that don't exist in dest are appended.

func PatchedFields

func PatchedFields(fields []resource.Field, spec PatchSpec) ([]resource.Field, error)

PatchedFields applies the given PatchSpec to the provided fields, returning only the modified fields or an error if the patching process encounters issues.

func SaveYAML added in v0.2.0

func SaveYAML(res resource.Resource, fields []resource.Field, patches []resource.Field, w io.Writer, create bool) error

SaveYAML writes fields to a writer as YAML. If create is true, uses create patches; otherwise uses edit patches.

func ValidateRequired added in v0.2.0

func ValidateRequired(originalFields, patchedFields []resource.Field, create bool) error

ValidateRequired checks that all required fields have a value set in the patches. originalFields should contain the field definitions with Required flags, patchedFields should contain the patches with values.

Types

type EditorFunc added in v0.2.0

type EditorFunc func(ctx context.Context, input []byte) ([]byte, error)

EditorFunc is a callback that takes input YAML content and returns edited content. This allows for different editing implementations (file-based, in-memory, etc.)

func CommandEditorFunc added in v0.2.0

func CommandEditorFunc(stdio config.Stdio, command string) EditorFunc

CommandEditorFunc creates an EditorFunc that runs a shell command with YAML on stdin and reads the edited YAML from stdout.

func ContentEditorFunc added in v0.2.0

func ContentEditorFunc(content []byte) EditorFunc

ContentEditorFunc creates an EditorFunc that ignores input and returns the provided content. This is designed to work with kong's FileContentFlag or similar pre-read file content.

func VisualCommandEditorFunc added in v0.2.0

func VisualCommandEditorFunc(stdio config.Stdio) (EditorFunc, error)

VisualCommandEditorFunc creates an EditorFunc that uses a temp file and system editor.

type PatchSpec

type PatchSpec struct {
	Create bool

	Set map[string][]string
	Add map[string][]string
	Del map[string][]string
}

func (*PatchSpec) Keys

func (spec *PatchSpec) Keys() iter.Seq[string]

Jump to

Keyboard shortcuts

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