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 {
|
2020-08-09 16:46:46 +03:00
|
|
|
rc.writers.fmt.Hilite.Fprintf(rc.Out, "sq %s", buildinfo.Version)
|
2020-08-06 20:58:47 +03:00
|
|
|
|
|
|
|
if len(buildinfo.Commit) > 0 {
|
2020-08-07 22:51:30 +03:00
|
|
|
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 {
|
2020-08-07 22:51:30 +03:00
|
|
|
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
|
|
|
|
}
|