-
Notifications
You must be signed in to change notification settings - Fork 20
/
dns_show.go
71 lines (59 loc) · 1.42 KB
/
dns_show.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
62
63
64
65
66
67
68
69
70
71
package cmd
import (
"errors"
"os"
"strconv"
"github.com/exoscale/cli/table"
"github.com/spf13/cobra"
)
func init() {
dnsCmd.AddCommand(dnsShowCmd)
dnsShowCmd.Flags().StringP("name", "n", "", "List records by name")
}
// dnsShowCmd represents the show command
var dnsShowCmd = &cobra.Command{
Use: "show <domain name | id> [type]",
Short: "Show the domain records",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("show expects one DNS domain by name or id")
}
var types []string
if len(args) > 1 {
types = make([]string, len(args)-1)
copy(types, args[1:])
} else {
types = []string{""}
}
name, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
t := table.NewTable(os.Stdout)
err = domainListRecords(t, args[0], name, types)
if err == nil {
t.Render()
}
return err
},
}
func domainListRecords(t *table.Table, domain, name string, types []string) error {
t.SetHeader([]string{"Type", "Name", "Content", "TTL", "Prio", "ID"})
for _, recordType := range types {
records, err := csDNS.GetRecordsWithFilters(gContext, domain, name, recordType)
if err != nil {
return err
}
for _, record := range records {
t.Append([]string{
record.RecordType,
record.Name,
record.Content,
strconv.Itoa(record.TTL),
strconv.Itoa(record.Prio),
strconv.FormatInt(record.ID, 10),
})
}
}
return nil
}