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

View file

@ -22,6 +22,7 @@ import (
"strings" "strings"
"text/template" "text/template"
"time" "time"
"regexp"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
@ -43,6 +44,7 @@ var cmdDirs = []string{"cmd", "cmds", "command", "commands"}
func init() { func init() {
funcMap = template.FuncMap{ funcMap = template.FuncMap{
"comment": commentifyString, "comment": commentifyString,
"camelcase": camelCaseString,
} }
} }
@ -354,3 +356,14 @@ func commentifyString(in string) string {
} }
return strings.Join(newlines, "\n") 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))
}