This commit is contained in:
nouney 2016-11-08 00:53:54 +01:00
parent ec2fe78599
commit 7fbe0bde7b
2 changed files with 16 additions and 3 deletions

View file

@ -78,8 +78,8 @@ import (
"github.com/spf13/cobra"
)
// {{.cmdName}}Cmd represents the {{.cmdName}} command
var {{ .cmdName }}Cmd = &cobra.Command{
// {{.cmdName|camelcase}}Cmd represents the {{.cmdName}} command
var {{ .cmdName|camelcase }}Cmd = &cobra.Command{
Use: "{{ .cmdName }}",
Short: "A brief description of your command",
Long: ` + "`" + `A longer description that spans multiple lines and likely contains examples
@ -95,7 +95,7 @@ to quickly create a Cobra application.` + "`" + `,
}
func init() {
{{ .parentName }}.AddCommand({{ .cmdName }}Cmd)
{{ .parentName }}.AddCommand({{ .cmdName|camelcase }}Cmd)
// Here you will define your flags and configuration settings.

View file

@ -22,6 +22,7 @@ import (
"strings"
"text/template"
"time"
"regexp"
"github.com/spf13/viper"
)
@ -43,6 +44,7 @@ var cmdDirs = []string{"cmd", "cmds", "command", "commands"}
func init() {
funcMap = template.FuncMap{
"comment": commentifyString,
"camelcase": camelCaseString,
}
}
@ -354,3 +356,14 @@ func commentifyString(in string) string {
}
return strings.Join(newlines, "\n")
}
func camelCaseString(in string) string {
r := regexp.MustCompile("[A-Za-z0-9_]+")
parts := r.FindAll([]byte(in), -1)
for i, v := range parts {
if i > 0 {
parts[i] = bytes.Title(v)
}
}
return string(bytes.Join(parts, nil))
}