Documentation
¶
Index ¶
- func AmbiguousPacks(cwd, filename string) []string
- func BulkAddRemoveTag(spec *schema.ObjectSpec) (action string, field string, value string, err error)
- func BulkApplyTag(items []MergedItem, selected map[int]bool, field, value, action string)
- func BulkSetField(spec *schema.ObjectSpec) (string, any, error)
- func ColumnsForSchema(spec *schema.ObjectSpec) []string
- func IsUserAborted(err error) bool
- func LoadSingleObject(filePath string) (map[string]any, error)
- func Run(target *ResolvedFile, schemasDir string) error
- func RunCreateWizard(cwd, schemasDir string) error
- func SaveItems(filePath string, items []MergedItem, targetLayer Layer) error
- func SaveObject(filePath string, obj map[string]any) error
- func ValidateFile(filePath, schemasDir string) ([]schema.ValidationError, error)
- type Bindings
- type BoolBinding
- type Change
- type ChangeKind
- type FieldDiff
- type History
- func (h *History) Baseline() []MergedItem
- func (h *History) CanRedo() bool
- func (h *History) CanUndo() bool
- func (h *History) Changes(current []MergedItem) []Change
- func (h *History) DiscardLast() ([]MergedItem, bool)
- func (h *History) HasChanges(current []MergedItem) bool
- func (h *History) Push(items []MergedItem, desc string)
- func (h *History) Redo(current []MergedItem) ([]MergedItem, string, bool)
- func (h *History) Undo(current []MergedItem) ([]MergedItem, string, bool)
- func (h *History) UndoDepth() int
- type Layer
- type LayerInfo
- type MergedItem
- type ResolvedFile
- type SliceBinding
- type Snapshot
- type StringBinding
- type WizardState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AmbiguousPacks ¶
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 ¶
IsUserAborted reports whether the error is a user abort from huh.
func LoadSingleObject ¶
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 ¶
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 ¶
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.
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 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) 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.
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.