Print prettier version info
This commit is contained in:
parent
9b40934654
commit
5d896ae439
@ -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
|
||||
|
@ -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"))
|
||||
|
@ -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"
|
||||
|
26
version/version.go
Normal file
26
version/version.go
Normal file
@ -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")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user