dns/show: introduce writeRecords() helper
to print a whole []libdns.Record Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
+7
-3
@@ -14,20 +14,24 @@ import (
|
|||||||
|
|
||||||
// Show shows current DNS entries
|
// Show shows current DNS entries
|
||||||
func (mgr *Manager) Show(ctx context.Context, names ...string) error {
|
func (mgr *Manager) Show(ctx context.Context, names ...string) error {
|
||||||
var buf bytes.Buffer
|
|
||||||
|
|
||||||
recs, err := mgr.GetRecords(ctx, names...)
|
recs, err := mgr.GetRecords(ctx, names...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return core.Wrap(err, "GetRecords")
|
return core.Wrap(err, "GetRecords")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return writeRecords(recs, os.Stdout)
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeRecords(recs []libdns.Record, w io.Writer) error {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
|
||||||
for _, rr := range recs {
|
for _, rr := range recs {
|
||||||
_ = fmtRecord(&buf, rr)
|
_ = fmtRecord(&buf, rr)
|
||||||
_, _ = buf.WriteRune('\n')
|
_, _ = buf.WriteRune('\n')
|
||||||
}
|
}
|
||||||
_, _ = fmt.Fprintf(&buf, "; %v records\n", len(recs))
|
_, _ = fmt.Fprintf(&buf, "; %v records\n", len(recs))
|
||||||
|
|
||||||
_, err = buf.WriteTo(os.Stdout)
|
_, err := buf.WriteTo(w)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user