Skip to content

Commit 4d50c44

Browse files
authored
fix: gather manifest info from the configured source after parsing flags (#113)
* fix: gather manifest info from the configured source after parsing flags * fix: remove the default flag value from the manifest info command
1 parent e43e865 commit 4d50c44

File tree

3 files changed

+52
-51
lines changed

3 files changed

+52
-51
lines changed

cmd/manifest/info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func NewInfoCommand(clients *shared.ClientFactory) *cobra.Command {
7373
cmd.Flags().StringVar(
7474
&manifestFlags.source,
7575
manifestFlagSource,
76-
config.ManifestSourceLocal.String(),
76+
"",
7777
fmt.Sprintf(
7878
"source of the app manifest (\"%s\" or \"%s\")",
7979
config.ManifestSourceLocal.String(),

cmd/manifest/info_test.go

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,15 @@ package manifest
1717
import (
1818
"context"
1919
"encoding/json"
20-
"fmt"
21-
"path/filepath"
22-
"strings"
2320
"testing"
2421

2522
"github.com/slackapi/slack-cli/internal/app"
2623
"github.com/slackapi/slack-cli/internal/config"
27-
"github.com/slackapi/slack-cli/internal/experiment"
2824
"github.com/slackapi/slack-cli/internal/hooks"
2925
"github.com/slackapi/slack-cli/internal/prompts"
3026
"github.com/slackapi/slack-cli/internal/shared"
3127
"github.com/slackapi/slack-cli/internal/shared/types"
3228
"github.com/slackapi/slack-cli/internal/slackerror"
33-
"github.com/slackapi/slack-cli/internal/style"
3429
"github.com/slackapi/slack-cli/test/testutil"
3530
"github.com/spf13/cobra"
3631
"github.com/stretchr/testify/assert"
@@ -113,7 +108,7 @@ func TestInfoCommand(t *testing.T) {
113108
assert.Equal(t, string(manifest)+"\n", cm.GetStdoutOutput())
114109
},
115110
},
116-
"gathers manifest.source from project configurations with the bolt experiment": {
111+
"gathers manifest.source local from project configurations": {
117112
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
118113
appSelectMock := prompts.NewAppSelectMock()
119114
appSelectPromptFunc = appSelectMock.AppSelectPrompt
@@ -133,8 +128,6 @@ func TestInfoCommand(t *testing.T) {
133128
},
134129
}, nil)
135130
cf.AppClient().Manifest = manifestMock
136-
cm.Config.ExperimentsFlag = append(cm.Config.ExperimentsFlag, string(experiment.BoltFrameworks))
137-
cm.Config.LoadExperiments(ctx, cm.IO.PrintDebug)
138131
mockProjectConfig := config.NewProjectConfigMock()
139132
mockProjectConfig.On("GetManifestSource", mock.Anything).Return(config.ManifestSourceLocal, nil)
140133
cm.Config.ProjectConfig = mockProjectConfig
@@ -150,24 +143,40 @@ func TestInfoCommand(t *testing.T) {
150143
assert.Equal(t, string(manifest)+"\n", cm.GetStdoutOutput())
151144
},
152145
},
153-
"errors if project manifest source is remote with the bolt experiment": {
154-
ExpectedError: slackerror.New(slackerror.ErrInvalidManifestSource).
155-
WithMessage(`Cannot get manifest info from the "%s" source`, config.ManifestSourceRemote).
156-
WithRemediation("%s", strings.Join([]string{
157-
fmt.Sprintf("Find the current manifest on app settings: %s", style.LinkText("https://api.slack.com/apps")),
158-
fmt.Sprintf("Set \"manifest.source\" to \"%s\" in \"%s\" to continue", config.ManifestSourceLocal, filepath.Join(".slack", "config.json")),
159-
fmt.Sprintf("Read about manifest sourcing with %s", style.Commandf("manifest info --help", false)),
160-
}, "\n")),
146+
"gathers manifest.source remote from project configurations": {
161147
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
162148
cf.SDKConfig.WorkingDirectory = "."
163149
cm.IO.AddDefaultMocks()
164150
cm.Os.AddDefaultMocks()
165-
cm.Config.ExperimentsFlag = append(cm.Config.ExperimentsFlag, string(experiment.BoltFrameworks))
166-
cm.Config.LoadExperiments(ctx, cm.IO.PrintDebug)
167151
mockProjectConfig := config.NewProjectConfigMock()
168152
mockProjectConfig.On("GetManifestSource", mock.Anything).
169153
Return(config.ManifestSource(config.ManifestSourceRemote), nil)
170154
cm.Config.ProjectConfig = mockProjectConfig
155+
manifestMock := &app.ManifestMockObject{}
156+
manifestMock.On("GetManifestRemote", mock.Anything, mock.Anything, mock.Anything).Return(types.SlackYaml{
157+
AppManifest: types.AppManifest{
158+
DisplayInformation: types.DisplayInformation{
159+
Name: "app005",
160+
},
161+
},
162+
}, nil)
163+
cf.AppClient().Manifest = manifestMock
164+
appSelectMock := prompts.NewAppSelectMock()
165+
appSelectPromptFunc = appSelectMock.AppSelectPrompt
166+
appSelectMock.On("AppSelectPrompt").Return(prompts.SelectedApp{
167+
App: types.App{AppID: "A005"},
168+
Auth: types.SlackAuth{Token: "xapp-example-005"},
169+
}, nil)
170+
},
171+
ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) {
172+
mockManifest := types.AppManifest{
173+
DisplayInformation: types.DisplayInformation{
174+
Name: "app005",
175+
},
176+
}
177+
manifest, err := json.MarshalIndent(mockManifest, "", " ")
178+
require.NoError(t, err)
179+
assert.Equal(t, string(manifest)+"\n", cm.GetStdoutOutput())
171180
},
172181
},
173182
}, func(clients *shared.ClientFactory) *cobra.Command {

cmd/manifest/manifest.go

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ package manifest
1717
import (
1818
"context"
1919
"fmt"
20-
"path/filepath"
2120
"strings"
2221

2322
"github.com/slackapi/slack-cli/internal/cmdutil"
2423
"github.com/slackapi/slack-cli/internal/config"
25-
"github.com/slackapi/slack-cli/internal/experiment"
2624
"github.com/slackapi/slack-cli/internal/prompts"
2725
"github.com/slackapi/slack-cli/internal/shared"
2826
"github.com/slackapi/slack-cli/internal/slackerror"
@@ -86,7 +84,7 @@ func NewCommand(clients *shared.ClientFactory) *cobra.Command {
8684
cmd.Flags().StringVar(
8785
&manifestFlags.source,
8886
manifestFlagSource,
89-
config.ManifestSourceLocal.String(),
87+
"",
9088
fmt.Sprintf(
9189
"source of the app manifest (\"%s\" or \"%s\")",
9290
config.ManifestSourceLocal.String(),
@@ -111,38 +109,32 @@ func getManifestSource(ctx context.Context, clients *shared.ClientFactory, cmd *
111109
}
112110
return config.ManifestSourceRemote, nil
113111
}
114-
if clients.Config.WithExperimentOn(experiment.BoltFrameworks) {
115-
if !cmd.Flag(manifestFlagSource).Changed {
116-
manifestConfigSource, err := clients.Config.ProjectConfig.GetManifestSource(ctx)
117-
if err != nil {
118-
return "", err
119-
}
120-
switch {
121-
case manifestConfigSource.Equals(config.ManifestSourceLocal):
122-
return manifestConfigSource, nil
123-
case manifestConfigSource.Equals(config.ManifestSourceRemote):
124-
return "", slackerror.New(slackerror.ErrInvalidManifestSource).
125-
WithMessage(`Cannot get manifest info from the "%s" source`, config.ManifestSourceRemote).
126-
WithRemediation("%s", strings.Join([]string{
127-
fmt.Sprintf("Find the current manifest on app settings: %s", style.LinkText("https://api.slack.com/apps")),
128-
fmt.Sprintf("Set \"manifest.source\" to \"%s\" in \"%s\" to continue", config.ManifestSourceLocal, filepath.Join(".slack", "config.json")),
129-
fmt.Sprintf("Read about manifest sourcing with %s", style.Commandf("manifest info --help", false)),
130-
}, "\n"))
131-
}
112+
if cmd.Flag(manifestFlagSource).Changed {
113+
switch {
114+
case config.ManifestSource(manifestFlags.source).Equals(config.ManifestSourceLocal):
115+
return config.ManifestSourceLocal, nil
116+
case config.ManifestSource(manifestFlags.source).Equals(config.ManifestSourceRemote):
117+
return config.ManifestSourceRemote, nil
118+
default:
119+
return "", slackerror.New(slackerror.ErrInvalidFlag).
120+
WithMessage(
121+
"The \"--%s\" flag must be \"%s\" or \"%s\"",
122+
manifestFlagSource,
123+
config.ManifestSourceLocal,
124+
config.ManifestSourceRemote,
125+
)
132126
}
133127
}
128+
manifestConfigSource, err := clients.Config.ProjectConfig.GetManifestSource(ctx)
129+
if err != nil {
130+
return "", err
131+
}
134132
switch {
135-
case config.ManifestSource(manifestFlags.source).Equals(config.ManifestSourceLocal):
136-
return config.ManifestSourceLocal, nil
137-
case config.ManifestSource(manifestFlags.source).Equals(config.ManifestSourceRemote):
138-
return config.ManifestSourceRemote, nil
133+
case manifestConfigSource.Equals(config.ManifestSourceLocal):
134+
return manifestConfigSource, nil
135+
case manifestConfigSource.Equals(config.ManifestSourceRemote):
136+
return manifestConfigSource, nil
139137
default:
140-
return "", slackerror.New(slackerror.ErrInvalidFlag).
141-
WithMessage(
142-
"The \"--%s\" flag must be \"%s\" or \"%s\"",
143-
manifestFlagSource,
144-
config.ManifestSourceLocal,
145-
config.ManifestSourceRemote,
146-
)
138+
return "", slackerror.New(slackerror.ErrInvalidManifestSource)
147139
}
148140
}

0 commit comments

Comments
 (0)