forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword_set.go
49 lines (40 loc) · 950 Bytes
/
password_set.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
package cmd
import (
"github.com/AlecAivazis/survey/v2"
"github.com/evcc-io/evcc/util/auth"
"github.com/spf13/cobra"
)
var passwordSetCmd = &cobra.Command{
Use: "set",
Short: "Set password",
Args: cobra.ExactArgs(0),
Run: runPasswordSet,
}
func init() {
passwordCmd.AddCommand(passwordSetCmd)
}
func runPasswordSet(cmd *cobra.Command, args []string) {
// load config
if err := loadConfigFile(&conf, !cmd.Flag(flagIgnoreDatabase).Changed); err != nil {
log.FATAL.Fatal(err)
}
// setup environment
if err := configureEnvironment(cmd, &conf); err != nil {
log.FATAL.Fatal(err)
}
prompt := &survey.Password{
Message: "Password",
Help: "help",
}
var password string
if err := survey.AskOne(prompt, &password); err != nil {
log.FATAL.Fatal(err)
}
if password == "" {
log.FATAL.Fatal("password cannot be empty")
} else {
auth.New().SetAdminPassword(password)
}
// wait for shutdown
<-shutdownDoneC()
}