yaml_editor

package
v0.1.28 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2025 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMapNode

func CreateMapNode(pairs ...interface{}) (*yaml.Node, error)

CreateMapNode creates a new mapping node with the given key-value pairs

func CreateScalarNode

func CreateScalarNode(value string) *yaml.Node

CreateScalarNode creates a new scalar node with the given value

func CreateSequenceNode

func CreateSequenceNode(items ...*yaml.Node) *yaml.Node

CreateSequenceNode creates a new sequence node with the given items

func DeepCopyNode

func DeepCopyNode(node *yaml.Node) *yaml.Node

DeepCopyNode creates a deep copy of a node

func GetNodeAtPath

func GetNodeAtPath(root *yaml.Node, path ...string) (*yaml.Node, error)

GetNodeAtPath returns the node at the given path

func GetValueByPath

func GetValueByPath(root *yaml.Node, path ...string) (interface{}, error)

GetValueByPath gets a value from a YAML node by path, with type conversion

func SetComment

func SetComment(node *yaml.Node, comment string, position CommentPosition)

SetComment sets a comment on a node

Types

type CommentPosition

type CommentPosition int

CommentPosition specifies where to place a comment relative to a node

const (
	CommentHead CommentPosition = iota // Comment before the node
	CommentLine                        // Comment at the end of the node's line
	CommentFoot                        // Comment after the node
)

type YAMLEditor

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

YAMLEditor provides utilities for manipulating YAML files while preserving comments and structure

func NewYAMLEditor

func NewYAMLEditor(data []byte) (*YAMLEditor, error)

NewYAMLEditor creates a new YAMLEditor from raw YAML data

func NewYAMLEditorFromFile

func NewYAMLEditorFromFile(filename string) (*YAMLEditor, error)

NewYAMLEditorFromFile creates a new YAMLEditor from a file

func (*YAMLEditor) AppendToSequence

func (e *YAMLEditor) AppendToSequence(node *yaml.Node, path ...string) error

AppendToSequence appends a node to a sequence at the given path

func (*YAMLEditor) CreateMap

func (e *YAMLEditor) CreateMap(pairs ...interface{}) (*yaml.Node, error)

CreateMap creates a new mapping node with the given key-value pairs

func (*YAMLEditor) CreateScalar

func (e *YAMLEditor) CreateScalar(value string) *yaml.Node

CreateScalar creates a new scalar node with the given value

func (*YAMLEditor) CreateSequence

func (e *YAMLEditor) CreateSequence(items ...*yaml.Node) *yaml.Node

CreateSequence creates a new sequence node with the given items

func (*YAMLEditor) CreateValueNode added in v0.1.24

func (e *YAMLEditor) CreateValueNode(value interface{}) (*yaml.Node, error)

CreateValueNode creates a new node from a value of any supported type

func (*YAMLEditor) DeepCopyNode

func (e *YAMLEditor) DeepCopyNode(node *yaml.Node) *yaml.Node

DeepCopyNode creates a deep copy of a node

func (*YAMLEditor) GetMapNode

func (e *YAMLEditor) GetMapNode(key string, mapNode *yaml.Node) (*yaml.Node, error)

GetMapNode returns the value node for a key in a mapping node

func (*YAMLEditor) GetNode

func (e *YAMLEditor) GetNode(path ...string) (*yaml.Node, error)

GetNode returns the node at the given path

func (*YAMLEditor) RemoveFromSequence

func (e *YAMLEditor) RemoveFromSequence(index int, path ...string) error

RemoveFromSequence removes a node from a sequence at the given path and index

func (*YAMLEditor) Save

func (e *YAMLEditor) Save(filename string) error

Save writes the YAML content to a file

func (*YAMLEditor) SetNode

func (e *YAMLEditor) SetNode(node *yaml.Node, path ...string) error

SetNode sets the node at the given path

Jump to

Keyboard shortcuts

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