Compare commits

..

1 Commits

Author SHA1 Message Date
amery 36347abaab dns/show: sort records
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-10-24 17:35:26 +00:00
2 changed files with 8 additions and 18 deletions
+5 -12
View File
@@ -6,7 +6,6 @@ import (
"io"
"net/netip"
"sort"
"strings"
"time"
"darvaza.org/core"
@@ -48,25 +47,19 @@ func SortRecords(s []libdns.Record) []libdns.Record {
}
func lessRecord(a, b libdns.Record) bool {
aName := strings.ToLower(a.Name)
bName := strings.ToLower(b.Name)
switch {
case aName < bName:
case a.Name < b.Name:
return true
case aName > bName:
case a.Name > b.Name:
return false
}
aType := strings.ToUpper(a.Type)
bType := strings.ToUpper(b.Type)
switch {
case aType < bType:
case a.Type < b.Type:
return true
case aType > bType:
case a.Type > b.Type:
return false
case aType == "A", aType == "AAAA":
case a.Type == "A", a.Type == "AAAA":
// IP Addresses
var aa, ba netip.Addr
+3 -6
View File
@@ -14,17 +14,14 @@ import (
// Show shows current DNS entries
func (mgr *Manager) Show(ctx context.Context, names ...string) error {
var buf bytes.Buffer
recs, err := mgr.GetRecords(ctx, names...)
if err != nil {
return core.Wrap(err, "GetRecords")
}
SortRecords(recs)
return writeRecords(recs, os.Stdout)
}
func writeRecords(recs []libdns.Record, w io.Writer) error {
var buf bytes.Buffer
for _, rr := range recs {
_ = fmtRecord(&buf, rr)
@@ -32,7 +29,7 @@ func writeRecords(recs []libdns.Record, w io.Writer) error {
}
_, _ = fmt.Fprintf(&buf, "; %v records\n", len(recs))
_, err := buf.WriteTo(w)
_, err = buf.WriteTo(os.Stdout)
return err
}