Documentation ¶
Index ¶
- Variables
- func ConvertType(value interface{}, variable Variable) (interface{}, error)
- func ConvertYAMLToStringMap(yamlMapOrList any) (interface{}, error)
- func ParseVariablesFromVarFile(varFilePath string) (map[string]any, error)
- func ParseVars(varsList []string, varFileList []string) (map[string]any, error)
- func ParseYamlString(str string) (any, error)
- func SplitIntoDependencyNameAndVariableName(uniqueVariableName string) (string, string)
- func UnmarshalListOfStrings(fields map[string]any, fieldName string) ([]string, error)
- func UnmarshalString(fields map[string]any, fieldName string, isRequiredField bool) (*string, error)
- type BoilerplateType
- type CustomValidationRule
- type CustomValidationRuleCollection
- type Dependency
- type DuplicateDependencyName
- type Engine
- type FormatNotJsonOrGo
- type Hook
- type Hooks
- type InvalidBoilerplateType
- type InvalidEntries
- type InvalidTemplateEngineErr
- type InvalidTypeForField
- type InvalidVarSyntax
- type InvalidVariableValue
- type MutexRequiredFieldErr
- type OptionsCanOnlyBeUsedWithEnum
- type OptionsMissing
- type ParseError
- type RequiredFieldMissing
- type SkipFile
- type TemplateEngineType
- type UndefinedOrderForFieldErr
- type UnrecognizedBoilerplateType
- type ValidationIssue
- type ValidationsMissing
- type Variable
- func NewBoolVariable(name string) Variable
- func NewEnumVariable(name string, options []string) Variable
- func NewFloatVariable(name string) Variable
- func NewIntVariable(name string) Variable
- func NewListVariable(name string) Variable
- func NewMapVariable(name string) Variable
- func NewStringVariable(name string) Variable
- func UnmarshalVariableFromBoilerplateConfigYaml(fields map[string]interface{}) (Variable, error)
- func UnmarshalVariablesFromBoilerplateConfigYaml(fields map[string]interface{}) ([]Variable, error)
- type VariableNameCannotBeEmpty
- type YAMLConversionErr
Constants ¶
This section is empty.
Variables ¶
var ( String = BoilerplateType("string") Int = BoilerplateType("int") Float = BoilerplateType("float") Bool = BoilerplateType("bool") List = BoilerplateType("list") Map = BoilerplateType("map") Enum = BoilerplateType("enum") )
var ALL_BOILERPLATE_TYPES = []BoilerplateType{String, Int, Float, Bool, List, Map, Enum}
var BOILERPLATE_TYPE_DEFAULT = String
var GO_LIST_SYNTAX_REGEX = regexp.MustCompile(`\[(.*)]`)
var GO_MAP_SYNTAX_REGEX = regexp.MustCompile(`map\[(.*)]`)
Functions ¶
func ConvertType ¶
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 ¶ added in v0.3.2
convertYAMLToStringMap modifies an input with type map[any]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 ¶
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 ¶
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 ¶
Parse a YAML string into a Go type
func SplitIntoDependencyNameAndVariableName ¶
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 ¶ added in v0.3.1
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.
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 ¶ added in v0.5.8
type CustomValidationRule struct { Validator validation.Rule Message string }
func ConvertValidationStringtoRules ¶ added in v0.5.8
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 ¶ added in v0.5.8
func (c CustomValidationRule) DescriptionText() string
type CustomValidationRuleCollection ¶ added in v0.5.8
type CustomValidationRuleCollection []CustomValidationRule
func (CustomValidationRuleCollection) GetValidators ¶ added in v0.5.8
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 ¶ added in v0.3.6
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 ¶ added in v0.3.5
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 ¶ added in v0.3.5
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 ¶ added in v0.3.6
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 ¶
All the scripts to execute as boilerplate hooks
func UnmarshalHooksFromBoilerplateConfigYaml ¶
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 ¶ added in v0.3.6
type InvalidBoilerplateType ¶
type InvalidBoilerplateType string
func (InvalidBoilerplateType) Error ¶
func (err InvalidBoilerplateType) Error() string
type InvalidEntries ¶ added in v0.5.8
type InvalidEntries struct {
Issues []ValidationIssue
}
type InvalidTemplateEngineErr ¶ added in v0.3.5
type InvalidTemplateEngineErr string
Custom errors
func (InvalidTemplateEngineErr) Error ¶ added in v0.3.5
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 ¶
func (InvalidVariableValue) Error ¶
func (err InvalidVariableValue) Error() string
type MutexRequiredFieldErr ¶ added in v0.3.7
type MutexRequiredFieldErr struct {
// contains filtered or unexported fields
}
func (MutexRequiredFieldErr) Error ¶ added in v0.3.7
func (err MutexRequiredFieldErr) Error() string
type OptionsCanOnlyBeUsedWithEnum ¶
type OptionsCanOnlyBeUsedWithEnum struct { Context string Type BoilerplateType }
func (OptionsCanOnlyBeUsedWithEnum) Error ¶
func (err OptionsCanOnlyBeUsedWithEnum) Error() string
type OptionsMissing ¶
type OptionsMissing string
func (OptionsMissing) Error ¶
func (err OptionsMissing) Error() string
type ParseError ¶
func (ParseError) Error ¶
func (err ParseError) Error() string
type RequiredFieldMissing ¶
type RequiredFieldMissing string
func (RequiredFieldMissing) Error ¶
func (err RequiredFieldMissing) Error() string
type SkipFile ¶ added in v0.3.4
A single skip_file entry, which is a file that (conditionally) should be excluded from the rendered output.
func UnmarshalSkipFilesFromBoilerplateConfigYaml ¶ added in v0.3.4
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 ¶ added in v0.3.6
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 ¶ added in v0.3.5
type TemplateEngineType string
const ( GoTemplate TemplateEngineType = "go-template" Jsonnet TemplateEngineType = "jsonnet" DefaultTemplateEngine = GoTemplate )
type UndefinedOrderForFieldErr ¶ added in v0.5.8
type UndefinedOrderForFieldErr struct {
// contains filtered or unexported fields
}
func (UndefinedOrderForFieldErr) Error ¶ added in v0.5.8
func (err UndefinedOrderForFieldErr) Error() string
type UnrecognizedBoilerplateType ¶
type UnrecognizedBoilerplateType BoilerplateType
func (UnrecognizedBoilerplateType) Error ¶
func (err UnrecognizedBoilerplateType) Error() string
type ValidationIssue ¶ added in v0.5.8
type ValidationsMissing ¶ added in v0.5.8
type ValidationsMissing string
func (ValidationsMissing) Error ¶ added in v0.5.8
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 ¶
Create a new variable that holds a bool
func NewEnumVariable ¶
Create a new variable that holds an enum with the given possible values
func NewFloatVariable ¶
Create a new variable that holds a float
func NewIntVariable ¶
Create a new variable that holds an int
func NewListVariable ¶
Create a new variable that holds a list of strings
func NewMapVariable ¶
Create a new variable that holds a map of string to string
func NewStringVariable ¶
Create a new variable that holds a string
func UnmarshalVariableFromBoilerplateConfigYaml ¶
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 ¶
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 ¶ added in v0.3.2
type YAMLConversionErr struct {
Key any
}
func (YAMLConversionErr) Error ¶ added in v0.3.2
func (err YAMLConversionErr) Error() string