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
- Variables
- func ConvertToYAMLPreservingDelimiters(data any, delimiters []string, opts ...u.YAMLOptions) (string, error)
- func DelimiterConflictsWithYAMLQuoting(delimiters []string) bool
- func EnsureDoubleQuotedForDelimiterSafety(node *goyaml.Node)
- func HasPosition(positions PositionMap, path string) bool
- type LongString
- type Options
- type Position
- type PositionMap
Constants ¶
const DefaultIndent = 2
DefaultIndent is the default indentation for YAML output.
Variables ¶
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 ConvertToYAMLPreservingDelimiters ¶
func ConvertToYAMLPreservingDelimiters(data any, delimiters []string, opts ...u.YAMLOptions) (string, error)
ConvertToYAMLPreservingDelimiters converts data to YAML while ensuring that custom template delimiter characters are preserved literally in the output. When custom delimiters contain single-quote characters, the default yaml.v3 encoder may use single-quoted style for certain values (like those starting with '!'), which escapes internal single quotes by doubling them. This breaks template processing because the delimiter pattern is altered. This function forces double-quoted YAML style for affected scalar values to preserve delimiters.
func DelimiterConflictsWithYAMLQuoting ¶
DelimiterConflictsWithYAMLQuoting checks if any custom delimiter contains a single-quote character that would conflict with YAML's single-quoted string escaping.
func EnsureDoubleQuotedForDelimiterSafety ¶
EnsureDoubleQuotedForDelimiterSafety recursively walks a yaml.Node tree and forces double-quoted style for scalar nodes whose values contain single-quote characters. This prevents YAML's single-quote escaping (two consecutive single quotes) from interfering with template delimiters that contain single quotes.
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 Position ¶
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 ¶
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).