emrichen

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2025 License: MIT Imports: 24 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenericMapToNode

func GenericMapToNode(mapValue reflect.Value) (*yaml.Node, error)

func GenericSliceToNode

func GenericSliceToNode(slice reflect.Value) (*yaml.Node, error)

func NodeToBool

func NodeToBool(node *yaml.Node) (bool, bool)

NodeToBool parses a YAML node to bool.

func NodeToFloat

func NodeToFloat(node *yaml.Node) (float64, bool)

NodeToFloat parses a YAML node to float.

func NodeToInt

func NodeToInt(node *yaml.Node) (int, bool)

NodeToInt parses a YAML node to int.

func NodeToInterface

func NodeToInterface(node *yaml.Node) (interface{}, bool)

NodeToInterface parses a YAML node into an interface{}.

func NodeToMap

func NodeToMap(node *yaml.Node) (map[string]interface{}, bool)

func NodeToScalarInterface

func NodeToScalarInterface(node *yaml.Node) (interface{}, bool)

func NodeToSlice

func NodeToSlice(node *yaml.Node) ([]interface{}, bool)

func NodeToString

func NodeToString(node *yaml.Node) (string, bool)

NodeToString parses a YAML node to string.

func ValueToNode

func ValueToNode(value interface{}) (*yaml.Node, error)

Types

type Interpreter

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

func NewInterpreter

func NewInterpreter(options ...InterpreterOption) (*Interpreter, error)

func (*Interpreter) CreateDecoder

func (ei *Interpreter) CreateDecoder(target interface{}) *interpretHelper

func (*Interpreter) CreateRawDecoder

func (ei *Interpreter) CreateRawDecoder(target *yaml.Node) *rawInterpretHelper

func (*Interpreter) LookupAll

func (ei *Interpreter) LookupAll(jsonPath string) (*yaml.Node, error)

func (*Interpreter) LookupFirst

func (ei *Interpreter) LookupFirst(jsonPath string) (*yaml.Node, error)

func (*Interpreter) ParseArgs added in v0.0.4

func (ei *Interpreter) ParseArgs(
	node *yaml.Node,
	variables []ParsedVariable,
) (map[string]*yaml.Node, error)

ParseArgs processes a YAML mapping node according to a list of variable specifications. It's a core utility function used by various Emrichen tags to parse their arguments in a consistent way.

Parameters: - node: A pointer to a yaml.Node that must be a mapping node containing key-value pairs - variables: A slice of parsedVariable structs that specify:

  • Name: The expected argument name
  • Required: Whether the argument must be present
  • Expand: Whether to process the value through the Emrichen interpreter

Returns: - map[string]*yaml.Node: A map of processed arguments where:

  • Keys are the argument names
  • Values are the processed YAML nodes (expanded if specified)

- error: Returns an error if:

  • The input node is not a mapping node
  • An unknown argument key is encountered
  • A required argument is missing
  • A key is not a scalar value
  • Value expansion fails

Example usage:

args, err := ei.ParseArgs(node, []parsedVariable{
  {Name: "test", Required: true, Expand: true},
  {Name: "then", Required: true, Expand: false},
  {Name: "else", Required: false, Expand: false},
})

func (*Interpreter) Process

func (ei *Interpreter) Process(node *yaml.Node) (*yaml.Node, error)

func (*Interpreter) RegisterTag

func (ei *Interpreter) RegisterTag(tag string, f func(node *yaml.Node) (*yaml.Node, error)) error

type InterpreterOption

type InterpreterOption func(*Interpreter) error

func WithAdditionalTags

func WithAdditionalTags(tags TagFuncMap) InterpreterOption

func WithFuncMap

func WithFuncMap(funcmap ...template.FuncMap) InterpreterOption

func WithVars

func WithVars(vars map[string]interface{}) InterpreterOption

type ParsedVariable added in v0.0.4

type ParsedVariable struct {
	Name     string
	Expand   bool
	Required bool
}

type TagFunc added in v0.0.4

type TagFunc func(ei *Interpreter, node *yaml.Node) (*yaml.Node, error)

type TagFuncMap added in v0.0.4

type TagFuncMap map[string]TagFunc

Jump to

Keyboard shortcuts

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