skeletonkit

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: MIT Imports: 15 Imported by: 2

README

skeletonkit

pkg.go.dev

skeletonkit is a library for skeleton codes generator such as gostaticanalysis/skeleton.

Documentation

Index

Constants

View Source
const (
	Cancel overwritePolicy
	ForceOverwrite
	Confirm
	NewOnly
)

Variables

View Source
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.

View Source
var DefaultPrompt = &Prompt{
	Input:     os.Stdin,
	Output:    os.Stdout,
	ErrOutput: os.Stderr,
}

DefaultPrompt is default Prompt.

Functions

func CreateDir

func CreateDir(prompt *Prompt, root string, fsys fs.FS, options ...CreatorOption) error

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

func ExecuteTemplate(tmpl *template.Template, data interface{}) (fs.FS, error)

ExecuteTemplate executes a template with data. ExecuteTemplate also parses the excuted string as a txtar format and return it as a file system.

func ModInit

func ModInit(path string) (string, error)

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

type Prompt struct {
	Input     io.Reader
	Output    io.Writer
	ErrOutput io.Writer
}

Prompt receive input from a user.

func (*Prompt) Choose

func (p *Prompt) Choose(description string, opts []string, prompt string) (int, error)

Choose shows options and user would select a option from these options. Choose returns index of the selected option.

func (*Prompt) YesNo

func (p *Prompt) YesNo(description string, defaultVal bool, prompt rune) (bool, error)

type TemplateOption added in v0.2.0

type TemplateOption func(*template.Template) (*template.Template, error)

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.

Jump to

Keyboard shortcuts

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