@@ -3,7 +3,6 @@ package fastcommit
33import (
44 "context"
55 "fmt"
6- "github.com/yarlson/tap"
76 "os"
87 "sort"
98 "strconv"
@@ -20,6 +19,7 @@ import (
2019 "github.com/pubgo/funk/v2/result"
2120 "github.com/sashabaranov/go-openai"
2221 "github.com/urfave/cli/v3"
22+ "github.com/yarlson/tap"
2323
2424 "github.com/pubgo/fastcommit/cmds/cmdutils"
2525 "github.com/pubgo/fastcommit/configs"
@@ -77,14 +77,13 @@ func New(version string) func(params Params) *Command {
7777 if errors .Is (err , context .Canceled ) {
7878 return nil
7979 }
80- return err
81- })
8280
83- defer func () {
84- if errors .Is (gErr , context .Canceled ) {
85- gErr = nil
81+ if err .Error () == "signal: interrupt" {
82+ return nil
8683 }
87- }()
84+
85+ return err
86+ })
8887
8988 if command .Args ().Len () > 0 {
9089 log .Error (ctx ).Msgf ("unknown command:%v" , command .Args ().Slice ())
@@ -99,37 +98,44 @@ func New(version string) func(params Params) *Command {
9998
10099 cmdutils .LoadConfigAndBranch ()
101100
102- allTags := utils .GetAllGitTags ()
101+ allTags := utils .GetAllGitTags (ctx )
103102 tagName := "v0.0.1"
104103 if len (allTags ) > 0 {
105104 ver := utils .GetNextReleaseTag (allTags )
106105 tagName = "v" + strings .TrimPrefix (ver .Original (), "v" )
107106 }
108107 assert .Exit (os .WriteFile (".version" , []byte (tagName ), 0644 ))
109108
110- repoPath := assert .Must1 (utils .AssertGitRepo ())
109+ repoPath := assert .Must1 (utils .AssertGitRepo (ctx ))
111110 log .Info ().Msg ("git repo: " + repoPath )
112111
113112 //username := strings.TrimSpace(assert.Must1(utils.RunOutput("git", "config", "get", "user.name")))
114113
115114 if flags .fastCommit {
116- preMsg := strings .TrimSpace (assert .Must1 (utils .RunOutput ("git" , "log" , "-1" , "--pretty=%B" )))
115+ preMsg := strings .TrimSpace (assert .Must1 (utils .RunOutput (ctx , "git" , "log" , "-1" , "--pretty=%B" )))
117116 prefixMsg := fmt .Sprintf ("chore: quick update %s" , cmdutils .GetBranchName ())
118117 msg := fmt .Sprintf ("%s at %s" , prefixMsg , time .Now ().Format (time .DateTime ))
119118
120- assert .Must (utils .RunShell ("git" , "add" , "-A" ))
119+ assert .Must (utils .RunShell (ctx , "git" , "add" , "-A" ))
121120 if strings .Contains (preMsg , prefixMsg ) {
122- assert .Must (utils .RunShell ("git" , "commit" , "--amend" , "--no-edit" , "-m" , strconv .Quote (msg )))
121+ assert .Must (utils .RunShell (ctx , "git" , "commit" , "--amend" , "--no-edit" , "-m" , strconv .Quote (msg )))
123122 } else {
124- assert .Must (utils .RunShell ("git" , "commit" , "-m" , strconv .Quote (msg )))
123+ assert .Must (utils .RunShell (ctx , "git" , "commit" , "-m" , strconv .Quote (msg )))
125124 }
126- assert .Must (utils .RunShell ("git" , "push" , "--force-with-lease" , "origin" , cmdutils .GetBranchName ()))
125+
126+ s := spinner .New (spinner .CharSets [35 ], 100 * time .Millisecond , func (s * spinner.Spinner ) {
127+ s .Prefix = "push git message: "
128+ })
129+ s .Start ()
130+ result .ErrOf (utils .RunShell (ctx , "git" , "push" , "--force-with-lease" , "origin" , cmdutils .GetBranchName ())).
131+ Log ().Must ()
132+ s .Stop ()
127133 return
128134 }
129135
130- assert .Must (utils .RunShell ("git" , "add" , "--update" ))
136+ assert .Must (utils .RunShell (ctx , "git" , "add" , "--update" ))
131137
132- diff := assert .Must1 (utils .GetStagedDiff (nil ))
138+ diff := assert .Must1 (utils .GetStagedDiff (ctx ))
133139 if diff == nil || len (diff .Files ) == 0 {
134140 return nil
135141 }
@@ -172,31 +178,24 @@ func New(version string) func(params Params) *Command {
172178 }
173179
174180 msg := resp .Choices [0 ].Message .Content
175- msg = tap .Text (ctx , tap.TextOptions {
176- Message : "git message(update or enter) >> " ,
181+ msg = strings . TrimSpace ( tap .Text (ctx , tap.TextOptions {
182+ Message : "git message(update or enter): " ,
177183 InitialValue : msg ,
178184 DefaultValue : msg ,
179185 Placeholder : "update or enter" ,
180- })
186+ }))
181187
182188 if msg == "" {
183189 return
184190 }
185191
186- //var p1 = tea.NewProgram(initialTextInputModel(msg))
187- //mm := assert.Must1(p1.Run()).(model2)
188- //if mm.isExit() {
189- // return nil
190- //}
191-
192- //msg = mm.Value()
193- assert .Must (utils .RunShell ("git" , "commit" , "-m" , strconv .Quote (msg )))
194- assert .Must (utils .RunShell ("git" , "push" , "origin" , cmdutils .GetBranchName ()))
192+ assert .Must (utils .RunShell (ctx , "git" , "commit" , "-m" , strconv .Quote (msg )))
193+ assert .Must (utils .RunShell (ctx , "git" , "push" , "origin" , cmdutils .GetBranchName ()))
195194 if flags .showPrompt {
196195 fmt .Println ("\n " + generatePrompt + "\n " )
197196 }
198197 log .Info ().Any ("usage" , resp .Usage ).Msg ("openai response usage" )
199- return nil
198+ return
200199 },
201200 }
202201
0 commit comments