-
Notifications
You must be signed in to change notification settings - Fork 12
/
setup.go
48 lines (39 loc) · 905 Bytes
/
setup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package setup
import (
"fmt"
"github.com/AlecAivazis/survey/v2"
"github.com/spf13/viper"
)
var questions = []*survey.Question{
{
Name: "apiKey",
Prompt: &survey.Input{Message: "Api Key:"},
Validate: survey.Required,
},
{
Name: "authToken",
Prompt: &survey.Input{Message: "Auth Token:"},
Validate: survey.Required,
},
}
func SurveyConfig() error {
answers := struct {
ApiKey string
AuthToken string
}{}
err := survey.Ask(questions, &answers)
if err != nil {
return err
}
confirm := false
survey.AskOne(&survey.Confirm{Message: "Does this look correct?"}, &confirm)
if confirm {
viper.Set("resy_api_key", answers.ApiKey)
viper.Set("resy_auth_token", answers.AuthToken)
viper.WriteConfig()
fmt.Println("Your user info has been saved! You're all set to start booking.")
} else {
fmt.Println("Your user info was not saved.")
}
return nil
}