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 11builds :
22 - main : cmd/main.go
33 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
55 goos :
66 - windows
77 - darwin
@@ -16,3 +16,12 @@ changelog:
1616 - ' ^refactor'
1717 - ' ^tweak'
1818 - ' ^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 (
1313 "gopkg.in/alecthomas/kingpin.v2"
1414)
1515
16+ var (
17+ version = "master"
18+ commit = ""
19+ date = ""
20+ builtBy = ""
21+ )
22+
1623var (
1724 app = kingpin .New ("algo" , "A command-line tool for algo-go repo." )
1825
@@ -40,6 +47,10 @@ func showMeta(number string) {
4047}
4148
4249func main () {
50+ app .Version (buildVersion (version , commit , date , builtBy ))
51+ app .VersionFlag .Short ('v' )
52+ app .HelpFlag .Short ('h' )
53+
4354 switch kingpin .MustParse (app .Parse (os .Args [1 :])) {
4455 case updateCmd .FullCommand ():
4556 update .Run ()
@@ -51,3 +62,17 @@ func main() {
5162 tags .Run ()
5263 }
5364}
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