Skip to content

Commit

Permalink
add flag to ignore exists tag
Browse files Browse the repository at this point in the history
  • Loading branch information
kazhuravlev committed Feb 20, 2024
1 parent 3bb6bca commit 8e220bf
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions cmd/gt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ import (
)

const (
flagRepoPath = "repo"
flagRepoPath = "repo"
flagIgnoreExistsTag = "ignore-exists-tag"
)

var (
version = "unknown-local-build"
)

var (
cliFlagIgnoreExistsTag = &cli.BoolFlag{
Name: flagIgnoreExistsTag,
Usage: "Use this option to force adding a new semver tag event when another one is exists",
Value: false,
}
)

func main() {
a := &cli.Command{
Version: version,
Expand Down Expand Up @@ -45,18 +54,21 @@ func main() {
{
Name: "major",
Aliases: []string{"maj"},
Flags: []cli.Flag{cliFlagIgnoreExistsTag},
Action: withManager(buildTagIncrementor(repomanager.ComponentMajor)),
Usage: "increment major part of semver",
},
{
Name: "minor",
Aliases: []string{"min"},
Flags: []cli.Flag{cliFlagIgnoreExistsTag},
Action: withManager(buildTagIncrementor(repomanager.ComponentMinor)),
Usage: "increment minor part of semver",
},
{
Name: "patch",
Aliases: []string{"pat"},
Flags: []cli.Flag{cliFlagIgnoreExistsTag},
Action: withManager(buildTagIncrementor(repomanager.ComponentPatch)),
Usage: "increment patch part of semver",
},
Expand Down Expand Up @@ -86,6 +98,8 @@ func main() {

func buildTagIncrementor(component repomanager.Component) func(context.Context, *cli.Command, *repomanager.Manager) error {
return func(ctx context.Context, c *cli.Command, m *repomanager.Manager) error {
ignoreExistsTag := c.Bool(flagIgnoreExistsTag)

repoPath := c.String(flagRepoPath)
if repoPath == "" {
return errors.New("path to repo must be set by flag " + flagRepoPath)
Expand All @@ -101,7 +115,7 @@ func buildTagIncrementor(component repomanager.Component) func(context.Context,
return fmt.Errorf("get current tag: %w", err)
}

if curTag.HasVal() {
if curTag.HasVal() && !ignoreExistsTag {
return fmt.Errorf("semver tag is already exists: %s", curTag.Val().TagName())
}

Expand Down

0 comments on commit 8e220bf

Please # to comment.