sq/cli/cmd_version.go

36 lines
688 B
Go
Raw Normal View History

2020-08-06 20:58:47 +03:00
package cli
import (
"fmt"
"github.com/spf13/cobra"
"github.com/neilotoole/sq/cli/buildinfo"
)
func newVersionCmd() (*cobra.Command, runFunc) {
cmd := &cobra.Command{
Use: "version",
Short: "Print sq version",
}
return cmd, execVersion
}
func execVersion(rc *RunContext, cmd *cobra.Command, args []string) error {
rc.writers.fmt.Hilite.Fprintf(rc.Out, "sq %s", buildinfo.Version)
2020-08-06 20:58:47 +03:00
if len(buildinfo.Commit) > 0 {
fmt.Fprint(rc.Out, " ")
2020-08-08 06:06:56 +03:00
rc.writers.fmt.Faint.Fprint(rc.Out, "#"+buildinfo.Commit)
2020-08-06 20:58:47 +03:00
}
if len(buildinfo.Timestamp) > 0 {
fmt.Fprint(rc.Out, " ")
2020-08-08 06:06:56 +03:00
rc.writers.fmt.Faint.Fprint(rc.Out, buildinfo.Timestamp)
2020-08-06 20:58:47 +03:00
}
fmt.Fprintln(rc.Out)
return nil
}