mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-22 18:30:40 +00:00
32 lines
736 B
Go
32 lines
736 B
Go
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/thegeeklab/git-sv/v2/app"
|
|
"github.com/thegeeklab/git-sv/v2/sv"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
func NextVersionHandler(g app.GitSV) cli.ActionFunc {
|
|
return func(c *cli.Context) error {
|
|
lastTag := g.LastTag()
|
|
|
|
currentVer, err := sv.ToVersion(lastTag)
|
|
if err != nil {
|
|
return fmt.Errorf("error parsing version: %s from git tag, message: %w", lastTag, err)
|
|
}
|
|
|
|
commits, err := g.Log(app.NewLogRange(app.TagRange, lastTag, ""))
|
|
if err != nil {
|
|
return fmt.Errorf("error getting git log, message: %w", err)
|
|
}
|
|
|
|
nextVer, _ := g.CommitProcessor.NextVersion(currentVer, commits)
|
|
|
|
fmt.Printf("%d.%d.%d\n", nextVer.Major(), nextVer.Minor(), nextVer.Patch())
|
|
|
|
return nil
|
|
}
|
|
}
|