-
Notifications
You must be signed in to change notification settings - Fork 1
/
set_timeout.go
50 lines (41 loc) · 986 Bytes
/
set_timeout.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
package cmd
import (
"time"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(setTimeoutCmd)
}
var setTimeoutCmd = &cobra.Command{
Use: "set-timeout",
Short: "An easy way to set the unlock timeout duration (e.g. '10s', '10m', '10h' etc.).",
PreRun: toggleDebug,
Run: func(cmd *cobra.Command, args []string) {
nativeCmd = true
err := setTimeout(cmd, args)
if err != nil {
log.Fatal(err)
}
},
}
func setTimeout(cmd *cobra.Command, args []string) error {
var err error
newTimeout := args[0]
config, err := getViperConfig()
if err != nil {
return err
}
log.Info("Setting new Unlock Timeout Period to '", newTimeout, "'...")
_, err = time.ParseDuration(newTimeout)
if err != nil {
log.Error("Provided Timeout Value '", newTimeout, "' not provided correctly... Exiting")
return err
}
config.UnlockTimeoutPeriod = newTimeout
err = WriteToConfig(config)
if err != nil {
return err
}
return nil
}