You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.0 KiB

package main
import (
"os/user"
"github.com/AlecAivazis/survey/v2"
)
func gpgPrompt(identities []Identity) (Identity, error) {
gpgOpts := []string{"None"}
gpgMap := make(map[string]Identity)
for _, ident := range identities {
gpgOpts = append(gpgOpts, ident.String())
gpgMap[ident.String()] = ident
}
gpgPrompt := &survey.Select{
Message: "GPG Identity",
Options: gpgOpts,
}
var gpgAnswer string
if err := survey.AskOne(gpgPrompt, &gpgAnswer); err != nil {
return Identity{}, err
}
if ident, ok := gpgMap[gpgAnswer]; ok {
return ident, nil
}
return Identity{}, nil
}
func userPrompt() (Identity, error) {
u, err := user.Current()
if err != nil {
return Identity{}, err
}
questions := []*survey.Question{
{
Name: "name",
Prompt: &survey.Input{
Message: "Name",
Default: u.Username,
},
Validate: survey.Required,
},
{
Name: "email",
Prompt: &survey.Input{
Message: "Email",
},
Validate: survey.Required,
},
}
var ident Identity
return ident, survey.Ask(questions, &ident)
}