Help us shape the future of Go! Take the 2026 Go Developer Survey

yamledit

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package yamledit edits YAML model files line by line: each edit parses the document with yaml.v3, finds the node through the node tree and rewrites only the lines of that node, so comments, key order, quoting and indentation of every other line are kept. Callers apply one edit at a time and re-parse.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendSequenceItems

func AppendSequenceItems(data []byte, find func(root *yaml.Node) (*yaml.Node, error), key string, items []string) ([]byte, error)

AppendSequenceItems appends the block lines items (each item already formatted as "- ..." with continuation lines indented by two spaces, relative to column 0) to the sequence under key of the mapping found by find, at the indentation of its existing items. An empty or flow sequence is replaced by a block sequence. TRLC-LINKS: REQ-EMG-104

func FindListItem

func FindListItem(keys []string, idKey, id string, sub ...string) func(*yaml.Node) (*yaml.Node, error)

FindListItem returns a function that finds the mapping item with id in the sequence at keys, then walks sub keys inside it. TRLC-LINKS: REQ-EMG-100, REQ-EMG-101, REQ-EMG-104

func FindPath

func FindPath(keys ...string) func(*yaml.Node) (*yaml.Node, error)

FindPath returns a function that walks mapping keys from the root. TRLC-LINKS: REQ-EMG-100, REQ-EMG-101, REQ-EMG-104

func KeyRange

func KeyRange(lines []string, key, value *yaml.Node) (int, int)

KeyRange returns the 0-based line range [start, end) a mapping key and its value occupy: the key line and every following line that is blank, indented deeper than the key, or (for a sequence value written without indentation) a "-" item at the key's indentation. Trailing blank and comment lines are not part of the range. TRLC-LINKS: REQ-EMG-101, REQ-EMG-104

func MappingEntry

func MappingEntry(node *yaml.Node, key string) (*yaml.Node, *yaml.Node)

MappingEntry returns the key and value nodes for key in a mapping node. TRLC-LINKS: REQ-EMG-068, REQ-EMG-100, REQ-EMG-101, REQ-EMG-104

func MappingValue

func MappingValue(node *yaml.Node, key string) *yaml.Node

MappingValue returns the value node for key in a mapping node. TRLC-LINKS: REQ-EMG-068, REQ-EMG-100, REQ-EMG-101, REQ-EMG-104

func Parse

func Parse(data []byte) (*yaml.Node, error)

Parse returns the root mapping node of a YAML document. TRLC-LINKS: REQ-EMG-100, REQ-EMG-101, REQ-EMG-104

func RemoveKey

func RemoveKey(data []byte, find func(root *yaml.Node) (*yaml.Node, error), key string) ([]byte, bool, error)

RemoveKey removes key and its value lines from the block mapping found by find; a missing key is no change. TRLC-LINKS: REQ-EMG-104

func RemoveSequenceItems

func RemoveSequenceItems(data []byte, find func(root *yaml.Node) (*yaml.Node, error), key string, indexes []int) ([]byte, error)

RemoveSequenceItems removes the items at indexes (0-based, any order) of the block sequence under key of the mapping found by find, each with its lines up to the next item; the other items keep their lines. TRLC-LINKS: REQ-EMG-104

func Scalar

func Scalar(s string) string

Scalar encodes s as a single-line YAML scalar (plain when safe, quoted otherwise); runs of whitespace are collapsed. TRLC-LINKS: REQ-EMG-101, REQ-EMG-104

func ScalarEnd

func ScalarEnd(line string, col int, value *yaml.Node) (int, bool)

ScalarEnd returns the column just after a single-line scalar that starts at col of line. TRLC-LINKS: REQ-EMG-100, REQ-EMG-101

func SetKey

func SetKey(data []byte, find func(root *yaml.Node) (*yaml.Node, error), key, raw string) ([]byte, error)

SetKey sets key of the block mapping found by find to the encoded YAML value raw (a single-line scalar or flow collection, or a block starting with a newline). An existing single-line scalar is replaced in place, keeping a trailing comment; any other existing value is replaced with its lines; a missing key is added after the mapping's last key. TRLC-LINKS: REQ-EMG-100, REQ-EMG-101, REQ-EMG-104

func SetScalarInPlace

func SetScalarInPlace(data []byte, find func(root *yaml.Node) (*yaml.Node, error), key, value string) ([]byte, error)

SetScalarInPlace replaces the single-line scalar value of key in the mapping found by find with value, keeping its quote style (plain, single or double) and every other byte of data, in block and flow mappings. It refuses a missing key, a value that is no scalar or not on its key's line (a block or multi-line scalar), and a value that its quote style cannot hold unescaped. TRLC-LINKS: REQ-EMG-068

func SpliceLines

func SpliceLines(lines []string, start, end int, replacement ...string) []byte

SpliceLines replaces lines [start, end) with replacement lines. TRLC-LINKS: REQ-EMG-101, REQ-EMG-104

func SplitLines

func SplitLines(data []byte) []string

SplitLines splits data into lines that keep their newline. TRLC-LINKS: REQ-EMG-101, REQ-EMG-104

Types

This section is empty.

Jump to

Keyboard shortcuts

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