feat: auto get latest tags in interactive mode
parent
dc351c9a22
commit
2690142440
|
@ -31,6 +31,7 @@ type action struct {
|
||||||
dryRun bool
|
dryRun bool
|
||||||
interactive bool
|
interactive bool
|
||||||
interactiveFrom bool
|
interactiveFrom bool
|
||||||
|
interactiveTo bool
|
||||||
autoGitCommit bool
|
autoGitCommit bool
|
||||||
autoGitTag bool
|
autoGitTag bool
|
||||||
autoGitPush bool
|
autoGitPush bool
|
||||||
|
@ -79,6 +80,7 @@ func (a *action) getFlags(c *cli.Context) {
|
||||||
a.flags.dryRun = c.Bool(flagDryRunName)
|
a.flags.dryRun = c.Bool(flagDryRunName)
|
||||||
a.flags.interactive = c.Bool(flagInteractiveName)
|
a.flags.interactive = c.Bool(flagInteractiveName)
|
||||||
a.flags.interactiveFrom = c.Bool(flagInteractiveFromName)
|
a.flags.interactiveFrom = c.Bool(flagInteractiveFromName)
|
||||||
|
a.flags.interactiveTo = c.Bool(flagInteractiveToName)
|
||||||
a.flags.autoGitCommit = c.Bool(flagAutoGitCommitName)
|
a.flags.autoGitCommit = c.Bool(flagAutoGitCommitName)
|
||||||
a.flags.autoGitTag = c.Bool(flagAutoGitTagName)
|
a.flags.autoGitTag = c.Bool(flagAutoGitTagName)
|
||||||
a.flags.autoGitPush = c.Bool(flagAutoGitPushName)
|
a.flags.autoGitPush = c.Bool(flagAutoGitPushName)
|
||||||
|
|
|
@ -38,6 +38,7 @@ func (a *action) RunGenerate(c *cli.Context) error {
|
||||||
return cli.ShowCommandHelp(c, commandGenerateName)
|
return cli.ShowCommandHelp(c, commandGenerateName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useLatestTag := false
|
||||||
if a.flags.interactive {
|
if a.flags.interactive {
|
||||||
fmt.Printf("Input version (%s):\n", flagVersionUsage)
|
fmt.Printf("Input version (%s):\n", flagVersionUsage)
|
||||||
a.flags.version = ioe.ReadInput()
|
a.flags.version = ioe.ReadInput()
|
||||||
|
@ -47,8 +48,12 @@ func (a *action) RunGenerate(c *cli.Context) error {
|
||||||
a.flags.from = ioe.ReadInputEmpty()
|
a.flags.from = ioe.ReadInputEmpty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if a.flags.interactiveTo {
|
||||||
fmt.Printf("Input to (%s):\n", flagToUsage)
|
fmt.Printf("Input to (%s):\n", flagToUsage)
|
||||||
a.flags.to = ioe.ReadInputEmpty()
|
a.flags.to = ioe.ReadInputEmpty()
|
||||||
|
} else {
|
||||||
|
useLatestTag = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := git.NewRepository(a.flags.repository)
|
repo, err := git.NewRepository(a.flags.repository)
|
||||||
|
@ -56,6 +61,13 @@ func (a *action) RunGenerate(c *cli.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if useLatestTag {
|
||||||
|
tags, err := repo.SemVerTags()
|
||||||
|
if err == nil {
|
||||||
|
a.flags.to = tags[len(tags)-1].Version.Original()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
commits, err := repo.Log(a.flags.from, a.flags.to)
|
commits, err := repo.Log(a.flags.from, a.flags.to)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -22,10 +22,10 @@ const (
|
||||||
flagVersionUsage = "`VERSION` to generate, follow Semantic Versioning"
|
flagVersionUsage = "`VERSION` to generate, follow Semantic Versioning"
|
||||||
|
|
||||||
flagFromName = "from"
|
flagFromName = "from"
|
||||||
flagFromUsage = "from `COMMIT`, which is kinda new commit, default is latest commit"
|
flagFromUsage = "`FROM COMMIT`, which is kinda new commit, default is latest commit"
|
||||||
|
|
||||||
flagToName = "to"
|
flagToName = "to"
|
||||||
flagToUsage = "to `COMMIT`, which is kinda old commit, default is oldest commit"
|
flagToUsage = "`TO COMMIT`, which is kinda old commit, default is oldest commit"
|
||||||
|
|
||||||
flagScopeName = "scope"
|
flagScopeName = "scope"
|
||||||
flagScopeUsage = "scope to generate"
|
flagScopeUsage = "scope to generate"
|
||||||
|
@ -49,7 +49,10 @@ const (
|
||||||
flagInteractiveUsage = "interactive mode"
|
flagInteractiveUsage = "interactive mode"
|
||||||
|
|
||||||
flagInteractiveFromName = "interactive-from"
|
flagInteractiveFromName = "interactive-from"
|
||||||
flagInteractiveFromUsage = "enable ask from in interactive mode"
|
flagInteractiveFromUsage = "enable ask `FROM COMMIT` in interactive mode"
|
||||||
|
|
||||||
|
flagInteractiveToName = "interactive-to"
|
||||||
|
flagInteractiveToUsage = "enable ask `TO COMMIT` in interactive mode, otherwise use latest SemVer tag"
|
||||||
|
|
||||||
flagAutoGitCommitName = "auto-commit"
|
flagAutoGitCommitName = "auto-commit"
|
||||||
flagAutoGitCommitUsage = "enable auto git commit after generating changelog"
|
flagAutoGitCommitUsage = "enable auto git commit after generating changelog"
|
||||||
|
@ -133,6 +136,10 @@ func NewApp() *App {
|
||||||
Name: flagInteractiveFromName,
|
Name: flagInteractiveFromName,
|
||||||
Usage: flagInteractiveFromUsage,
|
Usage: flagInteractiveFromUsage,
|
||||||
},
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: flagInteractiveToName,
|
||||||
|
Usage: flagInteractiveToUsage,
|
||||||
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: flagAutoGitCommitName,
|
Name: flagAutoGitCommitName,
|
||||||
Usage: flagAutoGitCommitUsage,
|
Usage: flagAutoGitCommitUsage,
|
||||||
|
|
Loading…
Reference in New Issue