Skip to content

Commit

Permalink
Merge pull request #286 from carapace-sh/codegen-normalize-colon
Browse files Browse the repository at this point in the history
codegen: skip colon on normalize
  • Loading branch information
rsteube authored Jul 27, 2024
2 parents 5a29172 + 86d81fa commit 8e045fa
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 8e045fa

Please sign in to comment.