forked from RiotGames/key-conjurer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set.go
53 lines (45 loc) · 1.27 KB
/
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
50
51
52
53
package main
import (
"fmt"
"strconv"
"github.com/spf13/cobra"
)
func init() {
setCmd.AddCommand(setTTLCmd)
setCmd.AddCommand(setTimeRemainingCmd)
}
var setCmd = &cobra.Command{
Use: "set",
Short: "Sets config values.",
Long: "Sets config values.",
}
var setTTLCmd = &cobra.Command{
Use: "ttl <ttl>",
Short: "Sets ttl value in number of hours.",
Long: "Sets ttl value in number of hours.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
config := ConfigFromCommand(cmd)
ttl, err := strconv.ParseUint(args[0], 10, 32)
if err != nil {
return fmt.Errorf("unable to parse value %s", args[0])
}
config.TTL = uint(ttl)
return nil
},
}
var setTimeRemainingCmd = &cobra.Command{
Use: "time-remaining <timeRemaining>",
Short: "Sets time remaining value in number of minutes.",
Long: "Sets time remaining value in number of minutes. Using minutes is an artifact from when keys could only live for 1 hour.",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
config := ConfigFromCommand(cmd)
timeRemaining, err := strconv.ParseUint(args[0], 10, 32)
if err != nil {
return fmt.Errorf("unable to parse value %s", args[0])
}
config.TimeRemaining = uint(timeRemaining)
return nil
},
}