Skip to content

Commit 1e9aed0

Browse files
authored
Merge pull request #15 from kazhuravlev/current-tag-options
Add option to change last tag format
2 parents 5668ace + dc054dc commit 1e9aed0

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,15 @@ By default `gt` will throw an error when you try to increment a tag on commit, t
6363

6464
In order to skip this error - provide additional flag to increment command like
6565
that: `gt t i min --ignore-exists-tag`.
66+
67+
### Examples
68+
69+
```shell
70+
# Get last semver tag in this repo
71+
$ gt tag last
72+
v1.9.0 (c2e70ec90579ba18fd73078e98f677aec75ae002)
73+
74+
# Show only tag name (useful for ci/cd)
75+
$ gt tag last -f tag
76+
v1.9.0
77+
```

cmd/gt/main.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ import (
1717
const (
1818
flagRepoPath = "repo"
1919
flagIgnoreExistsTag = "ignore-exists-tag"
20+
flagFormat = "format"
21+
)
22+
23+
const (
24+
formatFull = "full"
25+
formatTagOnly = "tag"
2026
)
2127

2228
var (
@@ -81,8 +87,18 @@ func main() {
8187
{
8288
Name: "last",
8389
Aliases: []string{"l"},
84-
Action: withManager(cmdTagGetSemverLast),
85-
Usage: "show last semver tag",
90+
Flags: []cli.Flag{
91+
&cli.StringFlag{
92+
Name: flagFormat,
93+
Usage: "will change the output format",
94+
Value: formatFull,
95+
Aliases: []string{"f"},
96+
OnlyOnce: true,
97+
Required: false,
98+
},
99+
},
100+
Action: withManager(cmdTagGetSemverLast),
101+
Usage: "show last semver tag",
86102
},
87103
},
88104
},
@@ -176,12 +192,25 @@ func buildTagIncrementor(component repomanager.Component) func(context.Context,
176192
}
177193

178194
func cmdTagGetSemverLast(ctx context.Context, c *cli.Command, m *repomanager.Manager) error {
195+
format := c.String(flagFormat)
196+
switch format {
197+
default:
198+
return fmt.Errorf("unknown format: %s", format)
199+
case formatFull, formatTagOnly:
200+
}
201+
179202
maxTag, err := m.GetTagsSemverMax()
180203
if err != nil {
181204
return fmt.Errorf("cannot get max tag: %w", err)
182205
}
183206

184-
fmt.Printf("%s (%s)\n", maxTag.TagName(), maxTag.Ref.Hash())
207+
switch format {
208+
case formatFull:
209+
fmt.Printf("%s (%s)\n", maxTag.TagName(), maxTag.Ref.Hash())
210+
case formatTagOnly:
211+
fmt.Printf("%s\n", maxTag.TagName())
212+
}
213+
185214
return nil
186215
}
187216

0 commit comments

Comments
 (0)