diff --git a/commands/template.go b/commands/template.go index 7e657ad..2387b40 100644 --- a/commands/template.go +++ b/commands/template.go @@ -14,7 +14,7 @@ import ( logy "github.com/apex/log" "github.com/briandowns/spinner" "github.com/netzkern/butler/config" - "github.com/netzkern/butler/util" + "github.com/pinzolo/casee" survey "gopkg.in/AlecAivazis/survey.v1" git "gopkg.in/src-d/go-git.v4" ) @@ -128,7 +128,7 @@ func (t *Templating) prompts() (*ProjectData, error) { return nil, err } - project.Name = util.NormalizeProjectName(project.Name) + project.Name = casee.ToPascalCase(project.Name) return project, nil } @@ -214,8 +214,15 @@ func (t *Templating) Run() error { var b bytes.Buffer - tmpl, err := template.New(path).Delims(startDelim, endDelim).Parse(string(dat)) - tmplPath, err := template.New(path).Delims(startDelim, endDelim).Parse(path) + utilFuncMap := template.FuncMap{ + "toCamelCase": casee.ToCamelCase, + "toPascalCase": casee.ToPascalCase, + "toSnakeCase": casee.ToSnakeCase, + } + + tmpl, err := template.New(path).Delims(startDelim, endDelim).Funcs(utilFuncMap).Parse(string(dat)) + + tmplPath, err := template.New(path).Delims(startDelim, endDelim).Funcs(utilFuncMap).Parse(path) err = tmplPath.Execute(&b, templateData) diff --git a/util/util.go b/util/util.go deleted file mode 100644 index 41e3c36..0000000 --- a/util/util.go +++ /dev/null @@ -1,14 +0,0 @@ -package util - -import ( - "log" - "regexp" -) - -func NormalizeProjectName(example string) string { - reg, err := regexp.Compile("[^a-zA-Z0-9-]+") - if err != nil { - log.Fatal(err) - } - return reg.ReplaceAllString(example, "") -}