forked from mantl/consul-cli
/
session_destroy.go
55 lines (44 loc) · 1.05 KB
/
session_destroy.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
package commands
import (
"github.com/spf13/cobra"
)
func (s *Session) AddDestroySub(cmd *cobra.Command) {
destroyCmd := &cobra.Command{
Use: "destroy <sessionId>",
Short: "Destroy a session",
Long: "Destroy a session",
RunE: func(cmd *cobra.Command, args []string) error {
return s.Destroy(args)
},
}
oldDestroyCmd := &cobra.Command{
Use: "session-destroy <sessionId>",
Short: "Destroy a session",
Long: "Destroy a session",
Deprecated: "Use session destroy",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
return s.Destroy(args)
},
}
s.AddDatacenterOption(destroyCmd)
s.AddDatacenterOption(oldDestroyCmd)
cmd.AddCommand(destroyCmd)
s.AddCommand(oldDestroyCmd)
}
func (s *Session) Destroy(args []string) error {
if err := s.CheckIdArg(args); err != nil {
return err
}
sessionid := args[0]
client, err := s.Session()
if err != nil {
return err
}
writeOpts := s.WriteOptions()
_, err = client.Destroy(sessionid, writeOpts)
if err != nil {
return err
}
return nil
}