mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-25 01:04:55 +03:00
4521008b72
* Initial impl of 'sq config set' * Verbose output for 'sq config get' * config/options: refining 'sq config get' * Refine 'sq config get': now prints defaults when --verbose * cli: 'sq config get option.key' implemented * cli: initial impl of 'sq config get --src' * cli: refine 'sq config get' * cli: 'sq config set --src' is implemented
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package yamlw
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/neilotoole/sq/libsq/core/options"
|
|
|
|
"github.com/goccy/go-yaml/printer"
|
|
|
|
"github.com/neilotoole/sq/cli/output"
|
|
)
|
|
|
|
var _ output.ConfigWriter = (*configWriter)(nil)
|
|
|
|
// configWriter implements output.ConfigWriter.
|
|
type configWriter struct {
|
|
p printer.Printer
|
|
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, p: newPrinter(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 writeYAML(w.p, w.out, c)
|
|
}
|
|
|
|
// Options implements output.ConfigWriter.
|
|
func (w *configWriter) Options(_ *options.Registry, o options.Options) error {
|
|
if len(o) == 0 {
|
|
return nil
|
|
}
|
|
|
|
return writeYAML(w.p, w.out, o)
|
|
}
|
|
|
|
// SetOption implements output.ConfigWriter.
|
|
func (w *configWriter) SetOption(_ *options.Registry, o options.Options, opt options.Opt) error {
|
|
if !w.pr.Verbose {
|
|
return nil
|
|
}
|
|
|
|
o = options.Effective(o, opt)
|
|
return w.Options(nil, o)
|
|
}
|