-
Notifications
You must be signed in to change notification settings - Fork 31
refactor(experiment): separate huh and lipgloss changes of charm #411
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -14,19 +14,29 @@ | |
|
|
||
| package iostreams | ||
|
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. question: Long-term, is there a more appropriate filename than
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. @mwbrooks I share this feeling. The terms "charm" or "huh" or "lipgloss" are meaningful for package imports but we might want to refactor this into a different packages once experiments conclude:
I'm not against
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.
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. @mwbrooks Cool cool! I'll hold off on changing that for another PR but it might be a good step toward the conclusions of |
||
|
|
||
| // Charm-based prompt implementations using the huh library | ||
| // These are used when the "charm" experiment is enabled | ||
| // Charm-based prompt implementations using the huh library. | ||
| // These are used when the "huh" experiment is enabled. | ||
|
|
||
| import ( | ||
| "context" | ||
| "slices" | ||
|
|
||
| huh "charm.land/huh/v2" | ||
| "github.com/slackapi/slack-cli/internal/experiment" | ||
| "github.com/slackapi/slack-cli/internal/style" | ||
| ) | ||
|
|
||
| // newForm wraps a field in a huh form, applying the Slack theme when the lipgloss experiment is enabled. | ||
| func newForm(io *IOStreams, field huh.Field) *huh.Form { | ||
| form := huh.NewForm(huh.NewGroup(field)) | ||
| if io != nil && io.config.WithExperimentOn(experiment.Lipgloss) { | ||
| form = form.WithTheme(style.ThemeSlack()) | ||
| } | ||
| return form | ||
| } | ||
|
|
||
| // buildInputForm constructs a huh form for text input prompts. | ||
| func buildInputForm(message string, cfg InputPromptConfig, input *string) *huh.Form { | ||
| func buildInputForm(io *IOStreams, message string, cfg InputPromptConfig, input *string) *huh.Form { | ||
| field := huh.NewInput(). | ||
| Title(message). | ||
| Prompt(style.Chevron() + " "). | ||
|
|
@@ -35,39 +45,39 @@ func buildInputForm(message string, cfg InputPromptConfig, input *string) *huh.F | |
| if cfg.Required { | ||
| field.Validate(huh.ValidateMinLength(1)) | ||
| } | ||
| return huh.NewForm(huh.NewGroup(field)).WithTheme(style.ThemeSlack()) | ||
| return newForm(io, field) | ||
| } | ||
|
|
||
| // charmInputPrompt prompts for text input using a charm huh form | ||
| func charmInputPrompt(_ *IOStreams, _ context.Context, message string, cfg InputPromptConfig) (string, error) { | ||
| func charmInputPrompt(io *IOStreams, _ context.Context, message string, cfg InputPromptConfig) (string, error) { | ||
| var input string | ||
| err := buildInputForm(message, cfg, &input).Run() | ||
| err := buildInputForm(io, message, cfg, &input).Run() | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return input, nil | ||
| } | ||
|
|
||
| // buildConfirmForm constructs a huh form for yes/no confirmation prompts. | ||
| func buildConfirmForm(message string, choice *bool) *huh.Form { | ||
| func buildConfirmForm(io *IOStreams, message string, choice *bool) *huh.Form { | ||
| field := huh.NewConfirm(). | ||
| Title(message). | ||
| Value(choice) | ||
| return huh.NewForm(huh.NewGroup(field)).WithTheme(style.ThemeSlack()) | ||
| return newForm(io, field) | ||
| } | ||
|
|
||
| // charmConfirmPrompt prompts for a yes/no confirmation using a charm huh form | ||
| func charmConfirmPrompt(_ *IOStreams, _ context.Context, message string, defaultValue bool) (bool, error) { | ||
| func charmConfirmPrompt(io *IOStreams, _ context.Context, message string, defaultValue bool) (bool, error) { | ||
| var choice = defaultValue | ||
| err := buildConfirmForm(message, &choice).Run() | ||
| err := buildConfirmForm(io, message, &choice).Run() | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| return choice, nil | ||
| } | ||
|
|
||
| // buildSelectForm constructs a huh form for single-selection prompts. | ||
| func buildSelectForm(msg string, options []string, cfg SelectPromptConfig, selected *string) *huh.Form { | ||
| func buildSelectForm(io *IOStreams, msg string, options []string, cfg SelectPromptConfig, selected *string) *huh.Form { | ||
| var opts []huh.Option[string] | ||
| for _, opt := range options { | ||
| key := opt | ||
|
|
@@ -85,13 +95,13 @@ func buildSelectForm(msg string, options []string, cfg SelectPromptConfig, selec | |
| Options(opts...). | ||
| Value(selected) | ||
|
|
||
| return huh.NewForm(huh.NewGroup(field)).WithTheme(style.ThemeSlack()) | ||
| return newForm(io, field) | ||
| } | ||
|
|
||
| // charmSelectPrompt prompts the user to select one option using a charm huh form | ||
| func charmSelectPrompt(_ *IOStreams, _ context.Context, msg string, options []string, cfg SelectPromptConfig) (SelectPromptResponse, error) { | ||
| func charmSelectPrompt(io *IOStreams, _ context.Context, msg string, options []string, cfg SelectPromptConfig) (SelectPromptResponse, error) { | ||
| var selected string | ||
| err := buildSelectForm(msg, options, cfg, &selected).Run() | ||
| err := buildSelectForm(io, msg, options, cfg, &selected).Run() | ||
| if err != nil { | ||
| return SelectPromptResponse{}, err | ||
| } | ||
|
|
@@ -101,7 +111,7 @@ func charmSelectPrompt(_ *IOStreams, _ context.Context, msg string, options []st | |
| } | ||
|
|
||
| // buildPasswordForm constructs a huh form for password (hidden input) prompts. | ||
| func buildPasswordForm(message string, cfg PasswordPromptConfig, input *string) *huh.Form { | ||
| func buildPasswordForm(io *IOStreams, message string, cfg PasswordPromptConfig, input *string) *huh.Form { | ||
| field := huh.NewInput(). | ||
| Title(message). | ||
| Prompt(style.Chevron() + " "). | ||
|
|
@@ -110,21 +120,21 @@ func buildPasswordForm(message string, cfg PasswordPromptConfig, input *string) | |
| if cfg.Required { | ||
| field.Validate(huh.ValidateMinLength(1)) | ||
| } | ||
| return huh.NewForm(huh.NewGroup(field)).WithTheme(style.ThemeSlack()) | ||
| return newForm(io, field) | ||
| } | ||
|
|
||
| // charmPasswordPrompt prompts for a password (hidden input) using a charm huh form | ||
| func charmPasswordPrompt(_ *IOStreams, _ context.Context, message string, cfg PasswordPromptConfig) (PasswordPromptResponse, error) { | ||
| func charmPasswordPrompt(io *IOStreams, _ context.Context, message string, cfg PasswordPromptConfig) (PasswordPromptResponse, error) { | ||
| var input string | ||
| err := buildPasswordForm(message, cfg, &input).Run() | ||
| err := buildPasswordForm(io, message, cfg, &input).Run() | ||
| if err != nil { | ||
| return PasswordPromptResponse{}, err | ||
| } | ||
| return PasswordPromptResponse{Prompt: true, Value: input}, nil | ||
| } | ||
|
|
||
| // buildMultiSelectForm constructs a huh form for multiple-selection prompts. | ||
| func buildMultiSelectForm(message string, options []string, selected *[]string) *huh.Form { | ||
| func buildMultiSelectForm(io *IOStreams, message string, options []string, selected *[]string) *huh.Form { | ||
| var opts []huh.Option[string] | ||
| for _, opt := range options { | ||
| opts = append(opts, huh.NewOption(opt, opt)) | ||
|
|
@@ -135,13 +145,13 @@ func buildMultiSelectForm(message string, options []string, selected *[]string) | |
| Options(opts...). | ||
| Value(selected) | ||
|
|
||
| return huh.NewForm(huh.NewGroup(field)).WithTheme(style.ThemeSlack()) | ||
| return newForm(io, field) | ||
| } | ||
|
|
||
| // charmMultiSelectPrompt prompts the user to select multiple options using a charm huh form | ||
| func charmMultiSelectPrompt(_ *IOStreams, _ context.Context, message string, options []string) ([]string, error) { | ||
| func charmMultiSelectPrompt(io *IOStreams, _ context.Context, message string, options []string) ([]string, error) { | ||
| var selected []string | ||
| err := buildMultiSelectForm(message, options, &selected).Run() | ||
| err := buildMultiSelectForm(io, message, options, &selected).Run() | ||
| if err != nil { | ||
| return []string{}, err | ||
| } | ||
|
|
||
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.
👌🏻