Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5d896ae

Browse files
committed
Print prettier version info
1 parent9b40934 commit5d896ae

File tree

4 files changed

+32
-11
lines changed

4 files changed

+32
-11
lines changed

‎.goreleaser.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
builds:
22
-ldflags:
3-
--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}}
3+
--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}}
44

55
env:
66
-CGO_ENABLED=0

‎commands/dispatch.go‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,11 @@ import (
1313
"github.com/khlieng/dispatch/storage"
1414
"github.com/khlieng/dispatch/storage/bleve"
1515
"github.com/khlieng/dispatch/storage/boltdb"
16+
"github.com/khlieng/dispatch/version"
1617
"github.com/spf13/cobra"
1718
"github.com/spf13/viper"
1819
)
1920

20-
var (
21-
version="dev"
22-
commit="none"
23-
date="unknown"
24-
)
25-
2621
constlogo=`
2722
____ _ _ _
2823
| _ \ (_) ___ _ __ __ _ | |_ ___ | |__
@@ -42,7 +37,7 @@ var rootCmd = &cobra.Command{
4237
Short:"Web-based IRC client in Go.",
4338
PersistentPreRun:func(cmd*cobra.Command,args []string) {
4439
ifcmd.Use=="dispatch" {
45-
fmt.Printf(logo,version,commit,date)
40+
fmt.Printf(logo,version.Tag,version.Commit,version.Date)
4641
}
4742

4843
storage.Initialize(viper.GetString("dir"))

‎install.sh‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env bash
22

3-
Import="github.com/khlieng/dispatch/commands"
3+
Import="github.com/khlieng/dispatch/version"
44

5-
Version=$(git describe --tags)
5+
Tag=$(git describe --tags)
66
Commit=$(git rev-parse --short HEAD)
77
Date=$(date +'%Y-%m-%dT%TZ')
88

9-
go install -ldflags"-s -w -X$Import.version=$Version -X$Import.commit=$Commit -X$Import.date=$Date"
9+
go install -ldflags"-s -w -X$Import.Tag=$Tag -X$Import.Commit=$Commit -X$Import.Date=$Date"

‎version/version.go‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package version
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
"time"
7+
)
8+
9+
var (
10+
Tag="dev"
11+
Commit="none"
12+
Date="unknown"
13+
)
14+
15+
funcinit() {
16+
vParts:=strings.Split(Tag,"-")
17+
18+
iflen(vParts)>1 {
19+
Tag=fmt.Sprintf("%s + %s commits",vParts[0],vParts[1])
20+
}
21+
22+
t,err:=time.Parse(time.RFC3339,Date)
23+
iferr==nil {
24+
Date=t.Format("02 Jan 2006, 15:04:05")
25+
}
26+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp