mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-24 08:36:43 +03:00
f0aa65791b
* CHANGELOG text clarification * Dialing in config/options * Yet more dialing in of config/options * Refactor output writers * YAML output for more commands
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package yamlw
|
|
|
|
import (
|
|
"io"
|
|
|
|
yamlp "github.com/goccy/go-yaml/printer"
|
|
|
|
"github.com/neilotoole/sq/cli/output"
|
|
"github.com/neilotoole/sq/libsq/driver"
|
|
"github.com/neilotoole/sq/libsq/source"
|
|
)
|
|
|
|
// mdWriter implements output.MetadataWriter for YAML.
|
|
type mdWriter struct {
|
|
out io.Writer
|
|
pr *output.Printing
|
|
yp yamlp.Printer
|
|
}
|
|
|
|
// NewMetadataWriter returns a new output.MetadataWriter instance
|
|
// that outputs metadata in JSON.
|
|
func NewMetadataWriter(out io.Writer, pr *output.Printing) output.MetadataWriter {
|
|
return &mdWriter{out: out, pr: pr, yp: newPrinter(pr)}
|
|
}
|
|
|
|
// DriverMetadata implements output.MetadataWriter.
|
|
func (w *mdWriter) DriverMetadata(md []driver.Metadata) error {
|
|
return writeYAML(w.out, w.yp, md)
|
|
}
|
|
|
|
// TableMetadata implements output.MetadataWriter.
|
|
func (w *mdWriter) TableMetadata(md *source.TableMetadata) error {
|
|
return writeYAML(w.out, w.yp, md)
|
|
}
|
|
|
|
// SourceMetadata implements output.MetadataWriter.
|
|
func (w *mdWriter) SourceMetadata(md *source.Metadata) error {
|
|
md2 := *md // Shallow copy is fine
|
|
md2.Location = source.RedactLocation(md2.Location)
|
|
|
|
return writeYAML(w.out, w.yp, &md2)
|
|
}
|