genfile

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package genfile implements generate_file code generation.

Index

Constants

View Source
const (
	// ErrInvalidContentType indicates the content attribute
	// has an invalid type.
	ErrInvalidContentType errors.Kind = "invalid content type"

	// ErrInvalidConditionType indicates the condition attribute
	// has an invalid type.
	ErrInvalidConditionType errors.Kind = "invalid condition type"

	// ErrContentEval indicates an error when evaluating the content attribute.
	ErrContentEval errors.Kind = "evaluating content"

	// ErrConditionEval indicates an error when evaluating the condition attribute.
	ErrConditionEval errors.Kind = "evaluating condition"

	// ErrLabelConflict indicates the two generate_file blocks
	// have the same label.
	ErrLabelConflict errors.Kind = "label conflict detected"
)
View Source
const (
	// StackContext is the stack context name.
	StackContext = "stack"

	// RootContext is the root context name.
	RootContext = "root"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type File

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

File represents generated file from a single generate_file block.

func Eval

func Eval(block hcl.GenFileBlock, evalctx *eval.Context) (File, error)

Eval the generate_file block.

func Load

func Load(
	root *config.Root,
	st *config.Stack,
	globals *eval.Object,
	vendorDir project.Path,
	vendorRequests chan<- event.VendorRequest,
) ([]File, error)

Load loads and parses from the file system all generate_file blocks for a given stack. It will navigate the file system from the stack dir until it reaches rootdir, loading generate_file blocks found on Terramate configuration files.

All generate_file blocks must have unique labels, even ones at different directories. Any conflicts will be reported as an error.

Metadata and globals for the stack are used on the evaluation of the generate_file blocks.

The rootdir MUST be an absolute path.

func (File) Asserts

func (f File) Asserts() []config.Assert

Asserts returns all (if any) of the evaluated assert configs of the generate_file block. If File.Condition returns false then assert configs will always be empty since they are not evaluated at all in that case.

func (File) Body

func (f File) Body() string

Body returns the file body.

func (File) Condition

func (f File) Condition() bool

Condition returns the result of the evaluation of the condition attribute for the generated code.

func (File) Context

func (f File) Context() string

Context of the generate_file block.

func (File) Header

func (f File) Header() string

Header returns the header of this file.

func (File) Label

func (f File) Label() string

Label of the original generate_file block.

func (File) Range

func (f File) Range() info.Range

Range returns the range information of the generate_file block.

func (File) String

func (f File) String() string

Jump to

Keyboard shortcuts

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