Skip to content

Commit 6727bd9

Browse files
committed
use github.com/creativeprojects/go-selfupdate for updates
1 parent 274a89b commit 6727bd9

File tree

3 files changed

+67
-51
lines changed

3 files changed

+67
-51
lines changed

cmd/selfUpdate.go

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package cmd
22

33
import (
44
"bufio"
5+
"context"
56
"fmt"
67
"os"
78
"strings"
89

910
"github.com/saltyorg/sb-go/spinners"
1011

1112
"github.com/blang/semver"
12-
"github.com/rhysd/go-github-selfupdate/selfupdate"
13+
"github.com/creativeprojects/go-selfupdate"
1314
"github.com/saltyorg/sb-go/runtime"
1415
"github.com/spf13/cobra"
1516
)
@@ -69,7 +70,17 @@ func doSelfUpdate(autoUpdate bool, verbose bool, optionalMessage string) {
6970
}
7071

7172
// First, check if an update is available without applying it
72-
latest, found, err := selfupdate.DetectLatest("saltyorg/sb-go")
73+
updater, err := selfupdate.NewUpdater(selfupdate.Config{})
74+
if err != nil {
75+
if verbose {
76+
fmt.Printf("Debug: Error creating updater: %v\n", err)
77+
}
78+
fmt.Println("Error creating updater:", err)
79+
os.Exit(1)
80+
return
81+
}
82+
83+
latest, found, err := updater.DetectLatest(context.Background(), selfupdate.ParseSlug("saltyorg/sb-go"))
7384
if err != nil {
7485
if verbose {
7586
fmt.Printf("Debug: Error checking for updates: %v\n", err)
@@ -79,7 +90,7 @@ func doSelfUpdate(autoUpdate bool, verbose bool, optionalMessage string) {
7990
return
8091
}
8192

82-
if !found || latest.Version.Equals(v) {
93+
if !found || latest.Version() == v.String() {
8394
if verbose {
8495
fmt.Println("Debug: No update available - current version is the latest")
8596
}
@@ -88,7 +99,7 @@ func doSelfUpdate(autoUpdate bool, verbose bool, optionalMessage string) {
8899
}
89100

90101
// An update is available
91-
_ = spinners.RunInfoSpinner(fmt.Sprintf("New sb CLI version available: %s (current: %s)", latest.Version, v))
102+
_ = spinners.RunInfoSpinner(fmt.Sprintf("New sb CLI version available: %s (current: %s)", latest.Version(), v))
92103

93104
// If autoUpdate is false, ask for confirmation
94105
if !autoUpdate {
@@ -102,7 +113,17 @@ func doSelfUpdate(autoUpdate bool, verbose bool, optionalMessage string) {
102113
}
103114

104115
// User confirmed or auto-update enabled, proceed with update
105-
result, err := selfupdate.UpdateSelf(v, "saltyorg/sb-go")
116+
exe, err := os.Executable()
117+
if err != nil {
118+
if verbose {
119+
fmt.Printf("Debug: Error getting executable path: %v\n", err)
120+
}
121+
fmt.Println("Error getting executable path:", err)
122+
os.Exit(1)
123+
return
124+
}
125+
126+
err = updater.UpdateTo(context.Background(), latest, exe)
106127
if err != nil {
107128
if verbose {
108129
fmt.Printf("Debug: Update failed with error: %v\n", err)
@@ -113,9 +134,9 @@ func doSelfUpdate(autoUpdate bool, verbose bool, optionalMessage string) {
113134
}
114135

115136
if verbose {
116-
fmt.Printf("Debug: Update successful - previous version: %s, new version: %s\n", v, result.Version)
137+
fmt.Printf("Debug: Update successful - previous version: %s, new version: %s\n", v, latest.Version())
117138
}
118-
_ = spinners.RunInfoSpinner(fmt.Sprintf("Successfully updated sb CLI to version: %s", result.Version))
139+
_ = spinners.RunInfoSpinner(fmt.Sprintf("Successfully updated sb CLI to version: %s", latest.Version()))
119140

120141
// Print an optional message if provided
121142
if optionalMessage != "" {

go.mod

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ require (
1212
github.com/charmbracelet/bubbletea v1.3.6
1313
github.com/charmbracelet/lipgloss v1.1.0
1414
github.com/cloudflare/cloudflare-go v0.115.0
15+
github.com/creativeprojects/go-selfupdate v1.5.1
1516
github.com/docker/docker v28.3.3+incompatible
1617
github.com/docker/go-connections v0.6.0
1718
github.com/go-playground/validator/v10 v10.27.0
18-
github.com/rhysd/go-github-selfupdate v1.2.3
1919
github.com/saltydk/go-rtorrent v1.0.1
2020
github.com/sj14/jellyfin-go v0.3.3
2121
github.com/spf13/cobra v1.9.1
@@ -28,6 +28,8 @@ require (
2828
)
2929

3030
require (
31+
code.gitea.io/sdk/gitea v0.22.0 // indirect
32+
github.com/42wim/httpsig v1.2.3 // indirect
3133
github.com/Masterminds/semver v1.5.0 // indirect
3234
github.com/Microsoft/go-winio v0.6.2 // indirect
3335
github.com/atotto/clipboard v0.1.4 // indirect
@@ -41,11 +43,13 @@ require (
4143
github.com/containerd/errdefs v1.0.0 // indirect
4244
github.com/containerd/errdefs/pkg v0.3.0 // indirect
4345
github.com/containerd/log v0.1.0 // indirect
46+
github.com/davidmz/go-pageant v1.0.2 // indirect
4447
github.com/distribution/reference v0.6.0 // indirect
4548
github.com/docker/go-units v0.5.0 // indirect
4649
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
4750
github.com/felixge/httpsnoop v1.0.4 // indirect
4851
github.com/gabriel-vasile/mimetype v1.4.10 // indirect
52+
github.com/go-fed/httpsig v1.1.0 // indirect
4953
github.com/go-logr/logr v1.4.3 // indirect
5054
github.com/go-logr/stdr v1.2.2 // indirect
5155
github.com/go-playground/locales v0.14.1 // indirect
@@ -54,7 +58,9 @@ require (
5458
github.com/gogo/protobuf v1.3.2 // indirect
5559
github.com/google/go-github/v30 v30.1.0 // indirect
5660
github.com/google/go-querystring v1.1.0 // indirect
57-
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect
61+
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
62+
github.com/hashicorp/go-retryablehttp v0.7.8 // indirect
63+
github.com/hashicorp/go-version v1.7.0 // indirect
5864
github.com/inconshreveable/mousetrap v1.1.0 // indirect
5965
github.com/leodido/go-urn v1.4.0 // indirect
6066
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
@@ -75,8 +81,8 @@ require (
7581
github.com/rogpeppe/go-internal v1.14.1 // indirect
7682
github.com/sahilm/fuzzy v0.1.1 // indirect
7783
github.com/spf13/pflag v1.0.7 // indirect
78-
github.com/tcnksm/go-gitconfig v0.1.2 // indirect
7984
github.com/ulikunitz/xz v0.5.15 // indirect
85+
github.com/xanzy/go-gitlab v0.115.0 // indirect
8086
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
8187
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
8288
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.62.0 // indirect
@@ -94,6 +100,5 @@ require (
94100
google.golang.org/genproto/googleapis/api v0.0.0-20250804133106-a7a43d27e69b // indirect
95101
google.golang.org/genproto/googleapis/rpc v0.0.0-20250804133106-a7a43d27e69b // indirect
96102
gopkg.in/validator.v2 v2.0.1 // indirect
97-
gopkg.in/yaml.v2 v2.4.0 // indirect
98103
gotest.tools/v3 v3.5.2 // indirect
99104
)

0 commit comments

Comments
 (0)