editor

package
v0.0.8 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AmbiguousPacks

func AmbiguousPacks(cwd, filename string) []string

AmbiguousPacks returns all pack IDs that contain a given filename in the detected layer. Useful for prompting the user to disambiguate.

func BulkAddRemoveTag

func BulkAddRemoveTag(spec *schema.ObjectSpec) (action string, field string, value string, err error)

BulkAddRemoveTag opens a form to add or remove a tag value on an array field.

func BulkApplyTag

func BulkApplyTag(items []MergedItem, selected map[int]bool, field, value, action string)

BulkApplyTag adds or removes a tag value from an array field on the selected items.

func BulkSetField

func BulkSetField(spec *schema.ObjectSpec) (string, any, error)

BulkSetField opens a form to pick a field and value for bulk assignment. Returns the field key and new value. Returns an error if the user aborts.

func ColumnsForSchema

func ColumnsForSchema(spec *schema.ObjectSpec) []string

ColumnsForSchema picks the first 4 string-typed fields from the spec, excluding verbose fields (description, pattern, cause, fix) that would clutter a narrow list view.

func IsUserAborted

func IsUserAborted(err error) bool

IsUserAborted reports whether the error is a user abort from huh.

func LoadSingleObject

func LoadSingleObject(filePath string) (map[string]any, error)

LoadSingleObject loads a single-object YAML file (e.g. pack.yaml). Returns an empty map if the file does not exist.

func Run

func Run(target *ResolvedFile, schemasDir string) error

Run opens the editor for the given resolved file. It loads the matching schema and dispatches to either an object editor (pack.yaml) or an array editor (resources.yaml, etc.).

func RunCreateWizard

func RunCreateWizard(cwd, schemasDir string) error

RunCreateWizard runs the full content pack creation wizard.

func SaveItems

func SaveItems(filePath string, items []MergedItem, targetLayer Layer) error

SaveItems marshals items to YAML and writes to filePath. Only items belonging to targetLayer are included in the output file.

func SaveObject

func SaveObject(filePath string, obj map[string]any) error

SaveObject marshals a single object to YAML and writes to filePath.

func ValidateFile

func ValidateFile(filePath, schemasDir string) ([]schema.ValidationError, error)

ValidateFile validates a single YAML file against its schema and returns all validation errors. Useful for batch validation from CLI commands.

Types

type Bindings

type Bindings struct {
	Strings map[string]*StringBinding
	Bools   map[string]*BoolBinding
	Slices  map[string]*SliceBinding
	Objects map[string]map[string]any // nested objects (passthrough)
	Maps    map[string]map[string]any // map fields (passthrough)
}

Bindings maps field keys to their typed binding structs.

func BuildForm

func BuildForm(spec *schema.ObjectSpec, values map[string]any) (*huh.Form, *Bindings)

BuildForm creates a huh form from a schema ObjectSpec and current values. Conditional fields whose condition is not met are skipped.

func NewBindings

func NewBindings() *Bindings

NewBindings creates an empty Bindings container.

func (*Bindings) ToMap

func (b *Bindings) ToMap(spec *schema.ObjectSpec) map[string]any

ToMap collects all binding values into a flat map[string]any suitable for YAML marshaling. It resolves _raw fields back to arrays and converts integer strings back to int.

type BoolBinding

type BoolBinding struct{ Value bool }

BoolBinding holds a bool value for huh form binding.

type Change

type Change struct {
	Kind   ChangeKind
	ItemID string
	Fields []FieldDiff
}

Change describes one item-level difference.

type ChangeKind

type ChangeKind int

ChangeKind categorises a difference between baseline and current.

const (
	ChangeAdded ChangeKind = iota
	ChangeEdited
	ChangeDeleted
)

type FieldDiff

type FieldDiff struct {
	Key      string
	OldValue string
	NewValue string
}

FieldDiff describes a single field that changed between baseline and current.

type History

type History struct {
	// contains filtered or unexported fields
}

History tracks undo/redo snapshots for the content editor. Push a snapshot before each mutation; Undo/Redo restore previous states.

func NewHistory

func NewHistory(items []MergedItem) *History

NewHistory creates a new History seeded with the initial item state.

func (*History) Baseline

func (h *History) Baseline() []MergedItem

Baseline returns a deep copy of the initial item state passed to NewHistory.

func (*History) CanRedo

func (h *History) CanRedo() bool

CanRedo reports whether there are states available to redo.

func (*History) CanUndo

func (h *History) CanUndo() bool

CanUndo reports whether there are states available to undo.

func (*History) Changes

func (h *History) Changes(current []MergedItem) []Change

Changes compares the baseline against current and returns all differences.

func (*History) DiscardLast

func (h *History) DiscardLast() ([]MergedItem, bool)

DiscardLast pops the most recent undo entry without touching the redo stack. Use this to roll back a Push that preceded a cancelled operation.

func (*History) HasChanges

func (h *History) HasChanges(current []MergedItem) bool

HasChanges reports whether the current items differ from the baseline.

func (*History) Push

func (h *History) Push(items []MergedItem, desc string)

Push records the current item state onto the undo stack and clears the redo stack (a new edit invalidates any previously undone future).

func (*History) Redo

func (h *History) Redo(current []MergedItem) ([]MergedItem, string, bool)

Redo pops the most recent snapshot from the redo stack and returns it. current is pushed onto the undo stack. Returns (nil, "", false) if nothing to redo.

func (*History) Undo

func (h *History) Undo(current []MergedItem) ([]MergedItem, string, bool)

Undo pops the most recent snapshot from the undo stack and returns it. current is the caller's present state; it is pushed onto the redo stack so the change can be re-applied. Returns (nil, "", false) if nothing to undo.

func (*History) UndoDepth

func (h *History) UndoDepth() int

UndoDepth returns the number of undoable steps currently on the stack.

type Layer

type Layer int

Layer describes which content layer is being edited.

const (
	LayerOfficial Layer = iota
	LayerCompany
	LayerUser
	LayerProject
)

func (Layer) String

func (l Layer) String() string

String returns a human-readable label for the layer.

type LayerInfo

type LayerInfo struct {
	Layer Layer
	Dir   string
}

LayerInfo pairs a Layer with its packs directory on disk.

func AllLayers

func AllLayers(cwd string) []LayerInfo

AllLayers returns the directories for each content layer that exists on disk.

type MergedItem

type MergedItem struct {
	Data       map[string]any
	Layer      Layer
	IsOverride bool // true when this item overrides an item from an earlier layer
}

MergedItem wraps a content item with its source layer information.

func BulkDeleteItems

func BulkDeleteItems(items []MergedItem, selected map[int]bool) []MergedItem

BulkDeleteItems removes items at the selected indices and returns a new slice.

func LoadMergedItems

func LoadMergedItems(cwd, packID, filename string) ([]MergedItem, error)

LoadMergedItems loads items from all layers for a given pack and file, merging by "id" or "name" key. Later layers override earlier ones.

func MoveItems

func MoveItems(items []MergedItem, selected map[int]bool, moveUp bool) []MergedItem

MoveItems moves all selected items one position in the given direction. moveUp=true shifts selected items toward index 0; moveUp=false shifts toward the end. Contiguous selected items move as a block. Returns a new slice.

type ResolvedFile

type ResolvedFile struct {
	Layer      Layer
	PackID     string
	Filename   string
	SchemaName string
	FilePath   string // actual file path to edit
	PackDir    string // directory containing the pack
}

ResolvedFile contains the resolved editing target.

func ResolveEditTarget

func ResolveEditTarget(cwd, arg string) (*ResolvedFile, error)

ResolveEditTarget determines the file path and layer for a content edit request. arg can be a direct path (starts with ./, .sap-devs/, or content/), a pack/file pair (e.g. "cap/resources.yaml"), or a bare filename (e.g. "resources.yaml").

type SliceBinding

type SliceBinding struct{ Value []string }

SliceBinding holds a string slice value for huh form binding.

type Snapshot

type Snapshot struct {
	Items []MergedItem
	Desc  string
}

Snapshot holds a deep copy of the item list at a point in time, along with a human-readable description of the change that produced it.

type StringBinding

type StringBinding struct{ Value string }

StringBinding holds a string value for huh form binding.

type WizardState

type WizardState struct {
	Layer    Layer
	PackDir  string
	Metadata map[string]any
	// SelectedFiles lists content filenames chosen by the user (e.g. "resources.yaml", "tips.md").
	SelectedFiles []string
	// Entries maps a YAML filename to the single initial entry data collected via BuildForm.
	Entries map[string]map[string]any
}

WizardState holds all answers collected during the creation wizard.

func (*WizardState) Summary

func (s *WizardState) Summary() string

Summary returns a human-readable description of what will be created.

func (*WizardState) WriteFiles

func (s *WizardState) WriteFiles() error

WriteFiles creates the pack directory and writes all files.

Jump to

Keyboard shortcuts

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