sq/cli/output/jsonw/configw.go
Neil O'Toole 81f631e135
Refactoring (#206)
* Renamed source.Type to source.DriverType for clarity

* More renaming wrt source.DriverType

* Renamed output.Formatting to output.Printing
2023-04-21 21:36:32 -06:00

47 lines
936 B
Go

package jsonw
import (
"io"
"github.com/neilotoole/sq/cli/config"
"github.com/neilotoole/sq/cli/output"
)
var _ output.ConfigWriter = (*configWriter)(nil)
// configWriter implements output.ConfigWriter.
type configWriter struct {
out io.Writer
pr *output.Printing
}
// NewConfigWriter returns a new output.ConfigWriter.
func NewConfigWriter(out io.Writer, pr *output.Printing) output.ConfigWriter {
return &configWriter{out: out, pr: pr}
}
// Location implements output.ConfigWriter.
func (w *configWriter) Location(loc, origin string) error {
type cfgInfo struct {
Location string `json:"location"`
Origin string `json:"origin,omitempty"`
}
c := cfgInfo{
Location: loc,
Origin: origin,
}
return writeJSON(w.out, w.pr, c)
}
// Options implements output.ConfigWriter.
func (w *configWriter) Options(opts *config.Options) error {
if opts == nil {
return nil
}
return writeJSON(w.out, w.pr, opts)
}