@@ -3,6 +3,7 @@ package tagcmd
33import (
44 "context"
55 "fmt"
6+ "sort"
67 "strings"
78 "time"
89
@@ -12,6 +13,7 @@ import (
1213 "github.com/pubgo/funk/v2/errors"
1314 "github.com/pubgo/funk/v2/recovery"
1415 "github.com/pubgo/funk/v2/result"
16+ "github.com/samber/lo"
1517 "github.com/urfave/cli/v3"
1618 "github.com/yarlson/tap"
1719
@@ -62,19 +64,43 @@ func New() *cli.Command {
6264 utils .LogConfigAndBranch ()
6365
6466 if flags .fastCommit {
65- tagName := strings .TrimSpace (tap .Text (ctx , tap.TextOptions {
67+ tags := utils .GetAllGitTags (ctx )
68+
69+ sort .Slice (tags , func (i , j int ) bool { return tags [i ].GreaterThanOrEqual (tags [j ]) })
70+ selectTags := lo .Map (tags , func (item * semver.Version , index int ) tap.SelectOption [* semver.Version ] {
71+ return tap.SelectOption [* semver.Version ]{
72+ Value : item ,
73+ Label : item .Original (),
74+ }
75+ })
76+ selectTags = lo .Chunk (selectTags , 10 )[0 ]
77+
78+ tagResult := tap .Select [* semver.Version ](ctx , tap.SelectOptions [* semver.Version ]{
79+ Message : "git tag(enter):" ,
80+ Options : selectTags ,
81+ })
82+
83+ if tagResult == nil {
84+ return nil
85+ }
86+
87+ tagName := tap .Text (ctx , tap.TextOptions {
6688 Message : "git tag(enter):" ,
67- DefaultValue : "v0.0.1" ,
68- Placeholder : "enter a tag" ,
89+ InitialValue : tagResult .Original (),
90+ DefaultValue : tagResult .Original (),
91+ Placeholder : "enter git tag" ,
6992 Validate : func (s string ) error {
7093 if ! strings .HasPrefix (s , "v" ) {
7194 return fmt .Errorf ("tag name must start with v" )
7295 }
7396
7497 _ , err := semver .NewSemver (s )
98+ if err == nil {
99+ return nil
100+ }
75101 return fmt .Errorf ("tag is invalid, tag=%s err=%w" , s , err )
76102 },
77- }))
103+ })
78104
79105 if tagName == "" {
80106 return fmt .Errorf ("tag name is empty" )
0 commit comments