Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 6 additions & 1 deletion cmd/project/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type promptObject struct {
Title string // "Reverse string"
Repository string // "slack-samples/reverse-string"
Description string // "A function that reverses a given string"
Subdir string // "agents/hello-world" - subdirectory within the repository
}

const viewMoreSamples = "slack-cli#view-more-samples"
Expand Down Expand Up @@ -158,11 +159,15 @@ func runCreateCommand(clients *shared.ClientFactory, cmd *cobra.Command, args []
}
}

subdir := createSubdirFlag
if subdir == "" {
subdir = template.GetSubdir()
}
createArgs := create.CreateArgs{
AppName: appNameArg,
Template: template,
GitBranch: createGitBranchFlag,
Subdir: createSubdirFlag,
Subdir: subdir,
}
clients.EventTracker.SetAppTemplate(template.GetTemplatePath())

Expand Down
56 changes: 33 additions & 23 deletions cmd/project/create_samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"sort"
"strings"

"github.com/slackapi/slack-cli/internal/experiment"
"github.com/slackapi/slack-cli/internal/iostreams"
"github.com/slackapi/slack-cli/internal/pkg/create"
"github.com/slackapi/slack-cli/internal/shared"
Expand All @@ -34,12 +35,24 @@ var embedPromptSamplesTmpl string
// promptSampleSelection gathers upstream samples to select from
func promptSampleSelection(ctx context.Context, clients *shared.ClientFactory, sampleRepos []create.GithubRepo) (string, error) {
filteredRepos := []create.GithubRepo{}
selection, err := clients.IO.SelectPrompt(ctx, "Select a language:",
[]string{
fmt.Sprintf("Bolt for JavaScript %s", style.Secondary("Node.js")),
fmt.Sprintf("Bolt for Python %s", style.Secondary("Python")),
fmt.Sprintf("Deno Slack SDK %s", style.Secondary("Deno")),
},
languageOptions := []string{
fmt.Sprintf("Bolt for JavaScript %s", style.Secondary("Node.js")),
fmt.Sprintf("Bolt for Python %s", style.Secondary("Python")),
fmt.Sprintf("Deno Slack SDK %s", style.Secondary("Deno")),
}
if clients.Config.WithExperimentOn(experiment.Templates) {
languageOptions = []string{
"Bolt for JavaScript",
"Bolt for Python",
"Deno Slack SDK",
}
}
Comment thread
zimeg marked this conversation as resolved.
Outdated
languagePrompt := "Select a language:"
if clients.Config.WithExperimentOn(experiment.Templates) {
languagePrompt = "Select a framework:"
}
Comment thread
zimeg marked this conversation as resolved.
Outdated
selection, err := clients.IO.SelectPrompt(ctx, languagePrompt,
languageOptions,
iostreams.SelectPromptConfig{
Flags: []*pflag.Flag{
clients.Config.Flags.Lookup("language"),
Expand All @@ -64,14 +77,26 @@ func promptSampleSelection(ctx context.Context, clients *shared.ClientFactory, s
}

sortedRepos := sortRepos(filteredRepos)
selectOptions := createSelectOptions(sortedRepos)
selectOptions := make([]string, len(sortedRepos))
for i, r := range sortedRepos {
if !clients.Config.WithExperimentOn(experiment.Charm) {
selectOptions[i] = fmt.Sprint(i+1, ". ", r.Name)
} else {
selectOptions[i] = r.Name
}
}
Comment thread
zimeg marked this conversation as resolved.

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 + "\n https://github.com/" + sortedRepos[index].FullName
desc := sortedRepos[index].Description
if !clients.Config.WithExperimentOn(experiment.Charm) {
desc += "\n https://github.com/" + sortedRepos[index].FullName
}
return desc
},
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,
Expand Down Expand Up @@ -127,18 +152,3 @@ func sortRepos(sampleRepos []create.GithubRepo) []create.GithubRepo {
})
return sortedRepos
}

// createSelectOptions takes in a list of repositories
// and returns an array of strings, each value being
// equal to the repository name (ie, deno-starter-template)
// and prepended with a number for a prompt visual aid
func createSelectOptions(filteredRepos []create.GithubRepo) []string {
// Create a slice of repository names to use as
// the primary item selection in the prompt
selectOptions := make([]string, 0)
for i, f := range filteredRepos {
selectOption := fmt.Sprint(i+1, ". ", f.Name)
selectOptions = append(selectOptions, selectOption)
}
return selectOptions
}
6 changes: 0 additions & 6 deletions cmd/project/create_samples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,3 @@ func TestSamples_SortRepos(t *testing.T) {
assert.Equal(t, sortedRepos[3].StargazersCount, 0, "Expected sortedRepos[3].StargazersCount to equal 0")
assert.Equal(t, sortedRepos[3].Description, "This is a new sample")
}

func TestSamples_CreateSelectOptions(t *testing.T) {
selectOptions := createSelectOptions(mockGitHubRepos)
assert.Equal(t, len(selectOptions), 4, "Expected selectOptions length to be 4")
assert.Contains(t, selectOptions[0], mockGitHubRepos[0].Name, "Expected selectOptions[0] to contain mockGitHubRepos[0].Name")
}
Loading
Loading