Skip to content

feat: introduce version info & update command#25

Merged
irisyann merged 10 commits into
mainfrom
feat/version-info-and-update-cmd-2
May 7, 2026
Merged

feat: introduce version info & update command#25
irisyann merged 10 commits into
mainfrom
feat/version-info-and-update-cmd-2

Conversation

@irisyann
Copy link
Copy Markdown
Contributor

@irisyann irisyann commented May 7, 2026

Summary

  • Adds cg update command to upgrade the CLI in-place, auto-detecting the install method (Homebrew, go install, or the install script) and prompting for confirmation before running
  • Adds a passive update-available nudge on cg startup: checks GitHub Releases and prints a one-liner hint when a newer version exists
  • Surfaces the current version in the welcome box header (◆ 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.json before hitting the network; skips entirely when CG_NO_UPDATE_CHECK=1 is set, or when the build version is dev/empty (local builds). Times out at 2 s so it never blocks the prompt.
  • FetchLatest() — explicit fetch used by cg update. 10 s timeout, updates the cache on success.
  • Both functions strip the leading v from the GitHub tag so version strings are compared uniformly (e.g. "1.4.0").

cmd/update.go (new)

cg update command:

  • Detects install method from the resolved binary path (/Cellar/ or /opt/homebrew/ → Homebrew; $GOBIN prefix → go install; fallback → install.sh script). Can be overridden with --method homebrew|go|script.
  • Validates the fetched version string against a semver regex before acting on it.
  • Prompts for confirmation via huh.NewConfirm (Charm ecosystem, consistent with cg auth). Exits cleanly on Ctrl-C / "No".
  • Delegates the actual upgrade to the appropriate package manager; streams stdout/stderr so progress is visible.

internal/display/banner.go

  • PrintWelcomeBox now accepts the build version string and renders it in the header row.
  • PrintUpdateReminder(current, latest) — new helper that writes the update nudge to stderr, respecting NO_COLOR.
  • Fixed a latent padding bug: printColoredRow was calling len() on a string that may contain multi-byte runes (e.g. ); replaced with utf8.RuneCountInString so box borders align correctly on all terminals.

cmd/root.go

  • Passes version into PrintWelcomeBox.
  • Calls updater.Check after 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 latest
  • cg on an older build (spoof version string) — update notice appears below the welcome box
  • CG_NO_UPDATE_CHECK=1 cg — no network call, no notice
  • cg update when already on latest — prints "Already up to date"
  • cg update when a newer version exists — shows current → latest, confirms, runs the correct install command for the detected method
  • cg update --method homebrew|go|script — overrides detection, runs expected command
  • cg update --method invalid — returns a clear error
  • Cancel the confirmation prompt — exits cleanly with no error
  • Terminal with multi-byte characters in version string — welcome box borders stay aligned

@irisyann irisyann requested a review from a team May 7, 2026 06:03
irisyann and others added 10 commits May 7, 2026 14:13
… pre-release tags

Move ValidVersion into the updater package so both the background Check
and the update command share one regex. Check() and FetchLatest() now
reject non-MAJOR.MINOR.PATCH tags (e.g. rc1 builds) before writing to
cache. Also normalise version prefix display in version cmd and banner.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tection

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@irisyann irisyann force-pushed the feat/version-info-and-update-cmd-2 branch from 1d31f0a to 67ba05a Compare May 7, 2026 06:13
@irisyann irisyann merged commit b9e9582 into main May 7, 2026
3 checks passed
@irisyann irisyann deleted the feat/version-info-and-update-cmd-2 branch May 7, 2026 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants