mirror of
https://github.com/git-chglog/git-chglog.git
synced 2026-07-21 02:11:56 +00:00
feat: Add --tag-filter-pattern flag.
This flag specifies a regular expression and only matched tags will be included in change log. Closes #43
This commit is contained in:
parent
63a4e63702
commit
1198e283de
10 changed files with 222 additions and 65 deletions
|
|
@ -258,6 +258,7 @@ func (config *Config) Convert(ctx *CLIContext) *chglog.Config {
|
|||
},
|
||||
Options: &chglog.Options{
|
||||
NextTag: ctx.NextTag,
|
||||
TagFilterPattern: ctx.TagFilterPattern,
|
||||
CommitFilters: opts.Commits.Filters,
|
||||
CommitSortBy: opts.Commits.SortBy,
|
||||
CommitGroupBy: opts.CommitGroups.GroupBy,
|
||||
|
|
|
|||
|
|
@ -6,16 +6,17 @@ import (
|
|||
|
||||
// CLIContext ...
|
||||
type CLIContext struct {
|
||||
WorkingDir string
|
||||
Stdout io.Writer
|
||||
Stderr io.Writer
|
||||
ConfigPath string
|
||||
OutputPath string
|
||||
Silent bool
|
||||
NoColor bool
|
||||
NoEmoji bool
|
||||
Query string
|
||||
NextTag string
|
||||
WorkingDir string
|
||||
Stdout io.Writer
|
||||
Stderr io.Writer
|
||||
ConfigPath string
|
||||
OutputPath string
|
||||
Silent bool
|
||||
NoColor bool
|
||||
NoEmoji bool
|
||||
Query string
|
||||
NextTag string
|
||||
TagFilterPattern string
|
||||
}
|
||||
|
||||
// InitContext ...
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import (
|
|||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func main() {
|
||||
func CreateApp(actionFunc cli.ActionFunc) *cli.App {
|
||||
ttl := color.New(color.FgYellow).SprintFunc()
|
||||
|
||||
cli.AppHelpTemplate = fmt.Sprintf(`
|
||||
|
|
@ -114,63 +114,77 @@ func main() {
|
|||
EnvVar: "NO_EMOJI",
|
||||
},
|
||||
|
||||
// tag-filter-pattern
|
||||
cli.StringFlag{
|
||||
Name: "tag-filter-pattern, p",
|
||||
Usage: "Regular expression of tag filter. Is specified, only matched tags will be picked",
|
||||
},
|
||||
|
||||
// help & version
|
||||
cli.HelpFlag,
|
||||
cli.VersionFlag,
|
||||
}
|
||||
|
||||
app.Action = func(c *cli.Context) error {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to get working directory", err)
|
||||
os.Exit(ExitCodeError)
|
||||
}
|
||||
app.Action = actionFunc
|
||||
|
||||
// initializer
|
||||
if c.Bool("init") {
|
||||
initializer := NewInitializer(
|
||||
&InitContext{
|
||||
WorkingDir: wd,
|
||||
Stdout: colorable.NewColorableStdout(),
|
||||
Stderr: colorable.NewColorableStderr(),
|
||||
},
|
||||
fs,
|
||||
NewQuestioner(
|
||||
gitcmd.New(&gitcmd.Config{
|
||||
Bin: "git",
|
||||
}),
|
||||
fs,
|
||||
),
|
||||
NewConfigBuilder(),
|
||||
templateBuilderFactory,
|
||||
)
|
||||
return app
|
||||
}
|
||||
|
||||
os.Exit(initializer.Run())
|
||||
}
|
||||
func AppAction(c *cli.Context) error {
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "failed to get working directory", err)
|
||||
os.Exit(ExitCodeError)
|
||||
}
|
||||
|
||||
// chglog
|
||||
chglogCLI := NewCLI(
|
||||
&CLIContext{
|
||||
// initializer
|
||||
if c.Bool("init") {
|
||||
initializer := NewInitializer(
|
||||
&InitContext{
|
||||
WorkingDir: wd,
|
||||
Stdout: colorable.NewColorableStdout(),
|
||||
Stderr: colorable.NewColorableStderr(),
|
||||
ConfigPath: c.String("config"),
|
||||
OutputPath: c.String("output"),
|
||||
Silent: c.Bool("silent"),
|
||||
NoColor: c.Bool("no-color"),
|
||||
NoEmoji: c.Bool("no-emoji"),
|
||||
Query: c.Args().First(),
|
||||
NextTag: c.String("next-tag"),
|
||||
},
|
||||
fs,
|
||||
NewConfigLoader(),
|
||||
NewGenerator(),
|
||||
NewQuestioner(
|
||||
gitcmd.New(&gitcmd.Config{
|
||||
Bin: "git",
|
||||
}),
|
||||
fs,
|
||||
),
|
||||
NewConfigBuilder(),
|
||||
templateBuilderFactory,
|
||||
)
|
||||
|
||||
os.Exit(chglogCLI.Run())
|
||||
|
||||
return nil
|
||||
os.Exit(initializer.Run())
|
||||
}
|
||||
|
||||
// chglog
|
||||
chglogCLI := NewCLI(
|
||||
&CLIContext{
|
||||
WorkingDir: wd,
|
||||
Stdout: colorable.NewColorableStdout(),
|
||||
Stderr: colorable.NewColorableStderr(),
|
||||
ConfigPath: c.String("config"),
|
||||
OutputPath: c.String("output"),
|
||||
Silent: c.Bool("silent"),
|
||||
NoColor: c.Bool("no-color"),
|
||||
NoEmoji: c.Bool("no-emoji"),
|
||||
Query: c.Args().First(),
|
||||
NextTag: c.String("next-tag"),
|
||||
TagFilterPattern: c.String("tag-filter-pattern"),
|
||||
},
|
||||
fs,
|
||||
NewConfigLoader(),
|
||||
NewGenerator(),
|
||||
)
|
||||
|
||||
os.Exit(chglogCLI.Run())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := CreateApp(AppAction)
|
||||
app.Run(os.Args)
|
||||
}
|
||||
|
|
|
|||
40
cmd/git-chglog/main_test.go
Normal file
40
cmd/git-chglog/main_test.go
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/urfave/cli"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var gAssert *assert.Assertions
|
||||
|
||||
func mock_app_action(c *cli.Context) error {
|
||||
assert := gAssert
|
||||
assert.Equal("c.yml", c.String("config"))
|
||||
assert.Equal("^v", c.String("tag-filter-pattern"))
|
||||
assert.Equal("o.md", c.String("output"))
|
||||
assert.Equal("v5", c.String("next-tag"))
|
||||
assert.True(c.Bool("silent"))
|
||||
assert.True(c.Bool("no-color"))
|
||||
assert.True(c.Bool("no-emoji"))
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestCreateApp(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
assert.True(true)
|
||||
gAssert = assert
|
||||
|
||||
app := CreateApp(mock_app_action)
|
||||
args := []string {
|
||||
"git-chglog",
|
||||
"--silent",
|
||||
"--no-color",
|
||||
"--no-emoji",
|
||||
"--config", "c.yml",
|
||||
"--output", "o.md",
|
||||
"--next-tag", "v5",
|
||||
"--tag-filter-pattern", "^v",
|
||||
}
|
||||
app.Run(args)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue