Skip to content

Commit

Permalink
feat: Support new sub-command "delete"
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoh86 committed Aug 17, 2024
1 parent 3776de3 commit f408a29
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions internal/manager.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package internal

import (
"fmt"
"strconv"
"strings"

Expand Down Expand Up @@ -74,6 +75,25 @@ func (m *Manager) GetVer() (string, error) {
return m.Prefix + v.String(), nil
}

func (m *Manager) DeleteVer() (string, error) {
{
vold, err := m.getVer()
if err != nil {
return "", fmt.Errorf("failed to get current ver: %w", err)
}
if err := m.deleteVer(vold); err != nil {
return "", fmt.Errorf("failed to delete ver: %w", err)
}
}
{
vnew, err := m.getVer()
if err != nil {
return "", fmt.Errorf("failed to refetch new ver: %w", err)
}
return m.Prefix + vnew.String(), nil
}
}

func (m *Manager) UpdateMajor(pre []semver.PRVersion, build, msg []string, file string) (string, string, error) {
return m.update(pre, build, msg, file, func(u Updater) UpdatePre { return u.Major() })
}
Expand Down
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func main() {
app.Flag("ancestors", "With ancestor versions (vN and vN.N)").Envar("GIT_VERTAG_ANCESTORS").BoolVar(&ancestors)

getCmd := app.Command("get", "Gets the current version tag.").Default()
deleteCmd := app.Command("delete", "Deletes the current version tag.")
majorCmd := app.Command("major", "Creates a tag for the next major version and prints it.")
minorCmd := app.Command("minor", "Creates a tag for the next minor version and prints it.")
patchCmd := app.Command("patch", "Creates a tag for the next patch version and prints it.")
Expand Down Expand Up @@ -94,6 +95,13 @@ func main() {
}
fmt.Println(v)

case deleteCmd.FullCommand():
v, err := mgr.DeleteVer()
if err != nil {
return
}
fmt.Println(v)

case majorCmd.FullCommand():
printResult(mgr.UpdateMajor(pre, build, message, file))

Expand Down

0 comments on commit f408a29

Please sign in to comment.