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"
|
"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.
|
||||||
|
|
||||||
|
|
|
@ -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))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue