Skip to content
Merged
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
1 change: 1 addition & 0 deletions cmd/feedback/feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ func chooseSurveyPrompt(ctx context.Context, clients *shared.ClientFactory, surv
selection, err := clients.IO.SelectPrompt(ctx, msg, surveyPromptOptions,
iostreams.SelectPromptConfig{
Flag: clients.Config.Flags.Lookup("name"),
Required: true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 The required option defaulting to false will cause this prompt to skip from the changes below!

PageSize: 4,
Description: func(value string, index int) string {
if index < len(surveyNames) {
Expand Down
52 changes: 49 additions & 3 deletions cmd/project/create_samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/slackapi/slack-cli/internal/iostreams"
"github.com/slackapi/slack-cli/internal/pkg/create"
"github.com/slackapi/slack-cli/internal/shared"
"github.com/slackapi/slack-cli/internal/style"
"github.com/spf13/pflag"
)

//go:embed samples.tmpl
Expand All @@ -36,13 +38,57 @@ func PromptSampleSelection(ctx context.Context, clients *shared.ClientFactory, s
return "", err
}

projectType := "deno"
filteredRepos := filterRepos(sampleRepos, projectType)
projectTypes := []string{}
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")),
},
Comment on lines +44 to +47
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Great consideration for detail by choosing to match the styling of the create command! 🎨

iostreams.SelectPromptConfig{
Flags: []*pflag.Flag{
clients.Config.Flags.Lookup("language"),
clients.Config.Flags.Lookup("template"), // Skip filtering with a template
},
Required: false,
},
)
if err != nil {
return "", err
} else if selection.Prompt {
switch selection.Index {
case 0:
projectTypes = []string{"bolt-js", "bolt-ts"}
case 1:
projectTypes = []string{"bolt-python"}
case 2:
projectTypes = []string{"deno"}
}
} else if selection.Flag {
switch strings.ToLower(strings.TrimSpace(selection.Option)) {
case "node":
projectTypes = []string{"bolt-js", "bolt-ts"}
case "python":
projectTypes = []string{"bolt-python"}
case "deno":
projectTypes = []string{"deno"}
default:
projectTypes = []string{selection.Option}
}
}

filteredRepos := []create.GithubRepo{}
if len(projectTypes) <= 0 {
filteredRepos = sampleRepos
}
for _, language := range projectTypes {
filteredRepos = append(filteredRepos, filterRepos(sampleRepos, language)...)
}
sortedRepos := sortRepos(filteredRepos)
selectOptions := createSelectOptions(sortedRepos)

var selectedTemplate string
selection, err := clients.IO.SelectPrompt(ctx, "Select a sample to build upon:", selectOptions, iostreams.SelectPromptConfig{
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
},
Expand Down
10 changes: 10 additions & 0 deletions cmd/project/create_samples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ func TestSamples_PromptSampleSelection(t *testing.T) {
res := w.Result()
sampler.On("Do", mock.Anything).Return(res, nil)
clientsMock := shared.NewClientsMock()
clientsMock.IO.On(
"SelectPrompt",
mock.Anything,
"Select a language:",
mock.Anything,
mock.Anything,
).Return(iostreams.SelectPromptResponse{
Index: 2,
Prompt: true,
}, nil)
clientsMock.IO.On(
"SelectPrompt",
mock.Anything,
Expand Down
2 changes: 2 additions & 0 deletions cmd/project/samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
// Flags
var samplesTemplateURLFlag string
var samplesGitBranchFlag string
var samplesLanguageFlag string

func NewSamplesCommand(clients *shared.ClientFactory) *cobra.Command {
cmd := &cobra.Command{
Expand All @@ -45,6 +46,7 @@ func NewSamplesCommand(clients *shared.ClientFactory) *cobra.Command {

cmd.Flags().StringVarP(&samplesTemplateURLFlag, "template", "t", "", "template URL for your app")
cmd.Flags().StringVarP(&samplesGitBranchFlag, "branch", "b", "", "name of git branch to checkout")
cmd.Flags().StringVar(&samplesLanguageFlag, "language", "", "runtime for the app framework\n ex: \"deno\", \"node\", \"python\"")

return cmd
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/project/samples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ func TestSamplesCommand(t *testing.T) {
}
return repos, nil
}
cm.IO.On("SelectPrompt", mock.Anything, "Select a language:", mock.Anything, mock.Anything).
Return(
iostreams.SelectPromptResponse{
Index: 2,
Prompt: true,
},
nil,
)
cm.IO.On("SelectPrompt", mock.Anything, "Select a sample to build upon:", mock.Anything, mock.Anything).
Return(
iostreams.SelectPromptResponse{
Expand Down
9 changes: 8 additions & 1 deletion internal/iostreams/survey.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,11 @@ func (io *IOStreams) SelectPrompt(ctx context.Context, msg string, options []str
return SelectPromptResponse{}, slackerror.New(slackerror.ErrMissingOptions)
}
if !io.IsTTY() {
return SelectPromptResponse{}, errInteractivityFlags(cfg)
if cfg.IsRequired() {
return SelectPromptResponse{}, errInteractivityFlags(cfg)
} else {
return SelectPromptResponse{}, nil
}
}

defaultSelectTemplate := survey.SelectQuestionTemplate
Expand Down Expand Up @@ -491,6 +495,9 @@ func (io *IOStreams) retrieveFlagValue(flagset []*pflag.Flag) (*pflag.Flag, erro
return nil, nil
}
for _, opt := range flagset {
if opt == nil {
continue
}
Comment on lines +498 to +500
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👁️‍🗨️ Here we avoid checking nonexistent flags for a changed value which is useful since the create command doesn't provide a "language" flag.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting how the survey is kinda getting in the way. Thanks for improving it!

if !opt.Changed {
continue
} else if flag != nil {
Expand Down
Loading