Documentation ¶
Overview ¶
Package configuration implements configuration loading logic for stencil repositories and template repositories
Index ¶
Examples ¶
Constants ¶
const ValidateNameRegexp = `^[_a-z][_a-z0-9-]*$`
ValidateNameRegexp is the regex used to validate the project's name
Variables ¶
This section is empty.
Functions ¶
func ValidateName ¶
ValidateName ensures that the name of a project in the manifest fits the criteria we require.
Example ¶
package main import ( "fmt" "go.rgst.io/stencil/pkg/configuration" ) func main() { // Normal name success := configuration.ValidateName("test") fmt.Println("success:", success) // Invalid name success = configuration.ValidateName("test.1234") fmt.Println("success:", success) }
Output: success: true success: false
Types ¶
type Argument ¶
type Argument struct { // Description is a description of this argument. Description string `yaml:"description"` // Required denotes this argument as required. Required bool `yaml:"required,omitempty"` // Default is the default value for this argument if it's not set. // This cannot be set when required is true. Default interface{} `yaml:"default,omitempty"` // Schema is a JSON schema, in YAML, for the argument. Schema map[string]any `yaml:"schema"` // From is a reference to an argument in another module, if this is // set, all other fields are ignored and instead the module referenced // field's are used instead. The name of the argument, the key in the map, // must be the same across both modules. From string `yaml:"from,omitempty"` }
Argument is a user-input argument that can be passed to templates
type Manifest ¶
type Manifest struct { // Name is the name of the project Name string `yaml:"name" jsonschema:"required"` // Modules are the template modules that this project depends // on and utilizes Modules []*TemplateRepository `yaml:"modules,omitempty"` // Versions is a map of versions of certain tools, this is used by templates // and will likely be replaced with something better in the future. Versions map[string]string `yaml:"versions,omitempty"` // Arguments is a map of arbitrary arguments to pass to the generator Arguments map[string]any `yaml:"arguments"` // Replacements is a list of module names to replace their URI. // // Expected format: // - local file: path/to/module // - remote file: https://github.com/rgst-io/stencil-base Replacements map[string]string `yaml:"replacements,omitempty"` }
Manifest is a manifest used to describe a project and impact what files are included
func LoadDefaultManifest ¶ added in v0.10.0
LoadDefaultManifest returns a parsed project manifest from a set default path on disk.
func LoadManifest ¶ added in v0.10.0
LoadManifest reads a manifest from disk at the specified path, parses it, and returns the output.
In most cases, you should use LoadDefaultManifest instead as it contains the standard locations for a manifest as well as getoutreach/stencil interop.
func NewDefaultManifest
deprecated
func NewManifest
deprecated
NewManifest reads a manifest from disk at the specified path, parses it, and returns the output.
Deprecated: Use LoadManifest instead.
Example ¶
package main import ( "fmt" "go.rgst.io/stencil/pkg/configuration" ) func main() { sm, err := configuration.NewManifest("testdata/stencil.yaml") if err != nil { // handle the error fmt.Println("error:", err) return } fmt.Println(sm.Name) fmt.Println(sm.Arguments) }
Output: testing map[hello:world]
type PostRunCommandSpec ¶
type PostRunCommandSpec struct { // Name is the name of the command being ran, used for UX Name string `yaml:"name,omitempty"` // Command is the command to be ran, note: this is ran inside // of a bash shell. Command string `yaml:"command" jsonschema:"required"` }
PostRunCommandSpec is the spec of a command to be ran and its friendly name
type TemplateRepository ¶
type TemplateRepository struct { // Name is the name of this module. This should be a valid go import path Name string `yaml:"name" jsonschema:"required"` // Version is a semantic version or branch of the template repository // that should be downloaded if not set then the latest version is used. // // Version can also be a constraint as supported by the underlying // resolver: // https://pkg.go.dev/go.rgst.io/stencil/internal/modules/resolver // // But note that constraints are currently not locked so the version // will change as the module is resolved on subsequent runs. // Eventually, this will be changed to use the lockfile by default. Version string `yaml:"version,omitempty"` }
TemplateRepository is a repository of template files.
type TemplateRepositoryManifest ¶
type TemplateRepositoryManifest struct { // Name is the name of this template repository. // This must match the import path. Name string `yaml:"name" jsonschema:"required"` // Modules are template repositories that this manifest requires Modules []*TemplateRepository `yaml:"modules,omitempty"` // MinStencilVersion is the minimum version of stencil that is required to // render this module. MinStencilVersion string `yaml:"minStencilVersion,omitempty"` // Type stores a comma-separated list of template repository types served by the current module. // Use the TemplateRepositoryTypes.Contains method to check. Type TemplateRepositoryTypes `yaml:"type,omitempty"` // PostRunCommand is a command to be ran after rendering and post-processors // have been ran on the project PostRunCommand []*PostRunCommandSpec `yaml:"postRunCommand,omitempty"` // Arguments are a declaration of arguments to the template generator Arguments map[string]Argument `yaml:"arguments,omitempty"` // DirReplacements is a list of directory name replacement templates to render DirReplacements map[string]string `yaml:"dirReplacements,omitempty"` }
TemplateRepositoryManifest is a manifest of a template repository
func LoadDefaultTemplateRepositoryManifest ¶ added in v0.10.0
func LoadDefaultTemplateRepositoryManifest() (*TemplateRepositoryManifest, error)
LoadDefaultTemplateRepositoryManifest reads a template repository manifest from disk and returns it, using a standard set of locations.
func LoadTemplateRepositoryManifest ¶ added in v0.10.0
func LoadTemplateRepositoryManifest(path string) (*TemplateRepositoryManifest, error)
LoadTemplateRepositoryManifest reads a template repository manifest from disk and returns it.
In most cases, you should use LoadDefaultTemplateRepositoryManifest instead as it contains the standard locations for a manifest.
type TemplateRepositoryType ¶
type TemplateRepositoryType string
TemplateRepositoryType specifies what type of a stencil repository the current one is.
const ( // TemplateRepositoryTypeExt denotes a repository as being // an extension repository. This means that it contains // a go extension. This repository may also contain go-templates if // this type is used together with the TemplateRepositoryTypeTemplates. TemplateRepositoryTypeExt TemplateRepositoryType = "extension" // TemplateRepositoryTypeTemplates denotes a repository as being a standard template repository. // When the same module/repo serves more than one type, join this explicit value with other // types, e.g. "templates,extension". TemplateRepositoryTypeTemplates TemplateRepositoryType = "templates" )
This block contains all of the TemplateRepositoryType values
type TemplateRepositoryTypes ¶
type TemplateRepositoryTypes []TemplateRepositoryType
TemplateRepositoryTypes specifies what type of a stencil repository the current one is. Use Contains to check for a type - it has special handling for the default case. Even though it is a struct, it is marshalled and unmarshalled as a string with comma separated values of TemplateRepositoryType.
func (TemplateRepositoryTypes) Contains ¶
func (ts TemplateRepositoryTypes) Contains(t TemplateRepositoryType) bool
Contains returns true if current repo needs to serve inpt type, with default assumed to be a templates-only repo (we do not support repos with no purpose).
func (*TemplateRepositoryTypes) UnmarshalYAML ¶
func (ts *TemplateRepositoryTypes) UnmarshalYAML(value *yaml.Node) error
UnmarshalYAML unmarshals TemplateRepositoryTypes from a string with comma-separated values.