Documentation ¶
Index ¶
- Variables
- func BubbleAsk(inputs []*Input) (map[string]string, error)
- func Copy(srcPath, dstPath string, src, dst afero.Fs) error
- func Create(appFs afero.Fs, sourceDir, targetDir string, dryrun bool, ...) error
- func Execute(source *Source, target *Target, userData map[string]string) error
- func PromptUser(inputs []*Input, current map[string]string, ask AskFunc) (map[string]string, error)
- func Template(srcPath, dstPath string, src, dst afero.Fs, data any) error
- type ActionType
- type AskFunc
- type Bones
- type Context
- type Data
- type FileData
- type Input
- type Rule
- type Source
- type SourceData
- type Target
- type TargetData
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidActionType = errors.New("not a valid ActionType")
Functions ¶
func Copy ¶
Copy copies a file from the source path to the destination path without applying any transformations
func PromptUser ¶
Types ¶
type ActionType ¶
type ActionType int
ENUM(COPY, TEMPLATE, IGNORE)
const ( // COPY is a ActionType of type COPY. COPY ActionType = iota // TEMPLATE is a ActionType of type TEMPLATE. TEMPLATE // IGNORE is a ActionType of type IGNORE. IGNORE )
func ParseActionType ¶
func ParseActionType(name string) (ActionType, error)
ParseActionType attempts to convert a string to a ActionType.
func (ActionType) MarshalText ¶
func (x ActionType) MarshalText() ([]byte, error)
MarshalText implements the text marshaller method.
func (ActionType) String ¶
func (x ActionType) String() string
String implements the Stringer interface.
func (*ActionType) UnmarshalText ¶
func (x *ActionType) UnmarshalText(text []byte) error
UnmarshalText implements the text unmarshaller method.
type Bones ¶
type Bones struct { // AllowExisting allows the template to be applied to a directory which already exists AllowExisting bool `yaml:"allow_existing" json:"allow_existing,omitempty" jsonschema:"default=false"` Rules []Rule `yaml:"rules" json:"rules"` Inputs []*Input `yaml:"inputs" json:"inputs,omitempty"` }
Bones describes the template behavior and is read from the bones file in the template directory
func DefaultBones ¶
func DefaultBones() *Bones
type Context ¶
A Context is the data required for a templated file to be executed and written to disk. In particular, SrcFS is a filesystem rooted at the folder containing all input files (typically the template subdirectory of the Khandra repository), and DstFS is a filesystem rooted at the folder where the template should be initialized.
type Data ¶
type Data struct { SourceData TargetData FileData U map[string]string // UserData }
func MergeData ¶
func MergeData(userData map[string]string, sourceData SourceData, targetData TargetData) *Data
type Input ¶
type Rule ¶
type Rule struct { Pattern string `yaml:"pattern" json:"pattern"` // rule is a candidate for application if the path matches this pattern Action ActionType `yaml:"action" json:"action" jsonschema:"type=string"` // COPY, TEMPLATE, IGNORE Priority int `yaml:"priority" json:"priority,omitempty" jsonschema:"default=0"` // higher priority rules win over lower priority rules Rename string `yaml:"rename,omitempty" json:"rename,omitempty"` // a template to rename the file }
A Rule describes how to translate a source file into a destination file
type Source ¶
type Source struct { Root string // Root is the directory the template is located in Fs afero.Fs // Fs is the filesystem the source was read from Bones *Bones // The Bones files which specifies the template }
A Source represents a Khandra template on disk. Generally anything that can be known only from the source template should be bundled into Source
type SourceData ¶
type SourceData struct { }
type Target ¶
type Target struct { Root string // Root is the directory the template will be initialized in Fs afero.Fs // Fs is the filesystem the target will be written to }
A Target represents a call to initialize a template Generally anything that depends on the initialization location or the user's input should be bundled into Target
func (*Target) Data ¶
func (t *Target) Data() TargetData
type TargetData ¶
type TargetData struct {
TargetName string
}