2020-08-06 20:58:47 +03:00
|
|
|
package tablew
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/neilotoole/sq/cli/output"
|
|
|
|
"github.com/neilotoole/sq/libsq/notify"
|
|
|
|
)
|
|
|
|
|
2020-08-19 23:46:04 +03:00
|
|
|
type notifyWriter struct {
|
2020-08-06 20:58:47 +03:00
|
|
|
tbl *table
|
|
|
|
}
|
|
|
|
|
2020-08-19 23:46:04 +03:00
|
|
|
// NewNotifyWriter implements output.NotificationWriter.
|
|
|
|
func NewNotifyWriter(out io.Writer, fm *output.Formatting, header bool) output.NotificationWriter {
|
2020-08-06 20:58:47 +03:00
|
|
|
tbl := &table{out: out, header: header, fm: fm}
|
2020-08-19 23:46:04 +03:00
|
|
|
w := ¬ifyWriter{tbl: tbl}
|
2020-08-06 20:58:47 +03:00
|
|
|
w.tbl.reset()
|
|
|
|
return w
|
|
|
|
}
|
|
|
|
|
2020-08-19 23:46:04 +03:00
|
|
|
// NotifyDestinations implements output.NotificationWriter.
|
|
|
|
func (w *notifyWriter) NotifyDestinations(dests []notify.Destination) error {
|
2020-08-06 20:58:47 +03:00
|
|
|
w.tbl.tblImpl.SetHeader([]string{"NOTIFIER", "TYPE", "TARGET"})
|
|
|
|
var rows [][]string
|
|
|
|
|
|
|
|
for _, dest := range dests {
|
|
|
|
row := []string{dest.Label, string(dest.Type), dest.Target}
|
|
|
|
rows = append(rows, row)
|
|
|
|
}
|
|
|
|
|
|
|
|
w.tbl.appendRowsAndRenderAll(rows)
|
|
|
|
return nil
|
|
|
|
}
|