forked from mantl/consul-cli
/
catalog_nodes.go
50 lines (41 loc) · 1.07 KB
/
catalog_nodes.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
package commands
import (
"github.com/spf13/cobra"
)
func (c *Catalog) AddNodesSub(cmd *cobra.Command) {
nodesCmd := &cobra.Command{
Use: "nodes",
Short: "Get all the nodes registered with a given DC",
Long: "Get all the nodes registered with a given DC",
RunE: func(cmd *cobra.Command, args []string) error {
return c.Nodes(args)
},
}
oldNodesCmd := &cobra.Command{
Use: "catalog-nodes",
Short: "Get all the nodes registered with a given DC",
Long: "Get all the nodes registered with a given DC",
Deprecated: "Use catalog nodes",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
return c.Nodes(args)
},
}
c.AddDatacenterOption(nodesCmd)
c.AddDatacenterOption(oldNodesCmd)
c.AddTemplateOption(nodesCmd)
cmd.AddCommand(nodesCmd)
c.AddCommand(oldNodesCmd)
}
func (c *Catalog) Nodes(args []string) error {
client, err := c.Catalog()
if err != nil {
return err
}
queryOpts := c.QueryOptions()
config, _, err := client.Nodes(queryOpts)
if err != nil {
return err
}
return c.Output(config)
}