gotemplate

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2023 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyExists         = errors.New("already exists")
	ErrParameterNotSet       = errors.New("parameter not set")
	ErrMalformedInput        = errors.New("malformed input")
	ErrParameterSet          = errors.New("parameter set but has no effect in this context")
	ErrGoVersionNotSupported = fmt.Errorf("go version is not supported, gt requires at least %s", minGoVersion)
)

Functions

This section is empty.

Types

type BoolValue

type BoolValue bool

func (BoolValue) Value

func (v BoolValue) Value(_ *OptionValues) bool

type BoolValuer

type BoolValuer interface {
	Value(vals *OptionValues) bool
}

type Category

type Category struct {
	Name    string
	Options []Option
}

Category is used to wrap multiple extensions into one organizational unit. This is to reduce the amount of required user input if certain categories if extensions can be skipped as a category instead of needing to skip all one by one.

type DynamicBoolValue

type DynamicBoolValue func(vals *OptionValues) bool

DefferedValue is a func that calculates the Value based on earlier inputs.

func (DynamicBoolValue) Value

func (f DynamicBoolValue) Value(vals *OptionValues) bool

type DynamicStringValue

type DynamicStringValue func(vals *OptionValues) string

DefferedValue is a func that calculates the Value based on earlier inputs.

func (DynamicStringValue) Value

func (f DynamicStringValue) Value(vals *OptionValues) string

type DynamicValue

type DynamicValue func(vals *OptionValues) interface{}

DefferedValue is a func that calculates the Value based on earlier inputs.

func (DynamicValue) Value

func (f DynamicValue) Value(vals *OptionValues) interface{}

type ErrInvalidPattern

type ErrInvalidPattern struct {
	Value       string
	Pattern     string
	Description string
}

ErrInvalidPattern indicates that an error occurred while matching a value with a pattern. The pattern as well as a description for the pattern is included in the error message.

func (*ErrInvalidPattern) Error

func (e *ErrInvalidPattern) Error() string

type ErrOutOfRange

type ErrOutOfRange struct {
	Value int
	Min   int
	Max   int
}

func (*ErrOutOfRange) Error

func (e *ErrOutOfRange) Error() string

type ErrTypeMismatch

type ErrTypeMismatch struct {
	Expected string
	Actual   string
}

func (*ErrTypeMismatch) Error

func (e *ErrTypeMismatch) Error() string

type GT

type GT struct {
	Streams
	Options         *Options
	FuncMap         template.FuncMap
	GithubTagLister repos.GithubTagLister
	// contains filtered or unexported fields
}

func New

func New() *GT

func (*GT) CheckVersion

func (gt *GT) CheckVersion()

func (*GT) InitNewProject

func (gt *GT) InitNewProject(opts *NewRepositoryOptions) (err error)

func (*GT) LoadConfigValuesFromFile

func (gt *GT) LoadConfigValuesFromFile(file string) (*OptionValues, error)

LoadConfigValuesFromFile loads value for the options from a file and validates the inputs

func (*GT) LoadConfigValuesInteractively

func (gt *GT) LoadConfigValuesInteractively() (*OptionValues, error)

func (*GT) PrintVersion

func (gt *GT) PrintVersion()

type NewOptionOption

type NewOptionOption func(*Option)

func WithPosthook

func WithPosthook(postHook PostHookFunc) NewOptionOption

func WithShouldDisplay

func WithShouldDisplay(shouldDisplay BoolValuer) NewOptionOption

func WithValidator

func WithValidator(validator Validator) NewOptionOption

type NewRepositoryOptions

type NewRepositoryOptions struct {
	OutputDir    string
	OptionValues *OptionValues
}

func (NewRepositoryOptions) Validate

func (opts NewRepositoryOptions) Validate() error

Validate validates all properties of NewRepositoryOptions except the ConfigValues, since those are validated by the Load functions.

type Option

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

Option is a struct containing all needed configuration for options to customize the template.

func NewOption

func NewOption(name, description string, defaultValue Valuer, opts ...NewOptionOption) Option

func (*Option) Default

func (s *Option) Default(currentValues *OptionValues) interface{}

Default either returns the default value (possibly calculated with currentValues).

func (*Option) Description

func (s *Option) Description() string

func (*Option) Name

func (s *Option) Name() string

func (*Option) PostHook

func (s *Option) PostHook(v interface{}, optionValues *OptionValues, targetDir string) error

PostHook executes the registered postHook if there is any.

func (*Option) ShouldDisplay

func (s *Option) ShouldDisplay(currentValues *OptionValues) bool

ShouldDisplay returns a bool value indicating whether the option should be shown or not. If shouldDisplay variable is not set on the option true is returned.

func (*Option) Validate

func (s *Option) Validate(value interface{}) error

Validate validates the value if a validator is specified.

type OptionNameToValue

type OptionNameToValue map[string]interface{}

type OptionValues

type OptionValues struct {
	Base       OptionNameToValue            `yaml:"base"`
	Extensions map[string]OptionNameToValue `yaml:"extensions"`
}

OptionValues is a struct mirroring the structure of Options but using maps. Instead of the whole option only the set value of the option is kept. This makes looking up already supplied option values easier than it would be in the Options struct.

func NewOptionValues

func NewOptionValues() *OptionValues

type Options

type Options struct {
	Base       []Option
	Extensions []Category
}

Options is the main struct wrapping the configuration for all allowed parameters and extensions. Slices are used instead of maps since the iteration order of maps is undefined/random. which could lead to confusion.

func NewOptions

func NewOptions(githubTagLister repos.GithubTagLister) *Options

NewOptions returns all of go/template's options.

type PostHookFunc

type PostHookFunc func(value interface{}, optionValues *OptionValues, targetDir string) error

type Streams

type Streams struct {
	Out       io.Writer
	Err       io.Writer
	InScanner *bufio.Scanner
}

type StringValue

type StringValue string

func (StringValue) Value

func (v StringValue) Value(_ *OptionValues) string

type StringValuer

type StringValuer interface {
	Value(vals *OptionValues) string
}

type Validator

type Validator interface {
	Validate(value interface{}) error
}

Validator is a single method interface that validates that a given value is valid. If any error happens during validation or if the value is not valid an error will be returned.

type ValidatorFunc

type ValidatorFunc func(value interface{}) error

ValidatorFunc is a function implementing the Validator interface.

func RangeValidator

func RangeValidator(min, max int) ValidatorFunc

RangeValidator validates that value is in between or equal to min and max.

func RegexValidator

func RegexValidator(pattern, description string) ValidatorFunc

RegexValidator returns a ValidatorFunc to validate a given value against a regex pattern. If the pattern doesn't match a ErrInvalidPattern is returned with a description on what the pattern means.

func (ValidatorFunc) Validate

func (f ValidatorFunc) Validate(value interface{}) error

type Value

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

func StaticValue

func StaticValue(v interface{}) *Value

func (*Value) Value

func (v *Value) Value(_ *OptionValues) interface{}

type Valuer

type Valuer interface {
	Value(vals *OptionValues) interface{}
}

Jump to

Keyboard shortcuts

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