mirror of
https://github.com/manifoldco/promptui.git
synced 2026-03-14 22:35:53 +01:00
33 lines
480 B
Go
33 lines
480 B
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"github.com/manifoldco/promptui"
|
|
)
|
|
|
|
func main() {
|
|
validate := func(input string) error {
|
|
_, err := strconv.ParseFloat(input, 64)
|
|
if err != nil {
|
|
return errors.New("Invalid number")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
prompt := promptui.Prompt{
|
|
Label: "Number",
|
|
Validate: validate,
|
|
}
|
|
|
|
result, err := prompt.Run()
|
|
|
|
if err != nil {
|
|
fmt.Printf("Prompt failed %v\n", err)
|
|
return
|
|
}
|
|
|
|
fmt.Printf("You choose %q\n", result)
|
|
}
|