mirror of
https://github.com/neilotoole/sq.git
synced 2024-12-19 14:11:45 +03:00
062e2dea88
- Windows filepath handling - Windows colorization handling - Minor code tidy up and refactor
44 lines
845 B
Go
44 lines
845 B
Go
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 == "" {
|
|
version = "0.0.0-dev"
|
|
}
|
|
|
|
rc.wrtr.fmt.Hilite.Fprintf(rc.Out, "sq %s", version)
|
|
|
|
if len(buildinfo.Commit) > 0 {
|
|
fmt.Fprint(rc.Out, " ")
|
|
rc.wrtr.fmt.Faint.Fprint(rc.Out, "#"+buildinfo.Commit)
|
|
}
|
|
|
|
if len(buildinfo.Timestamp) > 0 {
|
|
fmt.Fprint(rc.Out, " ")
|
|
rc.wrtr.fmt.Faint.Fprint(rc.Out, buildinfo.Timestamp)
|
|
}
|
|
|
|
fmt.Fprintln(rc.Out)
|
|
return nil
|
|
}
|