variables

package
v0.0.0-...-9995684 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2024 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	String = BoilerplateType("string")
	Int    = BoilerplateType("int")
	Float  = BoilerplateType("float")
	Bool   = BoilerplateType("bool")
	List   = BoilerplateType("list")
	Map    = BoilerplateType("map")
	Enum   = BoilerplateType("enum")
)
View Source
var ALL_BOILERPLATE_TYPES = []BoilerplateType{String, Int, Float, Bool, List, Map, Enum}
View Source
var BOILERPLATE_TYPE_DEFAULT = String
View Source
var GO_LIST_SYNTAX_REGEX = regexp.MustCompile(`\[(.*)]`)
View Source
var GO_MAP_SYNTAX_REGEX = regexp.MustCompile(`map\[(.*)]`)

Functions

func ConvertType

func ConvertType(value interface{}, variable Variable) (interface{}, error)

Check that the given value matches the type we're expecting in the given variable and return an error if it doesn't

func ConvertYAMLToStringMap

func ConvertYAMLToStringMap(yamlMapOrList interface{}) (interface{}, error)

convertYAMLToStringMap modifies an input with type map[interface{}]interface{} to map[string]interface{} so that it may be properly marshalled in to JSON. See: https://github.com/go-yaml/yaml/issues/139

func ParseVariablesFromVarFile

func ParseVariablesFromVarFile(varFilePath string) (map[string]interface{}, error)

Parse the variables in the given YAML file into a map of variable name to variable value. Along the way, each value is parsed as YAML.

func ParseVars

func ParseVars(varsList []string, varFileList []string) (map[string]interface{}, error)

Parse variables passed in via command line options, either as a list of NAME=VALUE variable pairs in varsList, or a list of paths to YAML files that define NAME: VALUE pairs. Return a map of the NAME: VALUE pairs. Along the way, each VALUE is parsed as YAML.

func ParseYamlString

func ParseYamlString(str string) (interface{}, error)

Parse a YAML string into a Go type

func SplitIntoDependencyNameAndVariableName

func SplitIntoDependencyNameAndVariableName(uniqueVariableName string) (string, string)

Given a unique variable name, return a tuple that contains the dependency name (if any) and the variable name. Variable and dependency names are split by a dot, so for "foo.bar", this will return ("foo", "bar"). For just "foo", it will return ("", "foo").

func UnmarshalListOfStrings

func UnmarshalListOfStrings(fields map[string]interface{}, fieldName string) ([]string, error)

Given a map of key:value pairs read from a Boilerplate YAML config file of the format:

fieldName:

  • value1
  • value2
  • value3

This method takes looks up the given fieldName in the map and unmarshals the data inside of it it into a list of strings with the given values.

func UnmarshalString

func UnmarshalString(fields map[string]interface{}, fieldName string, isRequiredField bool) (*string, error)

UnmarshalString is the public convenience interface for unmarshalStringField.

Types

type BoilerplateType

type BoilerplateType string

An enum that represents the types we support for boilerplate variables

func ParseBoilerplateType

func ParseBoilerplateType(str string) (*BoilerplateType, error)

Convert the given string to a BoilerplateType enum, or return an error if this is not a valid value for the BoilerplateType enum

func (BoilerplateType) String

func (boilerplateType BoilerplateType) String() string

Return a string representation of this Type

type CustomValidationRule

type CustomValidationRule struct {
	Validator validation.Rule
	Message   string
}

func ConvertValidationStringtoRules

func ConvertValidationStringtoRules(ruleString string) ([]CustomValidationRule, error)

ConvertValidationStringtoRules takes the string representation of the variable's validations and parses it into CustomValidationRules that should be run on the variable's value when submitted by a user

func (CustomValidationRule) DescriptionText

func (c CustomValidationRule) DescriptionText() string

type CustomValidationRuleCollection

type CustomValidationRuleCollection []CustomValidationRule

func (CustomValidationRuleCollection) GetValidators

func (c CustomValidationRuleCollection) GetValidators() []validation.Rule

type Dependency

type Dependency struct {
	Name                 string
	TemplateUrl          string
	OutputFolder         string
	Skip                 string
	DontInheritVariables bool
	Variables            []Variable
	VarFiles             []string
	ForEach              []string
	ForEachReference     string
}

A single boilerplate template that this boilerplate.yml depends on being executed first

func UnmarshalDependenciesFromBoilerplateConfigYaml

func UnmarshalDependenciesFromBoilerplateConfigYaml(fields map[string]interface{}) ([]Dependency, error)

Given a map of key:value pairs read from a Boilerplate YAML config file of the format:

dependencies:

  • name: <NAME> template-url: <TEMPLATE_URL> output-folder: <OUTPUT_FOLDER>

  • name: <NAME> template-url: <TEMPLATE_URL> output-folder: <OUTPUT_FOLDER>

This method takes the data above and unmarshals it into a list of Dependency objects

func UnmarshalDependencyFromBoilerplateConfigYaml

func UnmarshalDependencyFromBoilerplateConfigYaml(fields map[string]interface{}) (*Dependency, error)

Given a map of key:value pairs read from a Boilerplate YAML config file of the format:

name: <NAME> template-url: <TEMPLATE_URL> output-folder: <OUTPUT_FOLDER>

This method takes the data above and unmarshals it into a Dependency object

func (Dependency) MarshalYAML

func (dependency Dependency) MarshalYAML() (interface{}, error)

Implement the go-yaml marshaler interface so that the config can be marshaled into yaml. We use a custom marshaler instead of defining the fields as tags so that we skip the attributes that are empty.

type DuplicateDependencyName

type DuplicateDependencyName string

func (DuplicateDependencyName) Error

func (name DuplicateDependencyName) Error() string

type Engine

type Engine struct {
	Path           string             `yaml:"path"`
	TemplateEngine TemplateEngineType `yaml:"template_engine"`
}

A single engine entry, which specifies which template engine should be used to render the given files grabbed by the glob. Currently only the following template engines are supported:

- Go template (default) - Jsonnet

func UnmarshalEnginesFromBoilerplateConfigYaml

func UnmarshalEnginesFromBoilerplateConfigYaml(fields map[string]interface{}) ([]Engine, error)

Given a list of key:value pairs read from a Boilerplate YAML config file of the format:

engines:

  • path: <PATH> template_engine: <TEMPLATE_ENGINE>

convert to a list of Engine structs.

type FormatNotJsonOrGo

type FormatNotJsonOrGo struct {
	ExpectedJsonFormat string
	ExpectedGoFormat   string
	ActualFormat       string
	JsonErr            error
	GoErr              error
}

func (FormatNotJsonOrGo) Error

func (err FormatNotJsonOrGo) Error() string

type Hook

type Hook struct {
	Command    string
	Args       []string
	Env        map[string]string
	Skip       string
	WorkingDir string
}

A single hook, which is a command that is executed by boilerplate

func (Hook) MarshalYAML

func (hook Hook) MarshalYAML() (interface{}, error)

Implement the go-yaml marshaler interface so that the config can be marshaled into yaml. We use a custom marshaler instead of defining the fields as tags so that we skip the attributes that are empty.

type Hooks

type Hooks struct {
	BeforeHooks []Hook
	AfterHooks  []Hook
}

All the scripts to execute as boilerplate hooks

func UnmarshalHooksFromBoilerplateConfigYaml

func UnmarshalHooksFromBoilerplateConfigYaml(fields map[string]interface{}) (Hooks, error)

Given a map of key:value pairs read from a Boilerplate YAML config file of the format:

hooks:

before:
  - command: <CMD>
    args:
      - <ARG>
    env:
      <KEY>: <VALUE>
    skip: <CONDITION>

after:
  - command: <CMD>
    args:
      - <ARG>
    env:
      <KEY>: <VALUE>
    skip: <CONDITION>

This method takes the data above and unmarshals it into a Hooks struct

func (Hooks) MarshalYAML

func (hooks Hooks) MarshalYAML() (interface{}, error)

type InvalidBoilerplateType

type InvalidBoilerplateType string

func (InvalidBoilerplateType) Error

func (err InvalidBoilerplateType) Error() string

type InvalidEntries

type InvalidEntries struct {
	Issues []ValidationIssue
}

type InvalidTemplateEngineErr

type InvalidTemplateEngineErr string

Custom errors

func (InvalidTemplateEngineErr) Error

func (err InvalidTemplateEngineErr) Error() string

type InvalidTypeForField

type InvalidTypeForField struct {
	FieldName    string
	ExpectedType string
	ActualType   reflect.Type
	Context      string
}

func (InvalidTypeForField) Error

func (err InvalidTypeForField) Error() string

type InvalidVarSyntax

type InvalidVarSyntax string

func (InvalidVarSyntax) Error

func (varSyntax InvalidVarSyntax) Error() string

type InvalidVariableValue

type InvalidVariableValue struct {
	Value    interface{}
	Variable Variable
}

func (InvalidVariableValue) Error

func (err InvalidVariableValue) Error() string

type MutexRequiredFieldErr

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

func (MutexRequiredFieldErr) Error

func (err MutexRequiredFieldErr) Error() string

type OptionsCanOnlyBeUsedWithEnum

type OptionsCanOnlyBeUsedWithEnum struct {
	Context string
	Type    BoilerplateType
}

func (OptionsCanOnlyBeUsedWithEnum) Error

type OptionsMissing

type OptionsMissing string

func (OptionsMissing) Error

func (err OptionsMissing) Error() string

type ParseError

type ParseError struct {
	ExpectedType   string
	ExpectedFormat string
	ActualFormat   string
}

func (ParseError) Error

func (err ParseError) Error() string

type RequiredFieldMissing

type RequiredFieldMissing string

func (RequiredFieldMissing) Error

func (err RequiredFieldMissing) Error() string

type SkipFile

type SkipFile struct {
	Path    string
	NotPath string
	If      string
}

A single skip_file entry, which is a file that (conditionally) should be excluded from the rendered output.

func UnmarshalSkipFilesFromBoilerplateConfigYaml

func UnmarshalSkipFilesFromBoilerplateConfigYaml(fields map[string]interface{}) ([]SkipFile, error)

Given a list of key:value pairs read from a Boilerplate YAML config file of the format:

skip_files:

  • path: <PATH> if: <SKIPIF>
  • path: <PATH>
  • not_path: <PATH>

convert to a list of SkipFile structs.

func (SkipFile) MarshalYAML

func (skipFile SkipFile) MarshalYAML() (interface{}, error)

Implement the go-yaml marshaler interface so that the config can be marshaled into yaml. We use a custom marshaler instead of defining the fields as tags so that we skip the attributes that are empty.

type TemplateEngineType

type TemplateEngineType string
const (
	GoTemplate            TemplateEngineType = "go-template"
	Jsonnet               TemplateEngineType = "jsonnet"
	DefaultTemplateEngine                    = GoTemplate
)

type UndefinedOrderForFieldErr

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

func (UndefinedOrderForFieldErr) Error

func (err UndefinedOrderForFieldErr) Error() string

type UnrecognizedBoilerplateType

type UnrecognizedBoilerplateType BoilerplateType

func (UnrecognizedBoilerplateType) Error

func (err UnrecognizedBoilerplateType) Error() string

type ValidationIssue

type ValidationIssue struct {
	Value         interface{}
	ValidationMap map[string]bool
}

type ValidationsMissing

type ValidationsMissing string

func (ValidationsMissing) Error

func (err ValidationsMissing) Error() string

type Variable

type Variable interface {
	// The name of the variable
	Name() string

	// The full name of this variable, which includes its name and the dependency it is for (if any) in a
	// human-readable format
	FullName() string

	// The description of the variable, if any
	Description() string

	// The type of the variable
	Type() BoilerplateType

	// The user-defined sorting position of the variable
	Order() int

	// The default value for the variable, if any
	Default() interface{}

	// The name of another variable from which this variable should take its value
	Reference() string

	// The values this variable can take. Applies only if Type() is Enum.
	Options() []string

	// Return a copy of this variable but with the name set to the given name
	WithName(string) Variable

	// Return a copy of this variable but with the description set to the given description
	WithDescription(string) Variable

	// Return a copy of this variable but with the default set to the given value
	WithDefault(interface{}) Variable

	// Create a human-readable, string representation of the variable
	String() string

	// Show an example value that would be valid for this variable
	ExampleValue() string

	// A custom marshaling function to translate back to YAML, as expected by go-yaml.
	MarshalYAML() (interface{}, error)

	// Validations that should be run on the variable
	Validations() []CustomValidationRule
}

An interface for a variable defined in a boilerplate.yml config file

func NewBoolVariable

func NewBoolVariable(name string) Variable

Create a new variable that holds a bool

func NewEnumVariable

func NewEnumVariable(name string, options []string) Variable

Create a new variable that holds an enum with the given possible values

func NewFloatVariable

func NewFloatVariable(name string) Variable

Create a new variable that holds a float

func NewIntVariable

func NewIntVariable(name string) Variable

Create a new variable that holds an int

func NewListVariable

func NewListVariable(name string) Variable

Create a new variable that holds a list of strings

func NewMapVariable

func NewMapVariable(name string) Variable

Create a new variable that holds a map of string to string

func NewStringVariable

func NewStringVariable(name string) Variable

Create a new variable that holds a string

func UnmarshalVariableFromBoilerplateConfigYaml

func UnmarshalVariableFromBoilerplateConfigYaml(fields map[string]interface{}) (Variable, error)

Given a map of key:value pairs read from a Boilerplate YAML config file of the format:

name: <NAME> description: <DESCRIPTION> type: <TYPE> default: <DEFAULT>

This method takes the data above and unmarshals it into a Variable object

func UnmarshalVariablesFromBoilerplateConfigYaml

func UnmarshalVariablesFromBoilerplateConfigYaml(fields map[string]interface{}) ([]Variable, error)

Given a map of key:value pairs read from a Boilerplate YAML config file of the format:

variables:

  • name: <NAME> description: <DESCRIPTION> type: <TYPE>

  • name: <NAME> description: <DESCRIPTION> default: <DEFAULT>

This method takes the data above and unmarshals it into a list of Variable objects

type VariableNameCannotBeEmpty

type VariableNameCannotBeEmpty string

func (VariableNameCannotBeEmpty) Error

func (varSyntax VariableNameCannotBeEmpty) Error() string

type YAMLConversionErr

type YAMLConversionErr struct {
	Key interface{}
}

func (YAMLConversionErr) Error

func (err YAMLConversionErr) Error() string

Jump to

Keyboard shortcuts

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