forked from mantl/consul-cli
/
health_node.go
61 lines (49 loc) · 1.19 KB
/
health_node.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) AddNodeSub(cmd *cobra.Command) {
nodeCmd := &cobra.Command{
Use: "node <nodeName>",
Short: "Get the health info for a node",
Long: "Get the health info for a node",
RunE: func(cmd *cobra.Command, args []string) error {
return h.Node(args)
},
}
oldNodeCmd := &cobra.Command{
Use: "health-node <nodeName>",
Short: "Get the health info for a node",
Long: "Get the health info for a node",
Deprecated: "Use health node",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
return h.Node(args)
},
}
h.AddDatacenterOption(nodeCmd)
h.AddDatacenterOption(oldNodeCmd)
h.AddTemplateOption(nodeCmd)
cmd.AddCommand(nodeCmd)
h.AddCommand(oldNodeCmd)
}
func (h *Health) Node(args []string) error {
switch {
case len(args) == 0:
return fmt.Errorf("Node name must be specified")
case len(args) > 1:
return fmt.Errorf("Only one node name allowed")
}
node := args[0]
client, err := h.Health()
if err != nil {
return err
}
queryOpts := h.QueryOptions()
n, _, err := client.Node(node, queryOpts)
if err != nil {
return err
}
return h.Output(n)
}