diff --git a/.goreleaser.yml b/.goreleaser.yml index e4d6d250..284bdef2 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,6 +1,6 @@ builds: - ldflags: - - -s -w -X github.com/khlieng/dispatch/commands.version=v{{.Version}} -X github.com/khlieng/dispatch/commands.commit={{.ShortCommit}} -X github.com/khlieng/dispatch/commands.date={{.Date}} + - -s -w -X github.com/khlieng/dispatch/version.Tag=v{{.Version}} -X github.com/khlieng/dispatch/version.Commit={{.ShortCommit}} -X github.com/khlieng/dispatch/version.Date={{.Date}} env: - CGO_ENABLED=0 diff --git a/commands/dispatch.go b/commands/dispatch.go index b5c44f9f..1c01c6e0 100644 --- a/commands/dispatch.go +++ b/commands/dispatch.go @@ -13,16 +13,11 @@ import ( "github.com/khlieng/dispatch/storage" "github.com/khlieng/dispatch/storage/bleve" "github.com/khlieng/dispatch/storage/boltdb" + "github.com/khlieng/dispatch/version" "github.com/spf13/cobra" "github.com/spf13/viper" ) -var ( - version = "dev" - commit = "none" - date = "unknown" -) - const logo = ` ____ _ _ _ | _ \ (_) ___ _ __ __ _ | |_ ___ | |__ @@ -42,7 +37,7 @@ var rootCmd = &cobra.Command{ Short: "Web-based IRC client in Go.", PersistentPreRun: func(cmd *cobra.Command, args []string) { if cmd.Use == "dispatch" { - fmt.Printf(logo, version, commit, date) + fmt.Printf(logo, version.Tag, version.Commit, version.Date) } storage.Initialize(viper.GetString("dir")) diff --git a/install.sh b/install.sh index 38d76841..b8acbb42 100755 --- a/install.sh +++ b/install.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash -Import="github.com/khlieng/dispatch/commands" +Import="github.com/khlieng/dispatch/version" -Version=$(git describe --tags) +Tag=$(git describe --tags) Commit=$(git rev-parse --short HEAD) Date=$(date +'%Y-%m-%dT%TZ') -go install -ldflags "-s -w -X $Import.version=$Version -X $Import.commit=$Commit -X $Import.date=$Date" +go install -ldflags "-s -w -X $Import.Tag=$Tag -X $Import.Commit=$Commit -X $Import.Date=$Date" diff --git a/version/version.go b/version/version.go new file mode 100644 index 00000000..06674b31 --- /dev/null +++ b/version/version.go @@ -0,0 +1,26 @@ +package version + +import ( + "fmt" + "strings" + "time" +) + +var ( + Tag = "dev" + Commit = "none" + Date = "unknown" +) + +func init() { + vParts := strings.Split(Tag, "-") + + if len(vParts) > 1 { + Tag = fmt.Sprintf("%s + %s commits", vParts[0], vParts[1]) + } + + t, err := time.Parse(time.RFC3339, Date) + if err == nil { + Date = t.Format("02 Jan 2006, 15:04:05") + } +}