2022-12-30 20:10:56 +03:00
|
|
|
package jsonw
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
|
2023-06-21 15:28:15 +03:00
|
|
|
"github.com/neilotoole/sq/cli/hostinfo"
|
|
|
|
|
2022-12-30 20:10:56 +03:00
|
|
|
"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
|
2023-04-22 06:36:32 +03:00
|
|
|
pr *output.Printing
|
2022-12-30 20:10:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewVersionWriter returns a new output.VersionWriter instance
|
|
|
|
// that outputs version info in JSON.
|
2023-04-22 06:36:32 +03:00
|
|
|
func NewVersionWriter(out io.Writer, pr *output.Printing) output.VersionWriter {
|
|
|
|
return &versionWriter{out: out, pr: pr}
|
2022-12-30 20:10:56 +03:00
|
|
|
}
|
|
|
|
|
2023-06-21 15:28:15 +03:00
|
|
|
// Version implements output.VersionWriter.
|
|
|
|
func (w *versionWriter) Version(bi buildinfo.BuildInfo, latestVersion string, hi hostinfo.Info) error {
|
2022-12-30 20:10:56 +03:00
|
|
|
type cliBuildInfo struct {
|
|
|
|
buildinfo.BuildInfo
|
2023-06-21 15:28:15 +03:00
|
|
|
LatestVersion string `json:"latest_version"`
|
|
|
|
Host hostinfo.Info `json:"host"`
|
2022-12-30 20:10:56 +03:00
|
|
|
}
|
|
|
|
|
2023-06-21 15:28:15 +03:00
|
|
|
cbi := cliBuildInfo{
|
|
|
|
BuildInfo: bi,
|
2022-12-30 20:10:56 +03:00
|
|
|
LatestVersion: latestVersion,
|
2023-06-21 15:28:15 +03:00
|
|
|
Host: hi,
|
2022-12-30 20:10:56 +03:00
|
|
|
}
|
|
|
|
|
2023-06-21 15:28:15 +03:00
|
|
|
return writeJSON(w.out, w.pr, cbi)
|
2022-12-30 20:10:56 +03:00
|
|
|
}
|