config

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MPL-2.0 Imports: 24 Imported by: 2

Documentation

Overview

Package config provides functionality for loading and parsing boilerplate configuration files.

Index

Constants

View Source
const BoilerplateConfigFile = "boilerplate.yml"
View Source
const MaxReferenceDepth = 20

Variables

This section is empty.

Functions

func BoilerplateConfigPath added in v0.3.0

func BoilerplateConfigPath(templateFolder string) string

BoilerplateConfigPath returns the default path for a boilerplate.yml config file in the given folder.

func EnforceRequiredVersion added in v0.4.3

func EnforceRequiredVersion(boilerplateConfig *BoilerplateConfig) error

EnforceRequiredVersion enforces any required_version string that is configured on the boilerplate config by checking against the current version of the CLI.

func EnforceRequiredVersionWithProvider added in v0.10.1

func EnforceRequiredVersionWithProvider(boilerplateConfig *BoilerplateConfig, versionProvider VersionProvider) error

EnforceRequiredVersionWithProvider enforces any required_version string that is configured on the boilerplate config by checking against the version provided by the VersionProvider. This allows for dependency injection in tests.

func GetValueForVariable added in v0.5.8

func GetValueForVariable(
	variable variables.Variable,
	variablesInConfig map[string]variables.Variable,
	valuesForPreviousVariables map[string]any,
	opts *options.BoilerplateOptions,
	referenceDepth int,
) (any, error)

func GetVariables

func GetVariables(opts *options.BoilerplateOptions, boilerplateConfig, rootBoilerplateConfig *BoilerplateConfig, thisDep *variables.Dependency) (map[string]any, error)

GetVariables gets a value for each of the variables specified in boilerplateConfig, other than those already in existingVariables. The value for a variable can come from the user (if the non-interactive option isn't set), the default value in the config, or a command line option.

func GetVariablesWithContext added in v0.10.1

func GetVariablesWithContext(ctx context.Context, opts *options.BoilerplateOptions, boilerplateConfig, rootBoilerplateConfig *BoilerplateConfig, thisDep *variables.Dependency) (map[string]any, error)

GetVariablesWithContext collects variables from the user, variable defaults in the boilerplate.yml config, command line options, and environment variables. Variables in Boilerplate can can be used in both the Boilerplate config itself and in the templates.

The value for a variable can come from the user (if the non-interactive option isn't set), the default value in the config, or a command line option.

Types

type BoilerplateConfig

type BoilerplateConfig struct {
	RequiredVersion *string
	Variables       []variables.Variable
	Dependencies    []variables.Dependency
	Hooks           variables.Hooks
	Partials        []string
	SkipFiles       []variables.SkipFile
	Engines         []variables.Engine
}

BoilerplateConfig represents the contents of a boilerplate.yml config file.

func LoadBoilerplateConfig added in v0.3.0

func LoadBoilerplateConfig(opts *options.BoilerplateOptions) (*BoilerplateConfig, error)

LoadBoilerplateConfig loads the boilerplate.yml config contents for the folder specified in the given options.

func ParseBoilerplateConfig

func ParseBoilerplateConfig(configContents []byte) (*BoilerplateConfig, error)

ParseBoilerplateConfig parses the given configContents as a boilerplate.yml config file.

func (*BoilerplateConfig) GetVariablesMap added in v0.5.8

func (config *BoilerplateConfig) GetVariablesMap() map[string]variables.Variable

GetVariablesMap returns a map that maps variable names to the variable config.

func (*BoilerplateConfig) MarshalYAML added in v0.3.6

func (config *BoilerplateConfig) MarshalYAML() (any, error)

MarshalYAML implements 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.

func (*BoilerplateConfig) UnmarshalYAML added in v0.3.0

func (config *BoilerplateConfig) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements the go-yaml unmarshal interface for BoilerplateConfig. We can't let go-yaml handle this itself because:

  1. Variable is an interface
  2. We need to provide Defaults for optional fields, such as "type"
  3. We want to validate the variable as part of the unmarshalling process so we never have invalid Variable or Dependency classes floating around

type BoilerplateConfigNotFound added in v0.3.0

type BoilerplateConfigNotFound string

func (BoilerplateConfigNotFound) Error added in v0.3.0

func (err BoilerplateConfigNotFound) Error() string

type CyclicalReference added in v0.3.0

type CyclicalReference struct {
	VariableName  string
	ReferenceName string
}

func (CyclicalReference) Error added in v0.3.0

func (err CyclicalReference) Error() string

type DefaultVersionProvider added in v0.10.1

type DefaultVersionProvider struct{}

DefaultVersionProvider uses the standard go-commons version package.

func (DefaultVersionProvider) GetVersion added in v0.10.1

func (p DefaultVersionProvider) GetVersion() string

type InvalidBoilerplateVersion added in v0.4.3

type InvalidBoilerplateVersion struct {
	CurrentVersion     *goversion.Version
	VersionConstraints goversion.Constraints
}

func (InvalidBoilerplateVersion) Error added in v0.4.3

func (err InvalidBoilerplateVersion) Error() string

type KeyAndOrderPair added in v0.5.8

type KeyAndOrderPair struct {
	Key   string
	Order int
}

KeyAndOrderPair is a composite of the user-defined order and the user's variable name

type MissingReference added in v0.3.0

type MissingReference struct {
	VariableName  string
	ReferenceName string
}

func (MissingReference) Error added in v0.3.0

func (err MissingReference) Error() string

type MissingVariableWithNonInteractiveMode

type MissingVariableWithNonInteractiveMode string

func (MissingVariableWithNonInteractiveMode) Error

func (variableName MissingVariableWithNonInteractiveMode) Error() string

type VersionProvider added in v0.10.1

type VersionProvider interface {
	GetVersion() string
}

VersionProvider is an interface for providing version information. This allows for dependency injection in tests.

Jump to

Keyboard shortcuts

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