Skip to content

Commit dccd7e7

Browse files
committed
chore: quick update feat/ver123 at 2025-09-13 12:58:02
1 parent eccc4e3 commit dccd7e7

File tree

10 files changed

+124
-153
lines changed

10 files changed

+124
-153
lines changed

bootstrap/boot.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package bootstrap
22

33
import (
4+
"log/slog"
5+
46
_ "github.com/adrg/xdg"
57
_ "github.com/charmbracelet/bubbletea"
68
"github.com/pubgo/dix"
79
"github.com/pubgo/funk/config"
10+
"github.com/pubgo/funk/log"
811
"github.com/pubgo/funk/recovery"
912
_ "github.com/sashabaranov/go-openai"
1013

@@ -22,6 +25,8 @@ import (
2225
func Main(ver string) {
2326
defer recovery.Exit()
2427

28+
slog.SetDefault(slog.New(log.NewSlog(log.GetLogger("fastcommit"))))
29+
2530
initConfig()
2631

2732
var di = dix.New(dix.WithValuesNull())

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: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ package tagcmd
22

33
import (
44
"context"
5-
"strings"
6-
"time"
7-
8-
"github.com/briandowns/spinner"
95
tea "github.com/charmbracelet/bubbletea"
106
semver "github.com/hashicorp/go-version"
117
"github.com/pubgo/funk/assert"
128
"github.com/pubgo/funk/errors"
139
"github.com/pubgo/funk/recovery"
10+
"github.com/pubgo/funk/v2/result"
1411
"github.com/urfave/cli/v3"
12+
"strings"
1513

1614
"github.com/pubgo/fastcommit/cmds/cmdutils"
1715
"github.com/pubgo/fastcommit/utils"
@@ -25,15 +23,15 @@ func New() *cli.Command {
2523
defer recovery.Exit()
2624

2725
cmdutils.LoadConfigAndBranch()
28-
26+
2927
var p = tea.NewProgram(initialModel())
3028
m := assert.Must1(p.Run()).(model)
3129
selected := strings.TrimSpace(m.selected)
3230
if selected == "" {
3331
return nil
3432
}
3533

36-
tags := utils.GetAllGitTags()
34+
tags := utils.GetAllGitTags(ctx)
3735
ver := utils.GetNextTag(selected, tags)
3836
if selected == envRelease {
3937
ver = utils.GetNextReleaseTag(tags)
@@ -52,14 +50,14 @@ func New() *cli.Command {
5250
return errors.Errorf("tag name is not valid: %s", tagName)
5351
}
5452

55-
output := utils.GitPushTag(tagName)
53+
output := utils.Spin("push tag: ", func() (r result.Result[string]) {
54+
return r.WithValue(utils.GitPushTag(ctx, tagName))
55+
}).Log().Must()
5656
if utils.IsRemoteTagExist(output) {
57-
s := spinner.New(spinner.CharSets[35], 100*time.Millisecond, func(s *spinner.Spinner) {
58-
s.Prefix = "fetch git tag: "
57+
utils.Spin("fetch git tag: ", func() (r result.Result[any]) {
58+
utils.GitFetchAll(ctx)
59+
return
5960
})
60-
s.Start()
61-
utils.GitFetchAll()
62-
s.Stop()
6361
}
6462

6563
return nil

cmds/upgradecmd/cmd.go

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

33
import (
44
"context"
5-
"fmt"
5+
"github.com/pubgo/funk/pretty"
6+
"github.com/pubgo/funk/v2/result"
67
"os"
78
"os/exec"
89
"path/filepath"
10+
"runtime"
911
"sort"
1012

1113
"github.com/hashicorp/go-getter"
@@ -14,7 +16,6 @@ import (
1416
"github.com/pubgo/funk/assert"
1517
"github.com/pubgo/funk/errors"
1618
"github.com/pubgo/funk/log"
17-
"github.com/pubgo/funk/recovery"
1819
"github.com/rs/zerolog"
1920
"github.com/samber/lo"
2021
"github.com/urfave/cli/v3"
@@ -35,18 +36,24 @@ func New() *cli.Command {
3536
releases := assert.Must1(client.List(ctx))
3637

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

4041
for _, r := range releases {
4142
for _, a := range githubclient.GetAssets(r) {
4243
if a.IsChecksumFile() {
4344
continue
4445
}
4546

47+
if a.OS != runtime.GOOS {
48+
continue
49+
}
50+
51+
if a.Arch != runtime.GOARCH {
52+
continue
53+
}
54+
4655
assert.Must(tt.Append([]string{
4756
a.Name,
48-
a.OS,
49-
a.Arch,
5057
githubclient.GetSizeFormat(a.Size),
5158
a.URL,
5259
}))
@@ -56,20 +63,22 @@ func New() *cli.Command {
5663
},
5764
},
5865
},
59-
Action: func(ctx context.Context, command *cli.Command) error {
60-
defer recovery.Exit(func(err error) error {
66+
Action: func(ctx context.Context, command *cli.Command) (gErr error) {
67+
defer result.Recovery(&gErr, func(err error) error {
6168
if errors.Is(err, context.Canceled) {
6269
return nil
6370
}
64-
errors.Debug(err)
71+
pretty.Println(err)
6572
return err
6673
})
6774

6875
client := githubclient.NewPublicRelease("pubgo", "fastcommit")
6976
r := assert.Must1(client.List(ctx))
7077

7178
assets := githubclient.GetAssetList(r)
72-
assets = lo.Filter(assets, func(item githubclient.Asset, index int) bool { return !item.IsChecksumFile() })
79+
assets = lo.Filter(assets, func(item githubclient.Asset, index int) bool {
80+
return !item.IsChecksumFile() && item.OS == runtime.GOOS && item.Arch == runtime.GOARCH
81+
})
7382
sort.Slice(assets, func(i, j int) bool {
7483
return assert.Must1(version.NewSemver(assets[i].Name)).GreaterThan(lo.Must(version.NewSemver(assets[j].Name)))
7584
})
@@ -78,19 +87,24 @@ func New() *cli.Command {
7887
assets = assets[:20]
7988
}
8089

81-
result2 := tap.Select[string](context.Background(), tap.SelectOptions[string]{
82-
Message: "Which frontend framework do you prefer?",
90+
versionName := tap.Select[string](ctx, tap.SelectOptions[string]{
91+
Message: "Which version do you prefer?",
8392
Options: lo.Map(assets, func(item githubclient.Asset, index int) tap.SelectOption[string] {
8493
return tap.SelectOption[string]{
8594
Value: item.Name,
86-
Label: fmt.Sprintf("%s %s %s", item.Name, item.OS, item.Arch),
95+
Label: item.Name,
8796
}
8897
}),
8998
})
90-
fmt.Printf("\nYou chose: %s\n", result2)
9199

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

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

0 commit comments

Comments
 (0)