sq/cli/output/jsonw/versionwriter.go
Neil O'Toole 97739da1e1
#263: sq version host info (#271)
* sq version host info

* workflow: update bug_report.md with version instructions
2023-06-21 06:28:15 -06:00

42 lines
1001 B
Go

package jsonw
import (
"io"
"github.com/neilotoole/sq/cli/hostinfo"
"github.com/neilotoole/sq/cli/buildinfo"
"github.com/neilotoole/sq/cli/output"
)
var _ output.VersionWriter = (*versionWriter)(nil)
// versionWriter implements output.VersionWriter for JSON.
type versionWriter struct {
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{out: out, pr: pr}
}
// Version implements output.VersionWriter.
func (w *versionWriter) Version(bi buildinfo.BuildInfo, latestVersion string, hi hostinfo.Info) error {
type cliBuildInfo struct {
buildinfo.BuildInfo
LatestVersion string `json:"latest_version"`
Host hostinfo.Info `json:"host"`
}
cbi := cliBuildInfo{
BuildInfo: bi,
LatestVersion: latestVersion,
Host: hi,
}
return writeJSON(w.out, w.pr, cbi)
}