Skip to content

Commit c56ad55

Browse files
authored
chore!: remove deprecated --branch and --template flags from samples command (#466)
1 parent 2927885 commit c56ad55

File tree

3 files changed

+6
-45
lines changed

3 files changed

+6
-45
lines changed

cmd/project/create_samples.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ func promptSampleSelection(ctx context.Context, clients *shared.ClientFactory, s
4343
iostreams.SelectPromptConfig{
4444
Flags: []*pflag.Flag{
4545
clients.Config.Flags.Lookup("language"),
46-
clients.Config.Flags.Lookup("template"), // Skip filtering with a template
4746
},
4847
Required: false,
4948
},
@@ -69,25 +68,19 @@ func promptSampleSelection(ctx context.Context, clients *shared.ClientFactory, s
6968
selectOptions[i] = r.Name
7069
}
7170

72-
var selectedTemplate string
7371
selection, err = clients.IO.SelectPrompt(ctx, "Select a sample to build upon:", selectOptions, iostreams.SelectPromptConfig{
7472
Description: func(value string, index int) string {
7573
return sortedRepos[index].Description
7674
},
77-
Flag: clients.Config.Flags.Lookup("template"),
7875
Help: fmt.Sprintf("Guided tutorials can be found at %s", style.LinkText("https://docs.slack.dev/samples")),
7976
PageSize: 4, // Supports standard terminal height (24 rows)
8077
Required: true,
8178
Template: embedPromptSamplesTmpl,
8279
})
8380
if err != nil {
8481
return "", err
85-
} else if selection.Flag {
86-
selectedTemplate = selection.Option
87-
} else if selection.Prompt {
88-
selectedTemplate = sortedRepos[selection.Index].FullName
8982
}
90-
return selectedTemplate, nil
83+
return sortedRepos[selection.Index].FullName, nil
9184
}
9285

9386
// filterRepos returns a list of samples matching the provided project type

cmd/project/samples.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ import (
2828
)
2929

3030
// Flags
31-
var samplesTemplateURLFlag string
32-
var samplesGitBranchFlag string
3331
var samplesListFlag bool
3432
var samplesLanguageFlag string
3533

@@ -56,13 +54,6 @@ func NewSamplesCommand(clients *shared.ClientFactory) *cobra.Command {
5654
},
5755
}
5856

59-
// DEPRECATED(semver:major): Prefer the create command when repository details are known
60-
cmd.Flags().StringVarP(&samplesGitBranchFlag, "branch", "b", "", "name of git branch to checkout")
61-
cmd.Flag("branch").Hidden = true
62-
// DEPRECATED(semver:major): Prefer the create command when repository details are known
63-
cmd.Flags().StringVarP(&samplesTemplateURLFlag, "template", "t", "", "template URL for your app")
64-
cmd.Flag("template").Hidden = true
65-
6657
cmd.Flags().StringVar(&samplesLanguageFlag, "language", "", "runtime for the app framework\n ex: \"deno\", \"node\", \"python\"")
6758
cmd.Flags().BoolVar(&samplesListFlag, "list", false, "prints samples without interactivity")
6859

@@ -73,11 +64,6 @@ func NewSamplesCommand(clients *shared.ClientFactory) *cobra.Command {
7364
func runSamplesCommand(clients *shared.ClientFactory, cmd *cobra.Command, args []string) error {
7465
ctx := cmd.Context()
7566

76-
// DEPRECATED(semver:major): Prefer the create command when repository details are known
77-
if cmd.Flag("branch").Changed || cmd.Flag("template").Changed {
78-
clients.IO.PrintWarning(ctx, "DEPRECATED: The `--branch` and `--template` flags are deprecated for the `samples` command; use the `create` command instead")
79-
}
80-
8167
sampler := api.NewHTTPClient(api.HTTPClientOptions{
8268
TotalTimeOut: 60 * time.Second,
8369
})
@@ -100,16 +86,11 @@ func runSamplesCommand(clients *shared.ClientFactory, cmd *cobra.Command, args [
10086
// Instantiate the `create` command to call it using programmatically set flags
10187
createCmd := NewCreateCommand(clients)
10288

103-
// Prepare template and branch flags with selected or provided repo values
89+
// Prepare the template flag with the selected repo value
10490
if err := createCmd.Flag("template").Value.Set(selectedSample); err != nil {
10591
return err
10692
}
10793
createCmd.Flag("template").Changed = true
108-
if err := createCmd.Flag("branch").Value.Set(samplesGitBranchFlag); err != nil {
109-
return err
110-
}
111-
createCmd.Flag("branch").Changed = cmd.Flag("branch").Changed
112-
11394
// If preferred directory name is passed in as an argument to the `create`
11495
// command first, honor that preference and use it to create the project
11596
createCmd.SetArgs(args)

cmd/project/samples_test.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import (
2525
"github.com/spf13/cobra"
2626
"github.com/stretchr/testify/assert"
2727
"github.com/stretchr/testify/mock"
28-
"github.com/stretchr/testify/require"
2928
)
3029

3130
func TestSamplesCommand(t *testing.T) {
31+
var capturedArgs createPkg.CreateArgs
3232
testutil.TableTestCommand(t, testutil.CommandTests{
3333
"creates a template from a trusted sample": {
3434
CmdArgs: []string{"my-sample-app"},
@@ -72,29 +72,16 @@ func TestSamplesCommand(t *testing.T) {
7272
nil,
7373
)
7474
CreateFunc = func(ctx context.Context, clients *shared.ClientFactory, createArgs createPkg.CreateArgs) (appDirPath string, err error) {
75+
capturedArgs = createArgs
7576
return createArgs.AppName, nil
7677
}
7778
},
7879
ExpectedOutputs: []string{
7980
"cd my-sample-app/",
8081
},
8182
ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) {
82-
for _, call := range cm.IO.Calls {
83-
switch call.Method {
84-
case "SelectPrompt":
85-
args := call.Arguments
86-
opts := args.Get(3).(iostreams.SelectPromptConfig)
87-
flag := opts.Flag
88-
switch args.String(1) {
89-
case "Select a sample to build upon:":
90-
require.Equal(t, "template", flag.Name)
91-
assert.Equal(t, "", flag.Value.String())
92-
case "Select a template to build from:":
93-
require.Equal(t, "template", flag.Name)
94-
assert.Equal(t, "slack-samples/deno-starter-template", flag.Value.String())
95-
}
96-
}
97-
}
83+
assert.Equal(t, "my-sample-app", capturedArgs.AppName)
84+
assert.Equal(t, "slack-samples/deno-starter-template", capturedArgs.Template.GetTemplatePath())
9885
},
9986
},
10087
"lists available samples matching a language": {

0 commit comments

Comments
 (0)