Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions cmd/project/create_samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func promptSampleSelection(ctx context.Context, clients *shared.ClientFactory, s
iostreams.SelectPromptConfig{
Flags: []*pflag.Flag{
clients.Config.Flags.Lookup("language"),
clients.Config.Flags.Lookup("template"), // Skip filtering with a template
},
Required: false,
},
Expand All @@ -69,25 +68,19 @@ func promptSampleSelection(ctx context.Context, clients *shared.ClientFactory, s
selectOptions[i] = r.Name
}

var selectedTemplate string
selection, err = clients.IO.SelectPrompt(ctx, "Select a sample to build upon:", selectOptions, iostreams.SelectPromptConfig{
Description: func(value string, index int) string {
return sortedRepos[index].Description
},
Flag: clients.Config.Flags.Lookup("template"),
Help: fmt.Sprintf("Guided tutorials can be found at %s", style.LinkText("https://docs.slack.dev/samples")),
PageSize: 4, // Supports standard terminal height (24 rows)
Required: true,
Template: embedPromptSamplesTmpl,
})
if err != nil {
return "", err
} else if selection.Flag {
selectedTemplate = selection.Option
} else if selection.Prompt {
selectedTemplate = sortedRepos[selection.Index].FullName
}
return selectedTemplate, nil
return sortedRepos[selection.Index].FullName, nil
}

// filterRepos returns a list of samples matching the provided project type
Expand Down
21 changes: 1 addition & 20 deletions cmd/project/samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ import (
)

// Flags
var samplesTemplateURLFlag string
var samplesGitBranchFlag string
var samplesListFlag bool
var samplesLanguageFlag string

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

// DEPRECATED(semver:major): Prefer the create command when repository details are known
cmd.Flags().StringVarP(&samplesGitBranchFlag, "branch", "b", "", "name of git branch to checkout")
cmd.Flag("branch").Hidden = true
// DEPRECATED(semver:major): Prefer the create command when repository details are known
cmd.Flags().StringVarP(&samplesTemplateURLFlag, "template", "t", "", "template URL for your app")
cmd.Flag("template").Hidden = true

cmd.Flags().StringVar(&samplesLanguageFlag, "language", "", "runtime for the app framework\n ex: \"deno\", \"node\", \"python\"")
cmd.Flags().BoolVar(&samplesListFlag, "list", false, "prints samples without interactivity")

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

// DEPRECATED(semver:major): Prefer the create command when repository details are known
if cmd.Flag("branch").Changed || cmd.Flag("template").Changed {
clients.IO.PrintWarning(ctx, "DEPRECATED: The `--branch` and `--template` flags are deprecated for the `samples` command; use the `create` command instead")
}

sampler := api.NewHTTPClient(api.HTTPClientOptions{
TotalTimeOut: 60 * time.Second,
})
Expand All @@ -100,16 +86,11 @@ func runSamplesCommand(clients *shared.ClientFactory, cmd *cobra.Command, args [
// Instantiate the `create` command to call it using programmatically set flags
createCmd := NewCreateCommand(clients)

// Prepare template and branch flags with selected or provided repo values
// Prepare the template flag with the selected repo value
if err := createCmd.Flag("template").Value.Set(selectedSample); err != nil {
return err
}
createCmd.Flag("template").Changed = true
if err := createCmd.Flag("branch").Value.Set(samplesGitBranchFlag); err != nil {
return err
}
createCmd.Flag("branch").Changed = cmd.Flag("branch").Changed

// If preferred directory name is passed in as an argument to the `create`
// command first, honor that preference and use it to create the project
createCmd.SetArgs(args)
Expand Down
21 changes: 4 additions & 17 deletions cmd/project/samples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import (
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)

func TestSamplesCommand(t *testing.T) {
var capturedArgs createPkg.CreateArgs
testutil.TableTestCommand(t, testutil.CommandTests{
"creates a template from a trusted sample": {
CmdArgs: []string{"my-sample-app"},
Expand Down Expand Up @@ -72,29 +72,16 @@ func TestSamplesCommand(t *testing.T) {
nil,
)
CreateFunc = func(ctx context.Context, clients *shared.ClientFactory, createArgs createPkg.CreateArgs) (appDirPath string, err error) {
capturedArgs = createArgs
return createArgs.AppName, nil
}
},
ExpectedOutputs: []string{
"cd my-sample-app/",
},
ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) {
for _, call := range cm.IO.Calls {
switch call.Method {
case "SelectPrompt":
args := call.Arguments
opts := args.Get(3).(iostreams.SelectPromptConfig)
flag := opts.Flag
switch args.String(1) {
case "Select a sample to build upon:":
require.Equal(t, "template", flag.Name)
assert.Equal(t, "", flag.Value.String())
case "Select a template to build from:":
require.Equal(t, "template", flag.Name)
assert.Equal(t, "slack-samples/deno-starter-template", flag.Value.String())
}
}
}
assert.Equal(t, "my-sample-app", capturedArgs.AppName)
assert.Equal(t, "slack-samples/deno-starter-template", capturedArgs.Template.GetTemplatePath())
},
},
"lists available samples matching a language": {
Expand Down
Loading