feat: auto get latest tags in interactive mode
parent
dc351c9a22
commit
2690142440
|
@ -31,6 +31,7 @@ type action struct {
|
|||
dryRun bool
|
||||
interactive bool
|
||||
interactiveFrom bool
|
||||
interactiveTo bool
|
||||
autoGitCommit bool
|
||||
autoGitTag bool
|
||||
autoGitPush bool
|
||||
|
@ -79,6 +80,7 @@ func (a *action) getFlags(c *cli.Context) {
|
|||
a.flags.dryRun = c.Bool(flagDryRunName)
|
||||
a.flags.interactive = c.Bool(flagInteractiveName)
|
||||
a.flags.interactiveFrom = c.Bool(flagInteractiveFromName)
|
||||
a.flags.interactiveTo = c.Bool(flagInteractiveToName)
|
||||
a.flags.autoGitCommit = c.Bool(flagAutoGitCommitName)
|
||||
a.flags.autoGitTag = c.Bool(flagAutoGitTagName)
|
||||
a.flags.autoGitPush = c.Bool(flagAutoGitPushName)
|
||||
|
|
|
@ -38,6 +38,7 @@ func (a *action) RunGenerate(c *cli.Context) error {
|
|||
return cli.ShowCommandHelp(c, commandGenerateName)
|
||||
}
|
||||
|
||||
useLatestTag := false
|
||||
if a.flags.interactive {
|
||||
fmt.Printf("Input version (%s):\n", flagVersionUsage)
|
||||
a.flags.version = ioe.ReadInput()
|
||||
|
@ -47,8 +48,12 @@ func (a *action) RunGenerate(c *cli.Context) error {
|
|||
a.flags.from = ioe.ReadInputEmpty()
|
||||
}
|
||||
|
||||
fmt.Printf("Input to (%s):\n", flagToUsage)
|
||||
a.flags.to = ioe.ReadInputEmpty()
|
||||
if a.flags.interactiveTo {
|
||||
fmt.Printf("Input to (%s):\n", flagToUsage)
|
||||
a.flags.to = ioe.ReadInputEmpty()
|
||||
} else {
|
||||
useLatestTag = true
|
||||
}
|
||||
}
|
||||
|
||||
repo, err := git.NewRepository(a.flags.repository)
|
||||
|
@ -56,6 +61,13 @@ func (a *action) RunGenerate(c *cli.Context) error {
|
|||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -22,10 +22,10 @@ const (
|
|||
flagVersionUsage = "`VERSION` to generate, follow Semantic Versioning"
|
||||
|
||||
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"
|
||||
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"
|
||||
flagScopeUsage = "scope to generate"
|
||||
|
@ -49,7 +49,10 @@ const (
|
|||
flagInteractiveUsage = "interactive mode"
|
||||
|
||||
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"
|
||||
flagAutoGitCommitUsage = "enable auto git commit after generating changelog"
|
||||
|
@ -133,6 +136,10 @@ func NewApp() *App {
|
|||
Name: flagInteractiveFromName,
|
||||
Usage: flagInteractiveFromUsage,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: flagInteractiveToName,
|
||||
Usage: flagInteractiveToUsage,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: flagAutoGitCommitName,
|
||||
Usage: flagAutoGitCommitUsage,
|
||||
|
|
Loading…
Reference in New Issue