forked from mantl/consul-cli
/
catalog_node.go
59 lines (48 loc) · 1.18 KB
/
catalog_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
package commands
import (
"fmt"
"github.com/spf13/cobra"
)
func (c *Catalog) AddNodeSub(cmd *cobra.Command) {
nodeCmd := &cobra.Command{
Use: "node",
Short: "Get the services provided by a node",
Long: "Get the services provided by a node",
RunE: func(cmd *cobra.Command, args []string) error {
return c.Node(args)
},
}
oldNodeCmd := &cobra.Command{
Use: "catalog-node",
Short: "Get the services provided by a node",
Long: "Get the services provided by a node",
Deprecated: "Use catalog node",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
return c.Node(args)
},
}
c.AddDatacenterOption(nodeCmd)
c.AddDatacenterOption(oldNodeCmd)
c.AddTemplateOption(nodeCmd)
cmd.AddCommand(nodeCmd)
c.AddCommand(oldNodeCmd)
}
func (c *Catalog) 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 allowed")
}
client, err := c.Catalog()
if err != nil {
return err
}
queryOpts := c.QueryOptions()
config, _, err := client.Node(args[0], queryOpts)
if err != nil {
return err
}
return c.Output(config)
}