feat(md prompter): md prompt respects blankAllowed
Accessible prompter now respects blankAllowed and will not prompt for "skip" if blankAllowed is false.
This commit is contained in:
parent
202c1ad16b
commit
7b0c09541d
1 changed files with 9 additions and 5 deletions
|
|
@ -221,23 +221,27 @@ func (p *huhPrompter) InputHostname() (string, error) {
|
|||
|
||||
func (p *huhPrompter) MarkdownEditor(prompt, defaultValue string, blankAllowed bool) (string, error) {
|
||||
var result string
|
||||
options := []huh.Option[string]{
|
||||
huh.NewOption("Open Editor", "open"),
|
||||
}
|
||||
if blankAllowed {
|
||||
options = append(options, huh.NewOption("Skip", "skip"))
|
||||
}
|
||||
|
||||
form := p.newForm(
|
||||
huh.NewGroup(
|
||||
huh.NewSelect[string]().
|
||||
Title(prompt).
|
||||
Options(
|
||||
huh.NewOption("Open Editor", "open"),
|
||||
huh.NewOption("Skip", "skip"),
|
||||
).
|
||||
Options(options...).
|
||||
Value(&result),
|
||||
),
|
||||
)
|
||||
|
||||
if err := form.Run(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if result == "skip" {
|
||||
// TODO: loop if blank not allowed
|
||||
if !blankAllowed && defaultValue == "" {
|
||||
panic("blank not allowed and no default value")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue