Skip to content

Commit

Permalink
feat: add a new --suffix flag
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Oct 6, 2021
1 parent 4f5facb commit fcb14cc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ For example, `v1.2.3` would be output as `1.2.3`.
The default prefix is `v`, however a custom prefix can be supplied using `--prefix`.
So for `--prefix=foo/v --strip-prefix` and tag `foo/v1.2.3`, the output would be `1.2.3`.

## adding a suffix

`--suffix` can be used to set a custom suffix for the tag, e.g. build metadata or prelease.

## force patch version increment

Setting the `--force-patch-increment` flag forces a patch version increment regardless of the commit message content.
Expand Down
12 changes: 10 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (
preRelease = app.Flag("pre-release", "discards pre-release metadata if set to false").Default("true").Bool()
build = app.Flag("build", "discards build metadata if set to false").Default("true").Bool()
prefix = app.Flag("prefix", "set a custom prefix").Default("v").String()
suffix = app.Flag("suffix", "set a custom a custom suffix (metadata and/or prerelease)").String()
stripPrefix = app.Flag("strip-prefix", "strips the prefix from the tag").Default("false").Bool()
tagMode = app.Flag("tag-mode", "determines if latest tag of the current or all branches will be used").Default("current-branch").Enum("current-branch", "all-branches")
forcePatchIncrement = nextCmd.Flag("force-patch-increment", "forces a patch version increment regardless of the commit message content").Default("false").Bool()
Expand Down Expand Up @@ -67,13 +68,20 @@ func main() {
case currentCmd.FullCommand():
result = *current
}
fmt.Println(getVersion(tag, *prefix, result.String(), *stripPrefix))

result.SetMetadata(current.Metadata())
fmt.Println(getVersion(tag, *prefix, result.String(), *suffix, *stripPrefix))
}

func getVersion(tag, prefix, result string, stripPrefix bool) string {
func getVersion(tag, prefix, result, suffix string, stripPrefix bool) string {
if stripPrefix {
prefix = ""
}

if suffix != "" {
result = result + "-" + suffix
}

return prefix + result
}

Expand Down

0 comments on commit fcb14cc

Please sign in to comment.