mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-14 20:46:30 +00:00
26 lines
467 B
Go
26 lines
467 B
Go
package ui
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
|
|
"github.com/charmbracelet/huh"
|
|
)
|
|
|
|
func Ask(prompt, placeholder string, required bool) (string, error) {
|
|
var input string
|
|
err := huh.NewInput().
|
|
Title(prompt).
|
|
Value(&input).
|
|
Placeholder(placeholder).Validate(func(s string) error {
|
|
if required && strings.TrimSpace(s) == "" {
|
|
return errors.New("required")
|
|
}
|
|
return nil
|
|
}).Run()
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return strings.TrimSpace(input), nil
|
|
}
|