Skip to content

Commit 1f7bc8a

Browse files
committed
feat(cli): add version and add homebrew tap
1 parent f692a33 commit 1f7bc8a

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

.goreleaser.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
builds:
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"

cmd/main.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
1623
var (
1724
app = kingpin.New("algo", "A command-line tool for algo-go repo.")
1825

@@ -40,6 +47,10 @@ func showMeta(number string) {
4047
}
4148

4249
func 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\ncommit: %s", result, commit)
70+
}
71+
if date != "" {
72+
result = fmt.Sprintf("%s\nbuilt at: %s", result, date)
73+
}
74+
if builtBy != "" {
75+
result = fmt.Sprintf("%s\nbuilt by: %s", result, builtBy)
76+
}
77+
return result
78+
}

0 commit comments

Comments
 (0)