Documentation ¶
Index ¶
- Constants
- Variables
- func CreateDir(prompt *Prompt, root string, fsys fs.FS, options ...CreatorOption) error
- func ExecuteTemplate(tmpl *template.Template, data interface{}) (fs.FS, error)
- func ModInit(path string) (string, error)
- func ParseTemplate(tmplFS fs.FS, name, stripPrefix string, options ...TemplateOption) (*template.Template, error)
- type Creator
- type CreatorOption
- type Prompt
- type TemplateOption
Constants ¶
const ( Cancel overwritePolicy ForceOverwrite Confirm NewOnly )
Variables ¶
var DefaultFuncMap = template.FuncMap{ "gitkeep": func() string { return ".gitkeep" }, "gomod": func() string { return "go.mod" }, "gomodinit": func(path string) string { f, err := ModInit(path) if err != nil { panic(err) } return f }, }
DefaultFuncMap is a default functions which using in a template.
var DefaultPrompt = &Prompt{ Input: os.Stdin, Output: os.Stdout, ErrOutput: os.Stderr, }
DefaultPrompt is default Prompt.
Functions ¶
func CreateDir ¶
CreateDir creates files and directories which structure is the same with the given file system. The path of created root directory become the parameter root.
func ExecuteTemplate ¶
ExecuteTemplate executes a template with data. ExecuteTemplate also parses the excuted string as a txtar format and return it as a file system.
func ParseTemplate ¶
func ParseTemplate(tmplFS fs.FS, name, stripPrefix string, options ...TemplateOption) (*template.Template, error)
ParseTemplate parses a template which represents as txtar format from given a file system. The name is template name. If stripPrefix is not empty string, ParseTemplate uses sub directory of stripPrefix.
Types ¶
type Creator ¶ added in v0.3.0
type Creator struct {
// contains filtered or unexported fields
}
Creator is the representation of a file and directory writer.
type CreatorOption ¶ added in v0.3.0
type CreatorOption func(*Creator)
CreatorOption is an option for a creator. It can decorate a creator.
func CreatorWithEmpty ¶ added in v0.3.0
func CreatorWithEmpty(include bool) CreatorOption
CreatorWithEmpty sets if a creator must write empty files.
func CreatorWithPolicy ¶ added in v0.3.0
func CreatorWithPolicy(policy overwritePolicy) CreatorOption
CreatorWithPolicy sets the overwriting policy of a creator.
func CreatorWithSkipFunc ¶ added in v0.4.0
func CreatorWithSkipFunc(skipfunc func(path string, d fs.DirEntry) bool) CreatorOption
CreatorWithSkipFunc sets a function if it returns true a file or a directory would be skipped.
type Prompt ¶
Prompt receive input from a user.
type TemplateOption ¶ added in v0.2.0
TemplateOption is an option for a template. It can decorate the template.
func TemplateWithDelims ¶ added in v0.2.0
func TemplateWithDelims(left, right string) TemplateOption
TemplateWithDelims sets delims of a template.
func TemplateWithFuncs ¶ added in v0.2.0
func TemplateWithFuncs(funcs template.FuncMap) TemplateOption
TemplateWithFuncs add funcs to a template.