Skip to content

Commit 563a68f

Browse files
committed
chore: quick update feat/ver123 at 2025-09-13 11:42:24
1 parent eccc4e3 commit 563a68f

File tree

8 files changed

+98
-140
lines changed

8 files changed

+98
-140
lines changed

cmds/fastcommit/cmd.go

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package fastcommit
33
import (
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

cmds/fastcommit/ui.go

Lines changed: 0 additions & 61 deletions
This file was deleted.

cmds/tagcmd/cmd.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ func New() *cli.Command {
2525
defer recovery.Exit()
2626

2727
cmdutils.LoadConfigAndBranch()
28-
28+
2929
var p = tea.NewProgram(initialModel())
3030
m := assert.Must1(p.Run()).(model)
3131
selected := strings.TrimSpace(m.selected)
3232
if selected == "" {
3333
return nil
3434
}
3535

36-
tags := utils.GetAllGitTags()
36+
tags := utils.GetAllGitTags(ctx)
3737
ver := utils.GetNextTag(selected, tags)
3838
if selected == envRelease {
3939
ver = utils.GetNextReleaseTag(tags)
@@ -52,13 +52,13 @@ func New() *cli.Command {
5252
return errors.Errorf("tag name is not valid: %s", tagName)
5353
}
5454

55-
output := utils.GitPushTag(tagName)
55+
output := utils.GitPushTag(ctx, tagName)
5656
if utils.IsRemoteTagExist(output) {
5757
s := spinner.New(spinner.CharSets[35], 100*time.Millisecond, func(s *spinner.Spinner) {
5858
s.Prefix = "fetch git tag: "
5959
})
6060
s.Start()
61-
utils.GitFetchAll()
61+
utils.GitFetchAll(ctx)
6262
s.Stop()
6363
}
6464

cmds/upgradecmd/cmd.go

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package upgradecmd
22

33
import (
44
"context"
5-
"fmt"
65
"os"
76
"os/exec"
87
"path/filepath"
8+
"runtime"
99
"sort"
1010

1111
"github.com/hashicorp/go-getter"
@@ -35,18 +35,24 @@ func New() *cli.Command {
3535
releases := assert.Must1(client.List(ctx))
3636

3737
tt := tablewriter.NewWriter(os.Stdout)
38-
tt.Header([]string{"Name", "OS", "Arch", "Size", "Url"})
38+
tt.Header([]string{"Name", "Size", "Url"})
3939

4040
for _, r := range releases {
4141
for _, a := range githubclient.GetAssets(r) {
4242
if a.IsChecksumFile() {
4343
continue
4444
}
4545

46+
if a.OS != runtime.GOOS {
47+
continue
48+
}
49+
50+
if a.Arch != runtime.GOARCH {
51+
continue
52+
}
53+
4654
assert.Must(tt.Append([]string{
4755
a.Name,
48-
a.OS,
49-
a.Arch,
5056
githubclient.GetSizeFormat(a.Size),
5157
a.URL,
5258
}))
@@ -69,7 +75,9 @@ func New() *cli.Command {
6975
r := assert.Must1(client.List(ctx))
7076

7177
assets := githubclient.GetAssetList(r)
72-
assets = lo.Filter(assets, func(item githubclient.Asset, index int) bool { return !item.IsChecksumFile() })
78+
assets = lo.Filter(assets, func(item githubclient.Asset, index int) bool {
79+
return !item.IsChecksumFile() && item.OS == runtime.GOOS && item.Arch == runtime.GOARCH
80+
})
7381
sort.Slice(assets, func(i, j int) bool {
7482
return assert.Must1(version.NewSemver(assets[i].Name)).GreaterThan(lo.Must(version.NewSemver(assets[j].Name)))
7583
})
@@ -78,19 +86,24 @@ func New() *cli.Command {
7886
assets = assets[:20]
7987
}
8088

81-
result2 := tap.Select[string](context.Background(), tap.SelectOptions[string]{
89+
versionName := tap.Select[string](ctx, tap.SelectOptions[string]{
8290
Message: "Which frontend framework do you prefer?",
8391
Options: lo.Map(assets, func(item githubclient.Asset, index int) tap.SelectOption[string] {
8492
return tap.SelectOption[string]{
8593
Value: item.Name,
86-
Label: fmt.Sprintf("%s %s %s", item.Name, item.OS, item.Arch),
94+
Label: item.Name,
8795
}
8896
}),
8997
})
90-
fmt.Printf("\nYou chose: %s\n", result2)
9198

92-
asset, ok := lo.Find(assets, func(item githubclient.Asset) bool { return item.Name == result2 })
93-
assert.If(!ok, "%s not found", result2)
99+
if versionName == "" {
100+
return nil
101+
}
102+
103+
log.Info(ctx).Msgf("You chose: %s", versionName)
104+
105+
asset, ok := lo.Find(assets, func(item githubclient.Asset) bool { return item.Name == versionName })
106+
assert.If(!ok, "%s not found", versionName)
94107
var downloadURL = asset.URL
95108

96109
downloadDir := filepath.Join(os.TempDir(), "fastcommit")

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@ require (
2727
github.com/olekukonko/tablewriter v1.0.8
2828
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
2929
github.com/pubgo/dix v0.3.21
30-
github.com/pubgo/funk v0.5.69-alpha.21
30+
github.com/pubgo/funk v0.5.69-alpha.23
3131
github.com/rs/zerolog v1.34.0
3232
github.com/samber/lo v1.51.0
3333
github.com/sashabaranov/go-openai v1.40.5
3434
github.com/stretchr/testify v1.10.0
3535
github.com/urfave/cli/v3 v3.4.1
3636
github.com/yarlson/tap v0.9.0
3737
gopkg.in/yaml.v3 v3.0.1
38+
mvdan.cc/sh/v3 v3.12.0
3839
)
3940

4041
require (
@@ -140,5 +141,4 @@ require (
140141
google.golang.org/genproto/googleapis/rpc v0.0.0-20250603155806-513f23925822 // indirect
141142
google.golang.org/grpc v1.73.0 // indirect
142143
google.golang.org/protobuf v1.36.6 // indirect
143-
mvdan.cc/sh/v3 v3.12.0 // indirect
144144
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,8 +866,8 @@ github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOA
866866
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
867867
github.com/pubgo/dix v0.3.21 h1:jtriLYT6srKrxv0KRwic1no0d9ZTMtLx6r3JJxQ5Jvw=
868868
github.com/pubgo/dix v0.3.21/go.mod h1:5qHJ7ycvBVw1AUjgYMEsobzx1tggiRs+spgzd4Jglb4=
869-
github.com/pubgo/funk v0.5.69-alpha.21 h1:11EOPrkradItiy5bzL/Wn18QWZ7HWFSrXVD2BmEdmqY=
870-
github.com/pubgo/funk v0.5.69-alpha.21/go.mod h1:dBFx3ZnM6IML9tqK23ROTB9xX0Q27dLXUxAoSuh5mMI=
869+
github.com/pubgo/funk v0.5.69-alpha.23 h1:Qhs3HRU2wIWGbCegyDibXJgf2dfFl30QTiCWyRj6r8A=
870+
github.com/pubgo/funk v0.5.69-alpha.23/go.mod h1:dBFx3ZnM6IML9tqK23ROTB9xX0Q27dLXUxAoSuh5mMI=
871871
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
872872
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
873873
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=

0 commit comments

Comments
 (0)