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 {
|
|
|
|
version := buildinfo.Version
|
|
|
|
|
|
|
|
// If buildinfo.Version is not set (building without ldflags),
|
|
|
|
// then we set a dummy version.
|
|
|
|
if version == "" {
|
2020-08-07 22:51:30 +03:00
|
|
|
version = "0.0.0-dev"
|
2020-08-06 20:58:47 +03:00
|
|
|
}
|
|
|
|
|
2020-08-08 06:06:56 +03:00
|
|
|
rc.writers.fmt.Hilite.Fprintf(rc.Out, "sq %s", 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
|
|
|
|
}
|