-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.go
56 lines (45 loc) · 1.08 KB
/
configure.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
49
50
51
52
53
54
55
56
package cmd
import (
"os"
"github.com/AlecAivazis/survey/v2"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var (
qs = []*survey.Question{
{
Name: "githubToken",
Prompt: &survey.Password{Message: "Please enter a GitHub token:"},
Validate: survey.Required,
},
}
configureCmd = &cobra.Command{
Use: "configure",
Short: "Store your GitHub token other commands can work",
Long: `Store your GitHub token other commands can work,
Optionally, the environment variable 'RW_GH_TOKEN' can be set. This is useful in CI environments.`,
RunE: func(cmd *cobra.Command, args []string) error {
answers := struct {
GitHubToken string
}{}
err := survey.Ask(qs, &answers)
if err != nil {
return err
}
// makes sure the path to the config file exists
err = os.MkdirAll(os.ExpandEnv("$HOME/.config/warden"), os.ModePerm)
if err != nil {
return err
}
viper.Set("GH_TOKEN", answers.GitHubToken)
err = viper.WriteConfig()
if err != nil {
return err
}
return nil
},
}
)
func init() {
rootCmd.AddCommand(configureCmd)
}