Skip to content

Commit bab10c3

Browse files
committed
add branch flag
1 parent 51ce631 commit bab10c3

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var (
3333
flagNoFetch = flag.Bool("nofetch", false, "don't fetch remote tags")
3434
flagNoNewline = flag.Bool("nonewline", false, "don't print a newline after the output")
3535
flagIncPatch = flag.Bool("incpatch", false, "increment the patch level and create a new tag")
36+
flagBranch = flag.Bool("branch", false, "print the current branch name")
3637
)
3738

3839
func mainfn() int {
@@ -58,6 +59,9 @@ func mainfn() int {
5859
createTag = vi.IncPatch()
5960
}
6061
content := vi.Version()
62+
if *flagBranch {
63+
content = vi.Branch
64+
}
6165
if *flagGoPackage {
6266
content, err = vi.GoPackage(repoDir, *flagName)
6367
}

main_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ func TestMainFn(t *testing.T) {
2424
}
2525
}
2626

27+
func TestMainFnBranch(t *testing.T) {
28+
flag.Parse()
29+
*flagBranch = true
30+
*flagOut = "test.out"
31+
mainfn()
32+
b, err := os.ReadFile("test.out")
33+
if err == nil {
34+
defer os.Remove("test.out")
35+
s := string(b)
36+
if !strings.Contains(s, "main") {
37+
t.Error(s)
38+
}
39+
} else {
40+
t.Error(err)
41+
}
42+
}
43+
2744
func TestMainError(t *testing.T) {
2845
exitFn = func(i int) {
2946
if i == 0 {

0 commit comments

Comments
 (0)