From e523fd471ab8312c649c32c6e8a11deb3a1f2659 Mon Sep 17 00:00:00 2001 From: Sander Blue Date: Sun, 28 Mar 2021 22:17:21 -0500 Subject: [PATCH] feat: add `--sort [TYPE]` flag (#78) * feat(chglog): add --sort flag * chore(sort): update README with --sort usage --- README.md | 1 + cmd/git-chglog/config.go | 2 +- cmd/git-chglog/context.go | 1 + cmd/git-chglog/main.go | 8 ++++++++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ae43bbaf..17bbb9c9 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,7 @@ OPTIONS: --jira-url value Jira URL [$JIRA_URL] --jira-username value Jira username [$JIRA_USERNAME] --jira-token value Jira token [$JIRA_TOKEN] + --sort value Specify how to sort tags; currently supports "date" or by "semver" (default: date) --help, -h show help (default: false) --version, -v print the version (default: false) diff --git a/cmd/git-chglog/config.go b/cmd/git-chglog/config.go index f00985ba..98e22fbd 100644 --- a/cmd/git-chglog/config.go +++ b/cmd/git-chglog/config.go @@ -308,7 +308,7 @@ func (config *Config) Convert(ctx *CLIContext) *chglog.Config { Options: &chglog.Options{ NextTag: ctx.NextTag, TagFilterPattern: ctx.TagFilterPattern, - Sort: opts.Sort, + Sort: orValue(ctx.Sort, opts.Sort), NoCaseSensitive: ctx.NoCaseSensitive, Paths: ctx.Paths, CommitFilters: opts.Commits.Filters, diff --git a/cmd/git-chglog/context.go b/cmd/git-chglog/context.go index 65dea9db..39042663 100644 --- a/cmd/git-chglog/context.go +++ b/cmd/git-chglog/context.go @@ -24,6 +24,7 @@ type CLIContext struct { JiraToken string JiraURL string Paths []string + Sort string } // InitContext ... diff --git a/cmd/git-chglog/main.go b/cmd/git-chglog/main.go index 8503b149..7ad21f7d 100644 --- a/cmd/git-chglog/main.go +++ b/cmd/git-chglog/main.go @@ -178,6 +178,13 @@ func CreateApp(actionFunc cli.ActionFunc) *cli.App { EnvVars: []string{"JIRA_TOKEN"}, }, + // sort + &cli.StringFlag{ + Name: "sort", + Usage: "Specify how to sort tags; currently supports \"date\" or by \"semver\"", + DefaultText: "date", + }, + // help & version cli.HelpFlag, cli.VersionFlag, @@ -240,6 +247,7 @@ func AppAction(c *cli.Context) error { JiraToken: c.String("jira-token"), JiraURL: c.String("jira-url"), Paths: c.StringSlice("path"), + Sort: c.String("sort"), }, fs, NewConfigLoader(),