How lokesh-balla/gvm works
Project Type and Purpose
• gvm is a command-line tool (CLI) written in Go that provides version management for Go installations.
• It follows the Command Pattern: a root command (gvm) delegates to subcommands (install, list, use, uninstall).
File Structure Analysis
• Top-level:
• cmd/ → contains subcommand implementations (install.go, list.go, use.go, uninstall.go, root.go)
• main.go → entrypoint that initializes the CLI
• install.sh → bootstrap installer script
• docs/ → user documentation for GitHub Pages
• .github/ → CI/CD workflows (build, lint, release)
• Makefile → build, test, release targets
• Patterns:
• Modular CLI commands
• Zero external Go dependencies (standard library only)
• Configuration via file system (~/.gvm, ~/.gvm/bin)
Key README Insights
• Zero-dependency Go binary
• Supports standard OSes (Linux, Darwin, FreeBSD, etc.)
• Installs Go versions by downloading archives from official Go releases
• Manages PATH entries to switch Go versions
Main Components
A. CLI Layer
• Entry Point (main.go)
• Command Dispatcher (root command)
• Subcommand Modules (install, list, use, uninstall)
B. Core Logic Layer
• Version Resolver (determines download URL based on requested version)
• Downloader (HTTP client to fetch Go archives)
• Installer (unpack into ~/.gvm/versions/<version>)
• Environment Manager (symlinks in ~/.gvm/bin, PATH adjustments)
C. Persistence Layer
• File System
• ~/.gvm/versions/ (installed Go versions)
• ~/.gvm/bin/ (active version shim)
• Config files (if any)
D. External Services
• Go official downloads
• GitHub (for release binaries, CI status)
E. Developer Tooling / CI (optional separate view)
• GitHub Actions workflows (.github/workflows)
• golangci-lint, CodeQL scans
• Build & Release pipeline
Interactions & Data Flows
• User invokes gvm <subcommand> [args] → CLI Layer
• CLI calls Core Logic
• install: resolves version → downloads archive → writes to FS → updates shim
• Reads ~/.gvm/versions/ → returns versions
• use: updates symlink in ~/.gvm/bin → modifies PATH for shell
• uninstall: removes version directory from FS
• Core Logic reads/writes File System
• On install/uninstall: may call external HTTP API (Go download server)
Architectural Patterns & Principles
• Command Pattern for extendability (add new subcommands easily)
• Layered architecture: CLI → Core Logic → Persistence → External
• Single responsibility per module (each command only handles its own logic)
• Minimal external dependencies (ease of compilation & portability)