2023-06-21 15:28:15 +03:00
|
|
|
package yamlw
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/goccy/go-yaml/printer"
|
|
|
|
|
|
|
|
"github.com/neilotoole/sq/cli/buildinfo"
|
2023-11-20 04:06:36 +03:00
|
|
|
"github.com/neilotoole/sq/cli/hostinfo"
|
2023-06-21 15:28:15 +03:00
|
|
|
"github.com/neilotoole/sq/cli/output"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ output.VersionWriter = (*versionWriter)(nil)
|
|
|
|
|
|
|
|
// versionWriter implements output.VersionWriter for JSON.
|
|
|
|
type versionWriter struct {
|
|
|
|
p printer.Printer
|
|
|
|
out io.Writer
|
|
|
|
pr *output.Printing
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewVersionWriter returns a new output.VersionWriter instance
|
|
|
|
// that outputs version info in JSON.
|
|
|
|
func NewVersionWriter(out io.Writer, pr *output.Printing) output.VersionWriter {
|
|
|
|
return &versionWriter{p: newPrinter(pr), out: out, pr: pr}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Version implements output.VersionWriter.
|
|
|
|
func (w *versionWriter) Version(bi buildinfo.BuildInfo, latestVersion string, hi hostinfo.Info) error {
|
|
|
|
type cliBuildInfo struct {
|
2023-06-21 18:15:40 +03:00
|
|
|
Version string `json:"version" yaml:"version"`
|
|
|
|
Commit string `json:"commit,omitempty" yaml:"commit,omitempty"`
|
|
|
|
Timestamp string `json:"timestamp,omitempty" yaml:"timestamp,omitempty"`
|
|
|
|
LatestVersion string `json:"latest_version" yaml:"latest_version"`
|
|
|
|
Host hostinfo.Info `json:"host" yaml:"host"`
|
2023-06-21 15:28:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cbi := cliBuildInfo{
|
2023-06-21 18:15:40 +03:00
|
|
|
Version: bi.Version,
|
|
|
|
Commit: bi.Commit,
|
|
|
|
Timestamp: bi.Timestamp,
|
2023-06-21 15:28:15 +03:00
|
|
|
LatestVersion: latestVersion,
|
|
|
|
Host: hi,
|
|
|
|
}
|
|
|
|
|
|
|
|
return writeYAML(w.out, w.p, cbi)
|
|
|
|
}
|