2019-11-17 17:17:24 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-10-12 16:18:25 +02:00
|
|
|
"fmt"
|
2019-11-17 17:17:24 +01:00
|
|
|
"os"
|
2021-07-23 01:07:18 +02:00
|
|
|
|
2023-10-15 21:29:29 +02:00
|
|
|
"github.com/rs/zerolog"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
|
2023-10-16 21:41:33 +02:00
|
|
|
"github.com/thegeeklab/git-sv/app"
|
|
|
|
"github.com/thegeeklab/git-sv/app/commands"
|
2020-02-01 22:37:16 +01:00
|
|
|
"github.com/urfave/cli/v2"
|
2019-11-17 17:17:24 +01:00
|
|
|
)
|
|
|
|
|
2023-10-12 16:18:25 +02:00
|
|
|
//nolint:gochecknoglobals
|
|
|
|
var (
|
|
|
|
BuildVersion = "devel"
|
|
|
|
BuildDate = "00000000"
|
|
|
|
)
|
2019-12-05 00:18:38 +01:00
|
|
|
|
2019-11-17 17:17:24 +01:00
|
|
|
func main() {
|
2023-10-15 21:29:29 +02:00
|
|
|
gsv := app.New()
|
2023-10-16 00:29:02 +02:00
|
|
|
|
2023-10-17 15:23:29 +02:00
|
|
|
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
2023-10-12 16:18:25 +02:00
|
|
|
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,
|
2023-10-15 21:29:29 +02:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
&cli.StringFlag{
|
2023-10-16 00:29:02 +02:00
|
|
|
Name: "log-level",
|
|
|
|
Usage: "log level",
|
|
|
|
Value: "info",
|
|
|
|
Destination: &gsv.Settings.LogLevel,
|
2023-10-15 21:29:29 +02:00
|
|
|
},
|
|
|
|
},
|
2024-02-12 09:09:42 +01:00
|
|
|
Before: func(_ *cli.Context) error {
|
2023-10-16 00:29:02 +02:00
|
|
|
lvl, err := zerolog.ParseLevel(gsv.Settings.LogLevel)
|
2023-10-15 21:29:29 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
zerolog.SetGlobalLevel(lvl)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
2023-10-12 16:18:25 +02:00
|
|
|
Commands: []*cli.Command{
|
|
|
|
{
|
|
|
|
Name: "config",
|
|
|
|
Aliases: []string{"cfg"},
|
|
|
|
Usage: "cli configuration",
|
|
|
|
Subcommands: []*cli.Command{
|
|
|
|
{
|
|
|
|
Name: "default",
|
|
|
|
Usage: "show default config",
|
2023-10-15 21:29:29 +02:00
|
|
|
Action: commands.ConfigDefaultHandler(),
|
2023-10-12 16:18:25 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "show",
|
|
|
|
Usage: "show current config",
|
2023-10-15 21:29:29 +02:00
|
|
|
Action: commands.ConfigShowHandler(gsv.Config),
|
2023-10-12 16:18:25 +02:00
|
|
|
},
|
2021-02-14 23:42:22 +01:00
|
|
|
},
|
|
|
|
},
|
2023-10-12 16:18:25 +02:00
|
|
|
{
|
|
|
|
Name: "current-version",
|
|
|
|
Aliases: []string{"cv"},
|
|
|
|
Usage: "get last released version from git",
|
2023-10-15 21:29:29 +02:00
|
|
|
Action: commands.CurrentVersionHandler(gsv),
|
2021-01-25 21:16:56 +01:00
|
|
|
},
|
2023-10-12 16:18:25 +02:00
|
|
|
{
|
|
|
|
Name: "next-version",
|
|
|
|
Aliases: []string{"nv"},
|
|
|
|
Usage: "generate the next version based on git commit messages",
|
2023-10-15 21:29:29 +02:00
|
|
|
Action: commands.NextVersionHandler(gsv),
|
2021-01-25 06:51:42 +01:00
|
|
|
},
|
2023-10-12 16:18:25 +02:00
|
|
|
{
|
|
|
|
Name: "commit-log",
|
|
|
|
Aliases: []string{"cl"},
|
2023-10-12 17:26:56 +02:00
|
|
|
Usage: "list all commit logs according to range as json",
|
2023-10-12 16:18:25 +02:00
|
|
|
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.`,
|
2023-10-17 09:52:28 +02:00
|
|
|
Action: commands.CommitLogHandler(gsv, &gsv.Settings.CommitLogSettings),
|
|
|
|
Flags: commands.CommitLogFlags(&gsv.Settings.CommitLogSettings),
|
2020-02-02 04:49:54 +01:00
|
|
|
},
|
2023-10-12 16:18:25 +02:00
|
|
|
{
|
|
|
|
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.`,
|
2023-10-17 09:52:28 +02:00
|
|
|
Action: commands.CommitNotesHandler(gsv, &gsv.Settings.CommitNotesSettings),
|
2023-10-16 00:29:02 +02:00
|
|
|
Flags: commands.CommitNotesFlags(&gsv.Settings.CommitNotesSettings),
|
2021-07-31 05:47:58 +02:00
|
|
|
},
|
2023-10-12 16:18:25 +02:00
|
|
|
{
|
|
|
|
Name: "release-notes",
|
|
|
|
Aliases: []string{"rn"},
|
|
|
|
Usage: "generate release notes",
|
2023-10-17 09:52:28 +02:00
|
|
|
Action: commands.ReleaseNotesHandler(gsv, &gsv.Settings.ReleaseNotesSettings),
|
2023-10-16 00:29:02 +02:00
|
|
|
Flags: commands.ReleaseNotesFlags(&gsv.Settings.ReleaseNotesSettings),
|
2023-10-12 16:18:25 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "changelog",
|
|
|
|
Aliases: []string{"cgl"},
|
|
|
|
Usage: "generate changelog",
|
2023-10-17 09:52:28 +02:00
|
|
|
Action: commands.ChangelogHandler(gsv, &gsv.Settings.ChangelogSettings),
|
2023-10-16 00:29:02 +02:00
|
|
|
Flags: commands.ChangelogFlags(&gsv.Settings.ChangelogSettings),
|
2023-10-12 16:18:25 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "tag",
|
|
|
|
Aliases: []string{"tg"},
|
|
|
|
Usage: "generate tag with version based on git commit messages",
|
2023-10-18 15:51:05 +02:00
|
|
|
Action: commands.TagHandler(gsv, &gsv.Settings.TagSettings),
|
|
|
|
Flags: commands.TagFlags(&gsv.Settings.TagSettings),
|
2023-10-12 16:18:25 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "commit",
|
|
|
|
Aliases: []string{"cmt"},
|
2023-10-12 17:26:56 +02:00
|
|
|
Usage: "execute git commit with conventional commit message helper",
|
2023-10-15 21:29:29 +02:00
|
|
|
Action: commands.CommitHandler(gsv),
|
|
|
|
Flags: commands.CommitFlags(),
|
2023-10-12 16:18:25 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "validate-commit-message",
|
|
|
|
Aliases: []string{"vcm"},
|
|
|
|
Usage: "use as prepare-commit-message hook to validate and enhance commit message",
|
2023-10-15 21:29:29 +02:00
|
|
|
Action: commands.ValidateCommitMessageHandler(gsv),
|
|
|
|
Flags: commands.ValidateCommitMessageFlags(),
|
2020-08-28 03:57:55 +02:00
|
|
|
},
|
|
|
|
},
|
2019-11-17 17:17:24 +01:00
|
|
|
}
|
|
|
|
|
2023-10-15 22:20:39 +02:00
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
log.Fatal().Err(err).Msg("Execution error")
|
2021-08-01 00:05:22 +02:00
|
|
|
}
|
|
|
|
}
|