Files
jira/vendor/github.com/AlecAivazis/survey/examples/simple.go
T
2017-08-13 18:23:38 -07:00

44 lines
677 B
Go

package main
import (
"fmt"
"github.com/AlecAivazis/survey"
)
// the questions to ask
var simpleQs = []*survey.Question{
{
Name: "name",
Prompt: &survey.Input{
Message: "What is your name?",
},
Validate: survey.Required,
},
{
Name: "color",
Prompt: &survey.Select{
Message: "Choose a color:",
Options: []string{"red", "blue", "green"},
},
Validate: survey.Required,
},
}
func main() {
answers := struct {
Name string
Color string
}{}
// ask the question
err := survey.Ask(simpleQs, &answers)
if err != nil {
fmt.Println(err.Error())
return
}
// print the answers
fmt.Printf("%s chose %s.\n", answers.Name, answers.Color)
}