File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change 1
1
builds :
2
2
- main : cmd/main.go
3
3
binary : leetcode-tool
4
- ldflags : -s -w -X main.GitCommit ={{.Commit}} -X main.Date ={{.Date}}
4
+ ldflags : -s -w -X main.version ={{.Version}} -X main.commit={{. Commit}} -X main.date ={{ .CommitDate }} -X main.builtBy=goreleaser
5
5
goos :
6
6
- windows
7
7
- darwin
@@ -16,3 +16,12 @@ changelog:
16
16
- ' ^refactor'
17
17
- ' ^tweak'
18
18
- ' ^test'
19
+ brews :
20
+ - github :
21
+ owner : zcong1993
22
+ name : homebrew-tap
23
+ folder : Formula
24
+ homepage : https://github.com/zcong1993/leetcode-tool
25
+ description : 一个让你更方便刷题的工具
26
+ test : |
27
+ system "#{bin}/leetcode-tool -v"
Original file line number Diff line number Diff line change @@ -13,6 +13,13 @@ import (
13
13
"gopkg.in/alecthomas/kingpin.v2"
14
14
)
15
15
16
+ var (
17
+ version = "master"
18
+ commit = ""
19
+ date = ""
20
+ builtBy = ""
21
+ )
22
+
16
23
var (
17
24
app = kingpin .New ("algo" , "A command-line tool for algo-go repo." )
18
25
@@ -40,6 +47,10 @@ func showMeta(number string) {
40
47
}
41
48
42
49
func main () {
50
+ app .Version (buildVersion (version , commit , date , builtBy ))
51
+ app .VersionFlag .Short ('v' )
52
+ app .HelpFlag .Short ('h' )
53
+
43
54
switch kingpin .MustParse (app .Parse (os .Args [1 :])) {
44
55
case updateCmd .FullCommand ():
45
56
update .Run ()
@@ -51,3 +62,17 @@ func main() {
51
62
tags .Run ()
52
63
}
53
64
}
65
+
66
+ func buildVersion (version , commit , date , builtBy string ) string {
67
+ var result = version
68
+ if commit != "" {
69
+ result = fmt .Sprintf ("%s\n commit: %s" , result , commit )
70
+ }
71
+ if date != "" {
72
+ result = fmt .Sprintf ("%s\n built at: %s" , result , date )
73
+ }
74
+ if builtBy != "" {
75
+ result = fmt .Sprintf ("%s\n built by: %s" , result , builtBy )
76
+ }
77
+ return result
78
+ }
You can’t perform that action at this time.
0 commit comments