Skip to content

Commit

Permalink
Merge pull request #15 from kazhuravlev/current-tag-options
Browse files Browse the repository at this point in the history
Add option to change last tag format
  • Loading branch information
kazhuravlev authored Jul 9, 2024
2 parents 5668ace + dc054dc commit 1e9aed0
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,15 @@ By default `gt` will throw an error when you try to increment a tag on commit, t

In order to skip this error - provide additional flag to increment command like
that: `gt t i min --ignore-exists-tag`.

### Examples

```shell
# Get last semver tag in this repo
$ gt tag last
v1.9.0 (c2e70ec90579ba18fd73078e98f677aec75ae002)

# Show only tag name (useful for ci/cd)
$ gt tag last -f tag
v1.9.0
```
35 changes: 32 additions & 3 deletions cmd/gt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import (
const (
flagRepoPath = "repo"
flagIgnoreExistsTag = "ignore-exists-tag"
flagFormat = "format"
)

const (
formatFull = "full"
formatTagOnly = "tag"
)

var (
Expand Down Expand Up @@ -81,8 +87,18 @@ func main() {
{
Name: "last",
Aliases: []string{"l"},
Action: withManager(cmdTagGetSemverLast),
Usage: "show last semver tag",
Flags: []cli.Flag{
&cli.StringFlag{
Name: flagFormat,
Usage: "will change the output format",
Value: formatFull,
Aliases: []string{"f"},
OnlyOnce: true,
Required: false,
},
},
Action: withManager(cmdTagGetSemverLast),
Usage: "show last semver tag",
},
},
},
Expand Down Expand Up @@ -176,12 +192,25 @@ func buildTagIncrementor(component repomanager.Component) func(context.Context,
}

func cmdTagGetSemverLast(ctx context.Context, c *cli.Command, m *repomanager.Manager) error {
format := c.String(flagFormat)
switch format {
default:
return fmt.Errorf("unknown format: %s", format)
case formatFull, formatTagOnly:
}

maxTag, err := m.GetTagsSemverMax()
if err != nil {
return fmt.Errorf("cannot get max tag: %w", err)
}

fmt.Printf("%s (%s)\n", maxTag.TagName(), maxTag.Ref.Hash())
switch format {
case formatFull:
fmt.Printf("%s (%s)\n", maxTag.TagName(), maxTag.Ref.Hash())
case formatTagOnly:
fmt.Printf("%s\n", maxTag.TagName())
}

return nil
}

Expand Down

0 comments on commit 1e9aed0

Please sign in to comment.