parser

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2023 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const CurrentPackKey = "_self"
View Source
const VarEnvPrefix = "NOMAD_PACK_VAR_"

Variables

This section is empty.

Functions

func PackTemplateContextFuncs

func PackTemplateContextFuncs(isV1 bool) template.FuncMap

PackTemplateContextFuncs returns a text/template FuncMap that are necessary to access the variables and metadata information stored in the template context

func PackTemplateContextFuncsV1

func PackTemplateContextFuncsV1() template.FuncMap

PackTemplateContextFuncsV1 returns the a funcMap with error-only functions with the same names as v2 ones, so users are presented with more informative errors than the generic go-template ones.

func PackTemplateContextFuncsV2

func PackTemplateContextFuncsV2() template.FuncMap

PackTemplateContextFuncsV2 returns the funcMap for the V2 Pack template context. These are added to other template functions provided in the Renderer

Types

type PackContextable

type PackContextable interface {
	// contains filtered or unexported methods
}

type PackData

type PackData struct {
	Pack *pack.Pack
	// contains filtered or unexported fields
}

PackData is the currently selected Pack's metadata and variables, normally stored at `CurrentPackKey` in a PackTemplateContext.

type PackTemplateContext

type PackTemplateContext map[string]PackContextable

func (PackTemplateContext) Name

func (p PackTemplateContext) Name() string

type ParsedVariables

type ParsedVariables struct {
	Metadata *pack.Metadata
	// contains filtered or unexported fields
}

ParsedVariables wraps the parsed variables returned by parser.Parse and provides functionality to access them.

func (*ParsedVariables) AsOverrideFile

func (pv *ParsedVariables) AsOverrideFile() string

AsOverrideFile formats a ParsedVariables so it can be used as a var-file. This is used in the `generate varfile` command.

func (*ParsedVariables) ConvertVariablesToMapInterface

func (pv *ParsedVariables) ConvertVariablesToMapInterface() (map[string]any, hcl.Diagnostics)

ConvertVariablesToMapInterface creates the data object for V1 syntax templates.

func (*ParsedVariables) GetVars

func (pv *ParsedVariables) GetVars() map[pack.ID]map[variables.ID]*variables.Variable

GetVars returns the data in the v2 interim data format

func (*ParsedVariables) IsV1

func (pv *ParsedVariables) IsV1() bool

func (*ParsedVariables) IsV2

func (pv *ParsedVariables) IsV2() bool

func (*ParsedVariables) LoadV1Result

func (pv *ParsedVariables) LoadV1Result(in map[string]map[string]*variables.Variable) error

LoadV1Result populates this ParsedVariables with the result from parser_v1.Parse(). This function errors if the ParsedVariable has already been loaded.

func (*ParsedVariables) LoadV2Result

func (pv *ParsedVariables) LoadV2Result(in map[pack.ID]map[variables.ID]*variables.Variable) error

LoadV2Result populates this ParsedVariables with the result from parser_v2.Parse(). This function errors if the ParsedVariable has already been loaded.

func (*ParsedVariables) ToPackTemplateContext

func (pv *ParsedVariables) ToPackTemplateContext(p *pack.Pack) (PackTemplateContext, hcl.Diagnostics)

ToPackTemplateContext creates a PackTemplateContext from this ParsedVariables. Even though parsing the variable went without error, it is highly possible that conversion to native go types can incur an error. If an error is returned, it should be considered terminal.

type Parser

type Parser interface {
	Parse() (*ParsedVariables, hcl.Diagnostics)
}

func NewParser

func NewParser(cfg *config.ParserConfig) (Parser, error)

type ParserV1

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

ParserV1 can parse, merge, and validate HCL variables from multiple different sources.

func NewParserV1

func NewParserV1(cfg *config.ParserConfig) (*ParserV1, error)

func (*ParserV1) Parse

func (p *ParserV1) Parse() (*ParsedVariables, hcl.Diagnostics)

type ParserV2

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

func NewParserV2

func NewParserV2(cfg *config.ParserConfig) (*ParserV2, error)

func (*ParserV2) Parse

func (p *ParserV2) Parse() (*ParsedVariables, hcl.Diagnostics)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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