forked from mantl/consul-cli
/
health_checks.go
61 lines (49 loc) · 1.26 KB
/
health_checks.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
57
58
59
60
61
package commands
import (
"fmt"
"github.com/spf13/cobra"
)
func (h *Health) AddChecksSub(cmd *cobra.Command) {
checksCmd := &cobra.Command{
Use: "checks <serviceName>",
Short: "Get the health checks for a service",
Long: "Get the health checks for a service",
RunE: func(cmd *cobra.Command, args []string) error {
return h.Checks(args)
},
}
oldChecksCmd := &cobra.Command{
Use: "health-checks <serviceName>",
Short: "Get the health checks for a service",
Long: "Get the health checks for a service",
Deprecated: "Use health checks",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
return h.Checks(args)
},
}
h.AddDatacenterOption(checksCmd)
h.AddTemplateOption(checksCmd)
h.AddDatacenterOption(oldChecksCmd)
cmd.AddCommand(checksCmd)
h.AddCommand(oldChecksCmd)
}
func (h *Health) Checks(args []string) error {
switch {
case len(args) == 0:
return fmt.Errorf("Service name must be specified")
case len(args) > 1:
return fmt.Errorf("Only one service name allowed")
}
service := args[0]
client, err := h.Health()
if err != nil {
return err
}
queryOpts := h.QueryOptions()
checks, _, err := client.Checks(service, queryOpts)
if err != nil {
return err
}
return h.Output(checks)
}