Skip to content

Commit

Permalink
codegen: skip colon on normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jul 27, 2024
1 parent 5a29172 commit 86d81fa
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,22 @@ func cmdVarName(cmd *cobra.Command) string {
if !cmd.HasParent() {
return "root"
}
return strings.TrimPrefix(fmt.Sprintf(`%v_%v`, cmdVarName(cmd.Parent()), normaliceVarName(cmd.Name())), "root_")
return strings.TrimPrefix(fmt.Sprintf(`%v_%v`, cmdVarName(cmd.Parent()), normalizeVarName(cmd.Name())), "root_")
}

func normaliceVarName(s string) string {
func normalizeVarName(s string) string {
normalized := make([]string, 0)
capitalize := false

for _, c := range s {
if c == '-' {
switch {
case c == '-' || c == ':':
capitalize = true
continue
} else if capitalize {
case capitalize:
normalized = append(normalized, strings.ToUpper(string(c)))
capitalize = false
} else {
default:
normalized = append(normalized, string(c))
}
}
Expand Down

0 comments on commit 86d81fa

Please sign in to comment.