move version.go to main package
This commit is contained in:
+44
-2
@@ -1,20 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
|
||||
"github.com/mayswind/ezbookkeeping/cmd"
|
||||
"github.com/mayswind/ezbookkeeping/pkg/version"
|
||||
"github.com/mayswind/ezbookkeeping/pkg/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
// Version holds the version of this execution program
|
||||
Version string
|
||||
|
||||
// CommitHash holds the git commit hash of this execution program's source code
|
||||
CommitHash string
|
||||
|
||||
// BuildUnixTime holds the time when starting building this execution program
|
||||
BuildUnixTime string
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := &cli.App{
|
||||
Name: "ezBookkeeping",
|
||||
Usage: "A lightweight personal bookkeeping app hosted by yourself.",
|
||||
Version: version.GetFullVersion(),
|
||||
Version: GetFullVersion(),
|
||||
Commands: []*cli.Command{
|
||||
cmd.WebServer,
|
||||
cmd.Database,
|
||||
@@ -34,3 +47,32 @@ func main() {
|
||||
log.Fatalf("Failed to run ezBookkeeping with %s: %v", os.Args, err)
|
||||
}
|
||||
}
|
||||
|
||||
// GetFullVersion returns the full version
|
||||
func GetFullVersion() string {
|
||||
fullVersion := "Local Build"
|
||||
|
||||
if Version != "" {
|
||||
fullVersion = Version
|
||||
}
|
||||
|
||||
additionalInfos := make([]string, 0, 2)
|
||||
|
||||
if CommitHash != "" {
|
||||
additionalInfos = append(additionalInfos, "commit "+CommitHash)
|
||||
}
|
||||
|
||||
if BuildUnixTime != "" {
|
||||
unixTime, err := utils.StringToInt64(BuildUnixTime)
|
||||
|
||||
if unixTime > 0 && err == nil {
|
||||
additionalInfos = append(additionalInfos, "build time "+utils.FormatUnixTimeToLongDateTimeInServerTimezone(unixTime))
|
||||
}
|
||||
}
|
||||
|
||||
if len(additionalInfos) > 0 {
|
||||
fullVersion = fmt.Sprintf("%s (%s)", fullVersion, strings.Join(additionalInfos, ", "))
|
||||
}
|
||||
|
||||
return fullVersion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user