mirror of
https://github.com/spf13/cobra
synced 2024-11-24 22:57:12 +00:00
Fix #269
This commit is contained in:
parent
ec2fe78599
commit
7fbe0bde7b
2 changed files with 16 additions and 3 deletions
|
@ -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.
|
||||
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue