Documentation
¶
Index ¶
- func Create(ctx context.Context, res resource.Resource, fields []resource.Field, ...) ([]resource.Field, error)
- func Edit(ctx context.Context, res resource.Resource, fields []resource.Field, ...) ([]resource.Field, error)
- func FilterCreateFields(fields []resource.Field) []resource.Field
- func FilterDisplayableCreateFields(fields []resource.Field) []resource.Field
- func FilterDisplayableEditFields(fields []resource.Field) []resource.Field
- func FilterEditFields(fields []resource.Field) []resource.Field
- func MergePatches(dest, src []resource.Field) []resource.Field
- func PatchedFields(fields []resource.Field, spec PatchSpec) ([]resource.Field, error)
- func SaveYAML(res resource.Resource, fields []resource.Field, patches []resource.Field, ...) error
- func ValidateRequired(originalFields, patchedFields []resource.Field, create bool) error
- type EditorFunc
- type PatchSpec
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
FilterCreateFields filters to fields that have a pending create patch.
func FilterDisplayableCreateFields ¶ added in v0.2.0
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
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
FilterEditFields filters to fields that have a pending edit patch.
func MergePatches ¶ added in v0.2.0
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 ¶
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
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
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.