yaml

package
v1.203.0-test.13 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package yaml provides YAML parsing, caching, and utility functions for Atmos.

This package contains YAML-specific functionality including:

  • Parsing and unmarshaling YAML with custom tag processing
  • Content-aware caching for parsed YAML documents
  • Position tracking for provenance
  • Output formatting and highlighting

The custom tag processing uses the function registry from pkg/function to handle tags like !env, !exec, !terraform.output, etc.

Example usage:

data, err := yaml.UnmarshalYAML[map[string]any](content)
if err != nil {
    return err
}

Index

Constants

View Source
const DefaultIndent = 2

DefaultIndent is the default indentation for YAML output.

Variables

View Source
var (
	// ErrNilAtmosConfig is returned when atmosConfig is nil.
	ErrNilAtmosConfig = errors.New("atmosConfig cannot be nil")

	// ErrIncludeInvalidArguments is returned when !include has invalid arguments.
	ErrIncludeInvalidArguments = errors.New("invalid number of arguments in the !include function")

	// ErrIncludeFileNotFound is returned when !include references a non-existent file.
	ErrIncludeFileNotFound = errors.New("the !include function references a file that does not exist")

	// ErrIncludeAbsPath is returned when converting to absolute path fails.
	ErrIncludeAbsPath = errors.New("failed to convert the file path to an absolute path in the !include function")

	// ErrIncludeProcessFailed is returned when processing stack manifest fails.
	ErrIncludeProcessFailed = errors.New("failed to process the stack manifest with the !include function")

	// ErrInvalidYAMLFunction is returned when a YAML function has invalid syntax.
	ErrInvalidYAMLFunction = errors.New("invalid Atmos YAML function")
)

Functions

func HasPosition

func HasPosition(positions PositionMap, path string) bool

HasPosition checks if a position exists for a specific JSONPath.

Types

type LongString

type LongString string

LongString is a string type that encodes as a YAML folded scalar (>). This is used to wrap long strings across multiple lines for better readability.

func (LongString) MarshalYAML

func (s LongString) MarshalYAML() (interface{}, error)

MarshalYAML implements yaml.Marshaler to encode as a folded scalar.

type Options

type Options struct {
	Indent int
}

Options configures YAML encoding behavior.

type Position

type Position struct {
	Line   int // 1-indexed line number.
	Column int // 1-indexed column number.
}

Position represents a line and column position in a YAML file.

func GetPosition

func GetPosition(positions PositionMap, path string) Position

GetPosition gets the position for a specific JSONPath from the position map. Returns Position{0, 0} if not found.

type PositionMap

type PositionMap map[string]Position

PositionMap maps JSONPath-style paths to their positions in a YAML file.

func ExtractPositions

func ExtractPositions(node *goyaml.Node, enabled bool) PositionMap

ExtractPositions extracts line/column positions from a YAML node tree. Returns a map of JSONPath -> Position for all values in the YAML. If enabled is false, returns an empty map immediately (zero overhead).

Jump to

Keyboard shortcuts

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