diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index bb3e306..8721763 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -176,21 +176,7 @@ func initOptions() { } func printVersion() { - chunks := []string{fmt.Sprintf("Pgweb v%s", command.Version)} - - if command.GitCommit != "" { - chunks = append(chunks, fmt.Sprintf("(git: %s)", command.GitCommit)) - } - - if command.GoVersion != "" { - chunks = append(chunks, fmt.Sprintf("(go: %s)", command.GoVersion)) - } - - if command.BuildTime != "" { - chunks = append(chunks, fmt.Sprintf("(build time: %s)", command.BuildTime)) - } - - fmt.Println(strings.Join(chunks, " ")) + fmt.Println(command.VersionString()) } func startServer() { diff --git a/pkg/command/version.go b/pkg/command/version.go index 8c85a3a..2f4404d 100644 --- a/pkg/command/version.go +++ b/pkg/command/version.go @@ -1,5 +1,10 @@ package command +import ( + "fmt" + "strings" +) + const ( // Version is the current Pgweb application version Version = "0.11.12" @@ -32,3 +37,19 @@ func init() { Info.BuildTime = BuildTime Info.GoVersion = GoVersion } + +func VersionString() string { + chunks := []string{fmt.Sprintf("Pgweb v%s", Version)} + + if GitCommit != "" { + chunks = append(chunks, fmt.Sprintf("(git: %s)", GitCommit)) + } + if GoVersion != "" { + chunks = append(chunks, fmt.Sprintf("(go: %s)", GoVersion)) + } + if BuildTime != "" { + chunks = append(chunks, fmt.Sprintf("(build time: %s)", BuildTime)) + } + + return strings.Join(chunks, " ") +}