-
Notifications
You must be signed in to change notification settings - Fork 24
feat: include bolt for javascript and python in the 'samples' command #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0106715
5656f0d
83ed53e
8a8cd3f
da357f0
f169934
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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 | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 The
requiredoption defaulting to false will cause this prompt to skip from the changes below!