Conversation
0a6f367 to
76070bc
Compare
1e9f54d to
b735dbf
Compare
b735dbf to
f2f1417
Compare
fbf21b0 to
c56f82f
Compare
There was a problem hiding this comment.
Pull request overview
Introduces CLI version surfacing plus an update mechanism: a passive “update available” reminder on startup and a new cg update command to upgrade in-place.
Changes:
- Added
internal/updaterpackage to fetch/cache latest GitHub release and compare versions. - Added
cg updatecommand with install-method detection, confirmation prompt, and upgrade execution. - Updated welcome banner to show build version and added an update reminder helper; documented
cg updatein README.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/updater/checker.go | Implements cached update checks + version comparison utilities |
| internal/updater/checker_test.go | Adds unit tests for version comparison, cache behavior, and fetch behavior |
| cmd/update.go | Adds cg update command (method detection, confirmation, upgrade execution) |
| cmd/update_test.go | Adds tests for update command behavior around version fetching/validation |
| internal/display/banner.go | Shows version in welcome box header; adds update reminder output + padding fix |
| cmd/root.go | Plumbs version into welcome box and triggers update check on startup |
| README.md | Documents cg update and adds it to commands list |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| _, _ = fmt.Fprintln(w, top) | ||
| _, _ = fmt.Fprintln(w, blank) | ||
| printColoredRow(w, brandGreen+"◆ CoinGecko CLI "+colorReset+version, versionVisible) |
There was a problem hiding this comment.
The goreleaser outputs the version number without v, this will return 1.2.3 instead of v1.2.3
Can u check if this is true?
| case "go": | ||
| name = "go" | ||
| args = []string{"install", "github.com/coingecko/coingecko-cli@latest"} |
There was a problem hiding this comment.
Can check if this install method is correct? It seems like it'll produce a binary with coingecko-cli instead of cg. So if user have cg installed, then it'll not update the correct one.
| @@ -0,0 +1,84 @@ | |||
| package cmd | |||
There was a problem hiding this comment.
Add test for detectInstallMethod And ClassifyInstallPath
| current = strings.TrimPrefix(current, "v") | ||
| latest = strings.TrimPrefix(latest, "v") | ||
| if ColorEnabled() { | ||
| fmt.Fprintf(os.Stderr, " %sUpdate available:%s v%s → v%s. Run %scg update%s to upgrade.\n\n", |
There was a problem hiding this comment.
huh. does the linter not flag this? should be something like _, _ = fmt.Fprintf(os.Stderr, " %sUpdate available:%s v%s → v%s. cuz fmt.Fprintf returns (int, error);
| } | ||
|
|
||
| func runUpdate(cmd *cobra.Command, args []string) error { | ||
| display.PrintBanner() |
There was a problem hiding this comment.
don't think we should show banner when we run cg update
| ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
| defer cancel() | ||
| v, err := fetchLatest(ctx) | ||
| if err != nil { |
There was a problem hiding this comment.
Should we add a check for version tag here?
So we don't cache pre-release build v1.2.3-rc1 (not sure if we'll ever use it
There was a problem hiding this comment.
Because from validVersion, it seemed to only accept v1.2.3 format as valid?
Summary
cg updatecommand to upgrade the CLI in-place, auto-detecting the install method (Homebrew,go install, or the install script) and prompting for confirmation before runningcgstartup: checks GitHub Releases and prints a one-liner hint when a newer version exists◆ CoinGecko CLI v1.2.3)Changes
internal/updater/checker.go(new)Core update-check logic extracted into its own package:
Check(currentVersion)— passive checker used at startup. Reads a 24-hour cache at~/.config/coingecko-cli/update_check.jsonbefore hitting the network; skips entirely whenCG_NO_UPDATE_CHECK=1is set, or when the build version isdev/empty (local builds). Times out at 2 s so it never blocks the prompt.FetchLatest()— explicit fetch used bycg update. 10 s timeout, updates the cache on success.vfrom the GitHub tag so version strings are compared uniformly (e.g."1.4.0").cmd/update.go(new)cg updatecommand:/Cellar/or/opt/homebrew/→ Homebrew;$GOBINprefix →go install; fallback →install.shscript). Can be overridden with--method homebrew|go|script.huh.NewConfirm(Charm ecosystem, consistent withcg auth). Exits cleanly onCtrl-C/ "No".internal/display/banner.goPrintWelcomeBoxnow accepts the buildversionstring and renders it in the header row.PrintUpdateReminder(current, latest)— new helper that writes the update nudge to stderr, respectingNO_COLOR.printColoredRowwas callinglen()on a string that may contain multi-byte runes (e.g.◆); replaced withutf8.RuneCountInStringso box borders align correctly on all terminals.cmd/root.goversionintoPrintWelcomeBox.updater.Checkafter printing the welcome box and surfaces the reminder if an update is available.Test plan
cg(no args) — welcome box shows current version in header; no update notice when already on latestcgon an older build (spoof version string) — update notice appears below the welcome boxCG_NO_UPDATE_CHECK=1 cg— no network call, no noticecg updatewhen already on latest — prints "Already up to date"cg updatewhen a newer version exists — shows current → latest, confirms, runs the correct install command for the detected methodcg update --method homebrew|go|script— overrides detection, runs expected commandcg update --method invalid— returns a clear error