sq/cli/output/tablew/versionw.go
Neil O'Toole 98b47a2666
#199 - Config, refactoring (#204)
* refactor: moved cli flags to pkg cli/flag

* testh: add OptLongDB for long-running tests

* implement 'sq config dir'

* legacy dir migration: probably a bad idea

* cleanup

* Refactored SQ_CONFIG and --config

* added yaml writer

* Dialing in tests

* YAML output for 'sq driver ls'

* Significant refactoring of config

* Minor test for ioz

* Rename source.Set to source.Collection

* Cleaning up references to source.Set
2023-04-18 23:28:09 -06:00

50 lines
1.1 KiB
Go

package tablew
import (
"fmt"
"io"
"github.com/neilotoole/sq/cli/buildinfo"
"github.com/neilotoole/sq/cli/output"
"golang.org/x/mod/semver"
)
var _ output.VersionWriter = (*versionWriter)(nil)
// versionWriter implements output.VersionWriter for text.
type versionWriter struct {
out io.Writer
fm *output.Formatting
}
// NewVersionWriter returns a new output.VersionWriter instance
// that outputs version info in text.
func NewVersionWriter(out io.Writer, fm *output.Formatting) output.VersionWriter {
return &versionWriter{out: out, fm: fm}
}
func (w *versionWriter) Version(bi buildinfo.BuildInfo, latestVersion string) error {
fmt.Fprintf(w.out, "sq %s", bi.Version)
if w.fm.Verbose {
if len(bi.Commit) > 0 {
fmt.Fprint(w.out, " ")
w.fm.Faint.Fprint(w.out, "#"+bi.Commit)
}
if len(bi.Timestamp) > 0 {
fmt.Fprint(w.out, " ")
w.fm.Faint.Fprint(w.out, bi.Timestamp)
}
}
showUpdate := semver.Compare(latestVersion, bi.Version) > 0
if showUpdate {
fmt.Fprint(w.out, " ")
w.fm.Faint.Fprint(w.out, "Update available: "+latestVersion)
}
fmt.Fprintln(w.out)
return nil
}