mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-01 22:31:15 +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
|
|
}
|