Skip to content

Commit 83541ca

Browse files
fix: bash arg with custom initialisms
1 parent 4346a82 commit 83541ca

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

strcase/bash_arg.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import "strings"
55
// ToBashArg returns the Bash public name of the given string
66
func ToBashArg(s string) string {
77
s = ToPublicGoName(s)
8-
s = strings.ReplaceAll(s, "IPv", "Ipv")
8+
for _, initialism := range customInitialisms {
9+
// catch this kind of pattern: ExampleIDs ==> ExampleIds ==> example-ids
10+
s = strings.Replace(s, initialism[0], strings.Title(strings.ToLower(initialism[0])), -1)
11+
}
912
return toKebab(s)
1013
}
1114

strcase/goname.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ func ToPrivateGoName(s string) string {
1717

1818
// toGoName returns a different name if it should be different.
1919
func toGoName(name string) (should string) {
20-
name = strings.ReplaceAll(name, " ", "_")
21-
name = strings.ReplaceAll(name, "-", "_")
20+
name = strings.Replace(name, " ", "_", -1)
21+
name = strings.Replace(name, "-", "_", -1)
2222

2323
// Fast path for simple cases: "_" and all lowercase.
2424
if name == "_" {

0 commit comments

Comments
 (0)