Skip to content

Commit af8e3f4

Browse files
committed
fix: pass original app name as display name instead of title-casing kebab
Addresses review feedback — instead of converting the kebab-case directory name to title case (which mangles names like "TIM" or "Translator - Translate Languages"), pass the original user-provided app name through to manifest display fields. This preserves the user's exact casing and formatting.
1 parent 7e47fee commit af8e3f4

3 files changed

Lines changed: 19 additions & 45 deletions

File tree

internal/app/app.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,12 @@ import (
1919
"fmt"
2020
"path/filepath"
2121
"regexp"
22-
"strings"
2322
"text/template"
2423

2524
"github.com/slackapi/slack-cli/internal/api"
2625
"github.com/slackapi/slack-cli/internal/config"
2726
"github.com/slackapi/slack-cli/internal/shared/types"
2827
"github.com/spf13/afero"
29-
"golang.org/x/text/cases"
30-
"golang.org/x/text/language"
3128
)
3229

3330
// Client to access the app/project
@@ -49,14 +46,8 @@ func NewClient(
4946
}
5047
}
5148

52-
func kebabToTitleCase(s string) string {
53-
return cases.Title(language.English).String(strings.ReplaceAll(s, "-", " "))
54-
}
55-
5649
// UpdateDefaultProjectFiles should update any project specific files if any
57-
func UpdateDefaultProjectFiles(fs afero.Fs, dirPath string, appDirName string) error {
58-
displayName := kebabToTitleCase(appDirName)
59-
50+
func UpdateDefaultProjectFiles(fs afero.Fs, dirPath string, appDirName string, displayName string) error {
6051
// Files and their corresponding app name replacement functions
6152
projectFiles := []struct {
6253
filename string

internal/app/app_test.go

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ import (
2828
func Test_App_UpdateDefaultProjectFiles(t *testing.T) {
2929
tests := map[string]struct {
3030
appDirName string
31+
displayName string
3132
existingFiles map[string]string
3233
expectedFiles map[string]string
3334
expectedErrorType error
3435
}{
3536
"manifest.json file exists": {
36-
appDirName: "vibrant-butterfly-1234",
37+
appDirName: "vibrant-butterfly-1234",
38+
displayName: "Vibrant Butterfly 1234",
3739
existingFiles: map[string]string{
3840
"manifest.json": string(testdata.ManifestJSON),
3941
},
@@ -43,7 +45,8 @@ func Test_App_UpdateDefaultProjectFiles(t *testing.T) {
4345
expectedErrorType: nil,
4446
},
4547
"manifest.js file exists": {
46-
appDirName: "vibrant-butterfly-1234",
48+
appDirName: "vibrant-butterfly-1234",
49+
displayName: "Vibrant Butterfly 1234",
4750
existingFiles: map[string]string{
4851
"manifest.js": string(testdata.ManifestJS),
4952
},
@@ -53,7 +56,8 @@ func Test_App_UpdateDefaultProjectFiles(t *testing.T) {
5356
expectedErrorType: nil,
5457
},
5558
"manifest.ts file exists": {
56-
appDirName: "vibrant-butterfly-1234",
59+
appDirName: "vibrant-butterfly-1234",
60+
displayName: "Vibrant Butterfly 1234",
5761
existingFiles: map[string]string{
5862
"manifest.ts": string(testdata.ManifestTS),
5963
},
@@ -63,7 +67,8 @@ func Test_App_UpdateDefaultProjectFiles(t *testing.T) {
6367
expectedErrorType: nil,
6468
},
6569
"Multiple manifest files exist": {
66-
appDirName: "vibrant-butterfly-1234",
70+
appDirName: "vibrant-butterfly-1234",
71+
displayName: "Vibrant Butterfly 1234",
6772
existingFiles: map[string]string{
6873
"manifest.json": string(testdata.ManifestJSON),
6974
"manifest.ts": string(testdata.ManifestTS),
@@ -75,7 +80,8 @@ func Test_App_UpdateDefaultProjectFiles(t *testing.T) {
7580
expectedErrorType: nil,
7681
},
7782
"package.json file exists": {
78-
appDirName: "vibrant-butterfly-1234",
83+
appDirName: "vibrant-butterfly-1234",
84+
displayName: "Vibrant Butterfly 1234",
7985
existingFiles: map[string]string{
8086
"package.json": string(testdata.PackageJSON),
8187
},
@@ -85,7 +91,8 @@ func Test_App_UpdateDefaultProjectFiles(t *testing.T) {
8591
expectedErrorType: nil,
8692
},
8793
"pyproject.toml file exists": {
88-
appDirName: "vibrant-butterfly-1234",
94+
appDirName: "vibrant-butterfly-1234",
95+
displayName: "Vibrant Butterfly 1234",
8996
existingFiles: map[string]string{
9097
"pyproject.toml": string(testdata.PyprojectTOML),
9198
},
@@ -95,7 +102,8 @@ func Test_App_UpdateDefaultProjectFiles(t *testing.T) {
95102
expectedErrorType: nil,
96103
},
97104
"Multiple project files exist": {
98-
appDirName: "vibrant-butterfly-1234",
105+
appDirName: "vibrant-butterfly-1234",
106+
displayName: "Vibrant Butterfly 1234",
99107
existingFiles: map[string]string{
100108
"manifest.json": string(testdata.ManifestJSON),
101109
"package.json": string(testdata.PackageJSON),
@@ -110,6 +118,7 @@ func Test_App_UpdateDefaultProjectFiles(t *testing.T) {
110118
},
111119
"No manifest files exist": {
112120
appDirName: "vibrant-butterfly-1234",
121+
displayName: "Vibrant Butterfly 1234",
113122
existingFiles: map[string]string{},
114123
expectedFiles: map[string]string{},
115124
expectedErrorType: nil,
@@ -136,7 +145,7 @@ func Test_App_UpdateDefaultProjectFiles(t *testing.T) {
136145
}
137146

138147
// Run the tests
139-
err := UpdateDefaultProjectFiles(fs, projectDirPath, tc.appDirName)
148+
err := UpdateDefaultProjectFiles(fs, projectDirPath, tc.appDirName, tc.displayName)
140149

141150
// Assertions
142151
require.IsType(t, err, tc.expectedErrorType)
@@ -151,32 +160,6 @@ func Test_App_UpdateDefaultProjectFiles(t *testing.T) {
151160
}
152161
}
153162

154-
func Test_kebabToTitleCase(t *testing.T) {
155-
tests := map[string]struct {
156-
input string
157-
expected string
158-
}{
159-
"multiple words": {
160-
input: "my-app",
161-
expected: "My App",
162-
},
163-
"multiple words with numbers": {
164-
input: "vibrant-butterfly-1234",
165-
expected: "Vibrant Butterfly 1234",
166-
},
167-
"single word": {
168-
input: "hello",
169-
expected: "Hello",
170-
},
171-
}
172-
for name, tc := range tests {
173-
t.Run(name, func(t *testing.T) {
174-
result := kebabToTitleCase(tc.input)
175-
require.Equal(t, tc.expected, result)
176-
})
177-
}
178-
}
179-
180163
func Test_RegexReplaceAppNameInManifest(t *testing.T) {
181164
tests := map[string]struct {
182165
src []byte

internal/pkg/create/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func Create(ctx context.Context, clients *shared.ClientFactory, createArgs Creat
150150
}()
151151

152152
// Update default project files' app name, bot name, etc
153-
if err := app.UpdateDefaultProjectFiles(clients.Fs, projectDirPath, appDirName); err != nil {
153+
if err := app.UpdateDefaultProjectFiles(clients.Fs, projectDirPath, appDirName, createArgs.AppName); err != nil {
154154
return "", slackerror.Wrap(err, slackerror.ErrProjectFileUpdate)
155155
}
156156

0 commit comments

Comments
 (0)