Skip to content

Commit b79d52b

Browse files
committed
fix: barry quick fix, 2025-05-07 21:40:54
1 parent f9a5f66 commit b79d52b

File tree

4 files changed

+37
-161
lines changed

4 files changed

+37
-161
lines changed

.goreleaser.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ builds:
88
- GOPROXY=https://goproxy.io
99
targets:
1010
- "darwin_amd64"
11+
- "darwin_arm64"
1112
- "windows_amd64"
1213
- "linux_amd64"
14+
- "linux_arm64"
1315
ldflags:
14-
- -X 'github.com/pubgo/funk/version.version={{ .Version }}'
16+
- -X 'github.com/pubgo/funk/version.version=v{{ .Version }}'
1517
- -X 'github.com/pubgo/funk/version.project=fastcommit'
1618
- -X 'github.com/pubgo/funk/version.buildTime={{ .CommitDate }}'
1719
- -X 'github.com/pubgo/funk/version.commitID={{ .ShortCommit }}'

cmds/self/cmd.go

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ package selfcmd
22

33
import (
44
"context"
5-
"fmt"
65
"net/http"
76
"os"
7+
"os/exec"
88
"path/filepath"
9-
"runtime"
109

10+
tea "github.com/charmbracelet/bubbletea"
1111
"github.com/google/go-github/v71/github"
1212
"github.com/hashicorp/go-getter"
1313
"github.com/olekukonko/tablewriter"
14-
"github.com/pubgo/funk/pretty"
14+
"github.com/pubgo/funk/assert"
1515
"github.com/pubgo/funk/recovery"
1616
"github.com/samber/lo"
1717
"github.com/urfave/cli/v3"
@@ -46,34 +46,30 @@ func New() *cli.Command {
4646
Action: func(ctx context.Context, command *cli.Command) error {
4747
defer recovery.Exit()
4848

49-
cli := github.NewClient(http.DefaultClient)
50-
r, _ := lo.Must2(cli.Repositories.GetLatestRelease(context.Background(), "pubgo", "fastcommit"))
51-
pretty.Println(r)
52-
return nil
53-
var sss = "https://github.com/pubgo/fastcommit/releases/download/v0.0.6-alpha.6/fastcommit_Darwin_x86_64.tar.gz"
54-
var opts []getter.ClientOption
49+
client := github.NewClient(http.DefaultClient)
50+
r, _ := lo.Must2(client.Repositories.GetLatestRelease(context.Background(), "pubgo", "fastcommit"))
51+
52+
var p = tea.NewProgram(initialModel(r))
53+
mm := assert.Must1(p.Run()).(model)
5554

56-
//ff := lo.Must(os.CreateTemp("fastcommit", "v0.0.6-alpha.6"))
55+
var downloadURL = mm.selected.GetBrowserDownloadURL()
5756

58-
fffff := filepath.Join(os.TempDir(), "fastcommit")
59-
fmt.Println(fffff)
57+
downloadDir := filepath.Join(os.TempDir(), "fastcommit")
6058
pwd := lo.Must(os.Getwd())
6159

62-
fmt.Println(runtime.GOOS)
63-
fmt.Println(runtime.GOARCH)
64-
ctx, cancel := context.WithCancel(context.Background())
65-
defer cancel()
66-
// Build the client
67-
client := &getter.Client{
60+
execFile := filepath.Base(os.Args[0])
61+
execFile = lo.Must(exec.LookPath(execFile))
62+
63+
client1 := &getter.Client{
6864
Ctx: ctx,
69-
Src: sss,
70-
Dst: fffff,
65+
Src: downloadURL,
66+
Dst: downloadDir,
7167
Pwd: pwd,
7268
Mode: getter.ClientModeDir,
73-
Options: opts,
7469
ProgressListener: defaultProgressBar,
7570
}
76-
lo.Must0(client.Get())
71+
lo.Must0(client1.Get())
72+
lo.Must0(os.Rename(downloadDir+"/fastcommit", execFile))
7773

7874
return nil
7975
},

cmds/self/progress_tracking.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ type ProgressBar struct {
2929
pbs int
3030
}
3131

32-
func ProgressBarConfig(bar *pb.ProgressBar, prefix string) {
33-
bar.Set("prefix", prefix)
34-
//bar.SetTemplateString(fmt.Sprintf(`%s: {{with string . "prefix"}}{{.}} {{end}}{{counters . }} {{bar . }} {{percent . }} {{speed . }}{{with string . "suffix"}} {{.}}{{end}}`, prefix))
35-
//bar.Prefix(prefix)
36-
//bar.SetTemplateString()
37-
}
38-
3932
// TrackProgress instantiates a new progress bar that will
4033
// display the progress of stream until closed.
4134
// total can be 0.
@@ -45,7 +38,7 @@ func (cpb *ProgressBar) TrackProgress(src string, currentSize, totalSize int64,
4538

4639
newPb := pb.New64(totalSize)
4740
newPb.SetCurrent(currentSize)
48-
ProgressBarConfig(newPb, filepath.Base(src))
41+
newPb.Set("prefix", filepath.Base(src))
4942
if cpb.pool == nil {
5043
cpb.pool = pb.NewPool()
5144
cpb.pool.Start()

cmds/self/ui.go

Lines changed: 15 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,28 @@ package selfcmd
22

33
import (
44
"fmt"
5+
"runtime"
6+
"strings"
57

6-
"github.com/charmbracelet/bubbles/spinner"
7-
"github.com/charmbracelet/bubbles/textinput"
88
tea "github.com/charmbracelet/bubbletea"
9-
"github.com/charmbracelet/lipgloss"
10-
semver "github.com/hashicorp/go-version"
9+
"github.com/google/go-github/v71/github"
1110
"github.com/pubgo/funk/log"
12-
)
13-
14-
const (
15-
envAlpha = "alpha"
16-
envBeta = "beta"
17-
envRelease = "release"
11+
"github.com/samber/lo"
1812
)
1913

2014
type model struct {
2115
cursor int
22-
choices []string
23-
selected string
16+
assets []*github.ReleaseAsset
17+
selected *github.ReleaseAsset
2418
length int
2519
}
2620

27-
func initialModel() model {
28-
choices := []string{envAlpha, envBeta, envRelease}
21+
func initialModel(rsp *github.RepositoryRelease) model {
2922
return model{
30-
choices: choices,
31-
length: len(choices),
23+
assets: lo.Filter(rsp.Assets, func(item *github.ReleaseAsset, index int) bool {
24+
return !strings.Contains(item.GetName(), "checksums") && strings.Contains(strings.ToLower(item.GetName()), strings.ToLower(runtime.GOOS))
25+
}),
26+
length: len(rsp.Assets) - 1,
3227
}
3328
}
3429

@@ -43,7 +38,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
4338
case tea.KeyUp, tea.KeyLeft, tea.KeyDown, tea.KeyRight:
4439
m.cursor++
4540
case tea.KeyEnter:
46-
m.selected = m.choices[m.cursor%m.length]
41+
m.selected = m.assets[m.cursor%m.length]
4742
return m, tea.Quit
4843
default:
4944
log.Error().Str("key", msg.String()).Msg("unknown key")
@@ -55,126 +50,16 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
5550
}
5651

5752
func (m model) View() string {
58-
s := "Please Select Pre Tag:\n"
53+
s := "Please Select:\n"
5954

60-
for i, choice := range m.choices {
55+
for i, choice := range m.assets {
6156
cursor := " "
6257
if m.cursor%m.length == i {
6358
cursor = ">"
6459
}
6560

66-
s += fmt.Sprintf("%s %s\n", cursor, choice)
61+
s += fmt.Sprintf("%s %s\n", cursor, lo.FromPtr(choice.Name))
6762
}
6863

6964
return s
7065
}
71-
72-
type model1 struct {
73-
spinner spinner.Model
74-
quitting bool
75-
err error
76-
}
77-
78-
func InitialModelNew() model1 {
79-
s := spinner.New()
80-
s.Spinner = spinner.Line
81-
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
82-
return model1{spinner: s}
83-
}
84-
85-
func (m model1) Init() tea.Cmd {
86-
return m.spinner.Tick
87-
}
88-
89-
func (m model1) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
90-
switch msg := msg.(type) {
91-
case tea.KeyMsg:
92-
switch msg.String() {
93-
case "q", "esc", "ctrl+c":
94-
m.quitting = true
95-
return m, tea.Quit
96-
default:
97-
return m, nil
98-
}
99-
100-
default:
101-
var cmd tea.Cmd
102-
m.spinner, cmd = m.spinner.Update(msg)
103-
return m, cmd
104-
}
105-
}
106-
107-
func (m model1) View() string {
108-
109-
if m.err != nil {
110-
return m.err.Error()
111-
}
112-
str := fmt.Sprintf("%s Preparing...", m.spinner.View())
113-
if m.quitting {
114-
return str + "\n"
115-
}
116-
return str
117-
}
118-
119-
type model2 struct {
120-
textInput textinput.Model
121-
exit bool
122-
}
123-
124-
// sanitizeInput verifies that an input text string gets validated
125-
func sanitizeInput(input string) error {
126-
_, err := semver.NewSemver(input)
127-
return err
128-
}
129-
130-
func InitialTextInputModel(data string) model2 {
131-
ti := textinput.New()
132-
ti.Focus()
133-
ti.Prompt = ""
134-
ti.CharLimit = 156
135-
ti.Width = 20
136-
ti.Validate = sanitizeInput
137-
ti.SetValue(data)
138-
139-
return model2{
140-
textInput: ti,
141-
}
142-
}
143-
144-
// Init is called at the beginning of a textinput step
145-
// and sets the cursor to blink
146-
func (m model2) Init() tea.Cmd {
147-
return textinput.Blink
148-
}
149-
150-
// Update is called when "things happen", it checks for the users text input,
151-
// and for Ctrl+C or Esc to close the program.
152-
func (m model2) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
153-
var cmd tea.Cmd
154-
155-
switch msg := msg.(type) {
156-
case tea.KeyMsg:
157-
switch msg.Type {
158-
case tea.KeyEnter:
159-
return m, tea.Quit
160-
case tea.KeyCtrlC, tea.KeyEsc:
161-
m.exit = true
162-
return m, tea.Quit
163-
}
164-
}
165-
166-
m.textInput, cmd = m.textInput.Update(msg)
167-
return m, cmd
168-
}
169-
170-
// View is called to draw the textinput step
171-
func (m model2) View() string {
172-
return fmt.Sprintf(
173-
"new tag: %s\n",
174-
m.textInput.View(),
175-
)
176-
}
177-
178-
func (m model2) Value() string {
179-
return m.textInput.Value()
180-
}

0 commit comments

Comments
 (0)