Documentation
¶
Overview ¶
Package yamledit finds a kind/name YAML document in a policy repo (any document of a multi-document file) and edits it by byte splice, leaving comments, formatting and every other document intact.
Index ¶
- func Parse(data []byte, kind policy.Kind, name string) (*yaml.Node, error)
- func Quote(v string, style yaml.Style) string
- func Scalar(m *yaml.Node, key string) (k, v *yaml.Node)
- type Doc
- func (d *Doc) AppendSeq(path []string, item any) ([]byte, error)
- func (d *Doc) Get(path ...string) *yaml.Node
- func (d *Doc) Save(data []byte) error
- func (d *Doc) SetField(key, val string) ([]byte, error)
- func (d *Doc) SetPath(path []string, raw string) ([]byte, error)
- func (d *Doc) SetRaw(v *yaml.Node, raw string) ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
Parse returns the document declaring kind/name in data (which may hold several documents), or nil when none does.
Types ¶
type Doc ¶
type Doc struct {
Path string // path as walked (dir joined with the file)
Rel string // slash-separated path relative to dir
Data []byte
Mapping *yaml.Node
}
Doc is one YAML document of a given kind/name found in a policy repo. Data is the whole file; node positions (Line/Column) are file-absolute.
func (*Doc) AppendSeq ¶
AppendSeq appends item to the sequence at path (mapping keys from the document root), creating missing keys, by splicing lines: everything outside the edited sequence keeps its bytes. A block sequence gets a new "- item" after its last item; a flow sequence ([a, b]) is rewritten as a block sequence.
func (*Doc) SetField ¶
SetField sets a top-level scalar key by splicing bytes at the value's source span, so comments, blank lines, formatting and other documents are untouched. val is the raw string; it is quoted as needed (an existing quote style is kept).
func (*Doc) SetPath ¶
SetPath sets the inline scalar at path to raw, spliced in verbatim like SetRaw (raw must already be valid YAML: quote strings with Quote). Path elements are mapping keys, or "name=<v>" to pick the sequence item whose name is v. Only a missing top-level key is inserted (after name); deeper keys must exist.