Skip to content

Commit c326b5d

Browse files
mwbrookszimeg
andauthored
feat: display manifest source in human-friendly format (#90)
* feat: display manifest source in human-readable format * test: fix failing tests * Update cmd/app/link.go Co-authored-by: Eden Zimbelman <[email protected]> * feat: handle unknown manifest source * feat: quote the human-friendly name --------- Co-authored-by: Eden Zimbelman <[email protected]>
1 parent 1129877 commit c326b5d

File tree

6 files changed

+51
-11
lines changed

6 files changed

+51
-11
lines changed

cmd/app/link.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,15 @@ func LinkExistingApp(ctx context.Context, clients *shared.ClientFactory, app *ty
173173
Emoji: "warning",
174174
Text: "Warning",
175175
Secondary: []string{
176-
"Existing apps have manifests configured by app settings",
177-
"Linking existing apps requires the manifest source to be " + config.ManifestSourceRemote.String(),
178-
fmt.Sprintf(`Manifest source can be "%s" or "%s"`, config.ManifestSourceLocal.String(), config.ManifestSourceRemote.String()),
176+
"Linking an existing app requires the app manifest source to be managed by",
177+
fmt.Sprintf("%s.", config.ManifestSourceRemote.Human()),
179178
" ",
180-
fmt.Sprintf(style.Highlight(`Your manifest source is "%s"`), manifestSource.String()),
179+
fmt.Sprintf(`App manifest source can be %s or %s:`, config.ManifestSourceLocal.Human(), config.ManifestSourceRemote.Human()),
181180
fmt.Sprintf("- %s: uses manifest from your project's source code for all apps", config.ManifestSourceLocal.String()),
182181
fmt.Sprintf("- %s: uses manifest from app settings for each app", config.ManifestSourceRemote.String()),
183182
" ",
183+
fmt.Sprintf(style.Highlight(`Your manifest source is set to %s.`), manifestSource.Human()),
184+
" ",
184185
fmt.Sprintf("Current manifest source in %s:", style.Highlight(filepath.Join(config.ProjectConfigDirName, config.ProjectConfigJSONFilename))),
185186
fmt.Sprintf(style.Highlight(` %s: "%s"`), "manifest.source", manifestSource.String()),
186187
" ",

cmd/project/init_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func Test_Project_InitCommand(t *testing.T) {
8080
require.Contains(t, output, "Added "+filepath.Join("project-name", ".slack"))
8181
require.Contains(t, output, "Added "+filepath.Join("project-name", ".slack", ".gitignore"))
8282
require.Contains(t, output, "Added "+filepath.Join("project-name", ".slack", "hooks.json"))
83-
require.Contains(t, output, "Updated config.json manifest source to local")
83+
require.Contains(t, output, `Updated config.json manifest source to "project" (local)`)
8484
// Assert prompt to add existing apps was called
8585
cm.IO.AssertCalled(
8686
t,

internal/config/manifest.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package config
1515

16+
import "fmt"
17+
1618
type ManifestSource string
1719

1820
const (
@@ -35,6 +37,17 @@ func (ms ManifestSource) String() string {
3537
return string(ms)
3638
}
3739

40+
// Human returns the string value as a human-friendly name
41+
func (ms ManifestSource) Human() string {
42+
switch ms {
43+
case ManifestSourceLocal:
44+
return fmt.Sprintf(`"project" (%s)`, ms.String())
45+
case ManifestSourceRemote:
46+
return fmt.Sprintf(`"app settings" (%s)`, ms.String())
47+
}
48+
return ms.String()
49+
}
50+
3851
type ManifestConfig struct {
3952
// Source of the manifest using either "local" or "remote" values
4053
Source string `json:"source,omitempty"`

internal/config/manifest_test.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ func Test_Config_ManifestSource_String(t *testing.T) {
8484
a ManifestSource
8585
expected string
8686
}{
87-
"project manifest source is local": {
87+
"local manifest source": {
8888
a: ManifestSourceLocal,
8989
expected: "local",
9090
},
91-
"remote manifest source is remote": {
91+
"remote manifest source": {
9292
a: ManifestSourceRemote,
9393
expected: "remote",
9494
},
@@ -100,3 +100,29 @@ func Test_Config_ManifestSource_String(t *testing.T) {
100100
})
101101
}
102102
}
103+
104+
func Test_Config_ManifestSource_Human(t *testing.T) {
105+
tests := map[string]struct {
106+
a ManifestSource
107+
expected string
108+
}{
109+
"local manifest source is the project (local)": {
110+
a: ManifestSourceLocal,
111+
expected: `"project" (local)`,
112+
},
113+
"remote manifest source is app settings (remote)": {
114+
a: ManifestSourceRemote,
115+
expected: `"app settings" (remote)`,
116+
},
117+
"unknown manifest source uses String()": {
118+
a: "unknown",
119+
expected: "unknown",
120+
},
121+
}
122+
for name, tt := range tests {
123+
t.Run(name, func(t *testing.T) {
124+
actual := tt.a.Human()
125+
assert.Equal(t, tt.expected, actual)
126+
})
127+
}
128+
}

internal/pkg/create/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ func InstallProjectDependencies(
466466
clients.IO.PrintDebug(ctx, "Error setting manifest source in project-level config: %s", err)
467467
} else {
468468
configJSONFilename := config.ProjectConfigJSONFilename
469-
manifestSourceStyled := style.Highlight(manifestSource.String())
469+
manifestSourceStyled := style.Highlight(manifestSource.Human())
470470

471471
outputs = append(outputs, fmt.Sprintf(
472472
"Updated %s manifest source to %s",

internal/pkg/create/create_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,17 @@ func Test_Create_installProjectDependencies(t *testing.T) {
195195
"Detected a project using Deno",
196196
},
197197
},
198-
"When no manifest source, default to local": {
198+
"When no manifest source, default to project (local)": {
199199
experiments: []string{"bolt"},
200200
expectedOutputs: []string{
201-
"Updated config.json manifest source to local",
201+
`Updated config.json manifest source to "project" (local)`,
202202
},
203203
},
204204
"When manifest source is provided, should set it": {
205205
experiments: []string{"bolt"},
206206
manifestSource: config.ManifestSourceRemote,
207207
expectedOutputs: []string{
208-
"Updated config.json manifest source to remote",
208+
`Updated config.json manifest source to "app settings" (remote)`,
209209
},
210210
},
211211
}

0 commit comments

Comments
 (0)