/
describe.go
47 lines (41 loc) · 1022 Bytes
/
describe.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
package cmd
import (
"context"
"encoding/json"
"fmt"
"github.com/aws/aws-sdk-go-v2/service/elasticloadbalancing"
"github.com/spf13/cobra"
"log"
)
// describeCmd represents the describe command
var describeCmd = &cobra.Command{
Use: "describe",
Aliases: []string{"d"},
Short: "Describe ELB",
Long: `Show all ELB properties as json.`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
log.Fatal("wrong number of arguments")
}
describeLoadBalancer(args[0])
},
}
func init() {
rootCmd.AddCommand(describeCmd)
}
// describeLoad-Balancers prints all load-balancer info as json
func describeLoadBalancer(name string) {
res, err := client.DescribeLoadBalancers(context.TODO(), &elasticloadbalancing.DescribeLoadBalancersInput{
LoadBalancerNames: []string{name},
})
if err != nil {
log.Fatal(err)
}
for _, l := range res.LoadBalancerDescriptions {
data, err := json.MarshalIndent(l, "", " ")
if err != nil {
log.Fatal(err)
}
fmt.Println(string(data))
}
}