mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-11-13 21:30:40 +00:00
2d2de1a5e0
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Robert Kaussow <mail@thegeeklab.de>
143 lines
4.2 KiB
Go
143 lines
4.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/rs/zerolog"
|
|
"github.com/rs/zerolog/log"
|
|
|
|
"github.com/thegeeklab/git-sv/app"
|
|
"github.com/thegeeklab/git-sv/app/commands"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
//nolint:gochecknoglobals
|
|
var (
|
|
BuildVersion = "devel"
|
|
BuildDate = "00000000"
|
|
)
|
|
|
|
func main() {
|
|
gsv := app.New()
|
|
|
|
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
|
cli.VersionPrinter = func(c *cli.Context) {
|
|
fmt.Printf("%s version=%s date=%s\n", c.App.Name, c.App.Version, BuildDate)
|
|
}
|
|
|
|
app := &cli.App{
|
|
Name: "git-sv",
|
|
Usage: "Semantic version for git.",
|
|
Version: BuildVersion,
|
|
Flags: []cli.Flag{
|
|
&cli.StringFlag{
|
|
Name: "log-level",
|
|
Usage: "log level",
|
|
Value: "info",
|
|
Destination: &gsv.Settings.LogLevel,
|
|
},
|
|
},
|
|
Before: func(_ *cli.Context) error {
|
|
lvl, err := zerolog.ParseLevel(gsv.Settings.LogLevel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
zerolog.SetGlobalLevel(lvl)
|
|
|
|
return nil
|
|
},
|
|
Commands: []*cli.Command{
|
|
{
|
|
Name: "config",
|
|
Aliases: []string{"cfg"},
|
|
Usage: "cli configuration",
|
|
Subcommands: []*cli.Command{
|
|
{
|
|
Name: "default",
|
|
Usage: "show default config",
|
|
Action: commands.ConfigDefaultHandler(),
|
|
},
|
|
{
|
|
Name: "show",
|
|
Usage: "show current config",
|
|
Action: commands.ConfigShowHandler(gsv.Config),
|
|
},
|
|
},
|
|
},
|
|
{
|
|
Name: "current-version",
|
|
Aliases: []string{"cv"},
|
|
Usage: "get last released version from git",
|
|
Action: commands.CurrentVersionHandler(gsv),
|
|
},
|
|
{
|
|
Name: "next-version",
|
|
Aliases: []string{"nv"},
|
|
Usage: "generate the next version based on git commit messages",
|
|
Action: commands.NextVersionHandler(gsv),
|
|
},
|
|
{
|
|
Name: "commit-log",
|
|
Aliases: []string{"cl"},
|
|
Usage: "list all commit logs according to range as json",
|
|
Description: `The range filter is used based on git log filters, check https://git-scm.com/docs/git-log
|
|
for more info. When flag range is "tag" and start is empty, last tag created will be used instead.
|
|
When flag range is "date", if "end" is YYYY-MM-DD the range will be inclusive.`,
|
|
Action: commands.CommitLogHandler(gsv, &gsv.Settings.CommitLogSettings),
|
|
Flags: commands.CommitLogFlags(&gsv.Settings.CommitLogSettings),
|
|
},
|
|
{
|
|
Name: "commit-notes",
|
|
Aliases: []string{"cn"},
|
|
Usage: "generate a commit notes according to range",
|
|
Description: `The range filter is used based on git log filters, check https://git-scm.com/docs/git-log
|
|
for more info. When flag range is "tag" and start is empty, last tag created will be used instead.
|
|
When flag range is "date", if "end" is YYYY-MM-DD the range will be inclusive.`,
|
|
Action: commands.CommitNotesHandler(gsv, &gsv.Settings.CommitNotesSettings),
|
|
Flags: commands.CommitNotesFlags(&gsv.Settings.CommitNotesSettings),
|
|
},
|
|
{
|
|
Name: "release-notes",
|
|
Aliases: []string{"rn"},
|
|
Usage: "generate release notes",
|
|
Action: commands.ReleaseNotesHandler(gsv, &gsv.Settings.ReleaseNotesSettings),
|
|
Flags: commands.ReleaseNotesFlags(&gsv.Settings.ReleaseNotesSettings),
|
|
},
|
|
{
|
|
Name: "changelog",
|
|
Aliases: []string{"cgl"},
|
|
Usage: "generate changelog",
|
|
Action: commands.ChangelogHandler(gsv, &gsv.Settings.ChangelogSettings),
|
|
Flags: commands.ChangelogFlags(&gsv.Settings.ChangelogSettings),
|
|
},
|
|
{
|
|
Name: "tag",
|
|
Aliases: []string{"tg"},
|
|
Usage: "generate tag with version based on git commit messages",
|
|
Action: commands.TagHandler(gsv, &gsv.Settings.TagSettings),
|
|
Flags: commands.TagFlags(&gsv.Settings.TagSettings),
|
|
},
|
|
{
|
|
Name: "commit",
|
|
Aliases: []string{"cmt"},
|
|
Usage: "execute git commit with conventional commit message helper",
|
|
Action: commands.CommitHandler(gsv),
|
|
Flags: commands.CommitFlags(),
|
|
},
|
|
{
|
|
Name: "validate-commit-message",
|
|
Aliases: []string{"vcm"},
|
|
Usage: "use as prepare-commit-message hook to validate and enhance commit message",
|
|
Action: commands.ValidateCommitMessageHandler(gsv),
|
|
Flags: commands.ValidateCommitMessageFlags(),
|
|
},
|
|
},
|
|
}
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
log.Fatal().Err(err).Msg("Execution error")
|
|
}
|
|
}
|