2019-11-17 16:17:24 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-12-02 02:15:51 +00:00
|
|
|
"fmt"
|
2019-11-17 16:17:24 +00:00
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"sv4git/sv"
|
|
|
|
|
2020-02-01 21:37:16 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2019-11-17 16:17:24 +00:00
|
|
|
)
|
|
|
|
|
2019-12-04 23:18:38 +00:00
|
|
|
// Version for git-sv
|
|
|
|
var Version = ""
|
|
|
|
|
2019-11-17 16:17:24 +00:00
|
|
|
func main() {
|
2020-12-02 02:15:51 +00:00
|
|
|
log.SetFlags(0)
|
|
|
|
|
2019-11-17 16:17:24 +00:00
|
|
|
cfg := loadConfig()
|
|
|
|
|
2020-12-02 02:15:51 +00:00
|
|
|
fmt.Printf("%+v\n", cfg)
|
|
|
|
|
2020-02-01 22:43:02 +00:00
|
|
|
git := sv.NewGit(cfg.BreakingChangePrefixes, cfg.IssueIDPrefixes, cfg.TagPattern)
|
2019-11-17 16:17:24 +00:00
|
|
|
semverProcessor := sv.NewSemVerCommitsProcessor(cfg.IncludeUnknownTypeAsPatch, cfg.MajorVersionTypes, cfg.MinorVersionTypes, cfg.PatchVersionTypes)
|
|
|
|
releasenotesProcessor := sv.NewReleaseNoteProcessor(cfg.ReleaseNotesTags)
|
2020-02-02 01:40:31 +00:00
|
|
|
outputFormatter := sv.NewOutputFormatter()
|
2020-12-02 02:15:51 +00:00
|
|
|
validateMessageProcessor := sv.NewValidateMessageProcessor(cfg.ValidateMessageSkipBranches, cfg.CommitMessageTypes, cfg.IssueKeyName, cfg.BranchIssueRegex, cfg.IssueRegex)
|
2019-11-17 16:17:24 +00:00
|
|
|
|
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "sv"
|
2019-12-04 23:18:38 +00:00
|
|
|
app.Version = Version
|
2019-11-17 16:17:24 +00:00
|
|
|
app.Usage = "semantic version for git"
|
2020-02-01 21:37:16 +00:00
|
|
|
app.Commands = []*cli.Command{
|
2019-11-17 16:17:24 +00:00
|
|
|
{
|
|
|
|
Name: "current-version",
|
|
|
|
Aliases: []string{"cv"},
|
|
|
|
Usage: "get last released version from git",
|
|
|
|
Action: currentVersionHandler(git),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "next-version",
|
|
|
|
Aliases: []string{"nv"},
|
|
|
|
Usage: "generate the next version based on git commit messages",
|
|
|
|
Action: nextVersionHandler(git, semverProcessor),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "commit-log",
|
|
|
|
Aliases: []string{"cl"},
|
|
|
|
Usage: "list all commit logs since last version as jsons",
|
|
|
|
Action: commitLogHandler(git, semverProcessor),
|
2020-02-02 03:27:03 +00:00
|
|
|
Flags: []cli.Flag{&cli.StringFlag{Name: "t", Aliases: []string{"tag"}, Usage: "get commit log from tag"}},
|
2019-11-17 16:17:24 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "release-notes",
|
|
|
|
Aliases: []string{"rn"},
|
|
|
|
Usage: "generate release notes",
|
2020-02-02 01:40:31 +00:00
|
|
|
Action: releaseNotesHandler(git, semverProcessor, releasenotesProcessor, outputFormatter),
|
2020-02-02 03:27:03 +00:00
|
|
|
Flags: []cli.Flag{&cli.StringFlag{Name: "t", Aliases: []string{"tag"}, Usage: "get release note from tag"}},
|
2019-11-17 16:17:24 +00:00
|
|
|
},
|
2020-02-02 03:49:54 +00:00
|
|
|
{
|
|
|
|
Name: "changelog",
|
|
|
|
Aliases: []string{"cgl"},
|
|
|
|
Usage: "generate changelog",
|
|
|
|
Action: changelogHandler(git, semverProcessor, releasenotesProcessor, outputFormatter),
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.IntFlag{Name: "size", Value: 10, Aliases: []string{"n"}, Usage: "get changelog from last 'n' tags"},
|
|
|
|
&cli.BoolFlag{Name: "all", Usage: "ignore size parameter, get changelog for every tag"},
|
|
|
|
},
|
|
|
|
},
|
2019-12-04 22:37:50 +00:00
|
|
|
{
|
|
|
|
Name: "tag",
|
|
|
|
Aliases: []string{"tg"},
|
|
|
|
Usage: "generate tag with version based on git commit messages",
|
2020-02-02 01:40:31 +00:00
|
|
|
Action: tagHandler(git, semverProcessor),
|
2019-12-04 22:37:50 +00:00
|
|
|
},
|
2020-12-02 02:15:51 +00:00
|
|
|
{
|
|
|
|
Name: "commit",
|
|
|
|
Aliases: []string{"cmt"},
|
|
|
|
Usage: "execute git commit with convetional commit message helper",
|
|
|
|
Action: commitHandler(cfg, git, validateMessageProcessor),
|
|
|
|
},
|
2020-08-28 01:57:55 +00:00
|
|
|
{
|
|
|
|
Name: "validate-commit-message",
|
|
|
|
Aliases: []string{"vcm"},
|
|
|
|
Usage: "use as prepare-commit-message hook to validate message",
|
|
|
|
Action: validateCommitMessageHandler(git, validateMessageProcessor),
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{Name: "path", Required: true, Usage: "git working directory"},
|
|
|
|
&cli.StringFlag{Name: "file", Required: true, Usage: "name of the file that contains the commit log message"},
|
|
|
|
&cli.StringFlag{Name: "source", Required: true, Usage: "source of the commit message"},
|
|
|
|
},
|
|
|
|
},
|
2019-11-17 16:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
apperr := app.Run(os.Args)
|
|
|
|
if apperr != nil {
|
|
|
|
log.Fatal(apperr)
|
|
|
|
}
|
|
|
|
}
|