Documentation
¶
Overview ¶
Package versioncheck provides tools for discovering, inspecting, comparing semantic versions, and generating actionable diagnostic upgrade recommendations for GoDoctor external utilities.
Index ¶
- Constants
- Variables
- func BuildUpgradeCommand(spec ToolSpec, recommended string) string
- func ExtractVersion(text string, re *regexp.Regexp) string
- func FormatStatusTable(statuses []ToolStatus) string
- func Satisfies(installed Version, constraint string) bool
- type Checker
- type InstallInstructions
- type Option
- type Runner
- type Status
- type ToolSpec
- type ToolStatus
- type Version
- type VersionCache
Constants ¶
const ( ArgVersion = "version" ArgDashVersion = "--version" ArgShortV = "-v" ArgDashHelp = "-help" ToolGo = "go" ToolGoDisplayName = "Go Toolchain" ToolGolangCILint = "golangci_lint" ToolGolangCILintDisplayName = "golangci-lint" ToolModernize = "modernize" ToolDeadcode = "deadcode" ToolSelene = "selene" ToolTestQuery = "testquery" DefaultGoVersion = ">=1.24.0" DefaultGolangCILintVer = "v2.12.2" DefaultLatestVer = "latest" )
CLI tool argument and identity constants.
const ( DevelVersion = "devel" DevelParenVersion = "(devel)" )
Devel string constants
const DefaultCacheTTL = 5 * time.Minute
DefaultCacheTTL defines the default duration (5 minutes) to retain version check results.
Variables ¶
var DefaultCache = NewVersionCache(DefaultCacheTTL)
DefaultCache is the global shared cache instance.
var DefaultChecker = NewChecker()
DefaultChecker is the package-level default Checker instance.
var ( // GenericSemverRe fallback semver pattern GenericSemverRe = regexp.MustCompile(`v?([0-9]+\.[0-9]+(?:\.[0-9]+)?(?:-[0-9a-zA-Z.+_-]+)?)`) )
Functions ¶
func BuildUpgradeCommand ¶
BuildUpgradeCommand constructs a clean install or upgrade command for a tool.
func ExtractVersion ¶
ExtractVersion searches text using the given regex pattern and returns the first capture group.
func FormatStatusTable ¶
func FormatStatusTable(statuses []ToolStatus) string
FormatStatusTable renders a formatted ASCII / Unicode table suitable for terminal display.
Types ¶
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
Checker coordinates binary discovery, version extraction, semver evaluation, and caching.
func NewChecker ¶
NewChecker initializes a new Checker with optional overrides.
type InstallInstructions ¶
type InstallInstructions struct {
GoInstall string `json:"go_install,omitempty"`
Homebrew string `json:"homebrew,omitempty"`
Script string `json:"script,omitempty"`
DocsURL string `json:"docs_url,omitempty"`
}
InstallInstructions provides platform and package manager specific install guidance.
type Option ¶
type Option func(*Checker)
Option configures Checker instances.
func WithNoCache ¶
WithNoCache disables reading from or writing to the cache.
type Runner ¶
type Runner interface {
LookPath(file string) (string, error)
RunCommand(ctx context.Context, name string, args ...string) ([]byte, error)
ReadBuildInfo(path string) (*buildinfo.BuildInfo, error)
Stat(path string) (os.FileInfo, error)
}
Runner abstracts CLI execution, path lookup, and binary inspection for testability.
type Status ¶
type Status string
Status represents the health status of an external tool.
const ( // StatusOk indicates the tool is installed and meets or exceeds recommended version. StatusOk Status = "OK" // StatusOutdated indicates the installed version is older than recommended. StatusOutdated Status = "OUTDATED" // StatusMissing indicates the tool was not found in $PATH. StatusMissing Status = "MISSING" // StatusUnknown indicates the tool is present but its version could not be parsed. StatusUnknown Status = "UNKNOWN" )
type ToolSpec ¶
type ToolSpec struct {
ID string `json:"id"`
DisplayName string `json:"display_name"`
Binaries []string `json:"binaries"`
VersionArgs [][]string `json:"version_args"`
OutputRegex *regexp.Regexp `json:"-"`
DefaultRecommended string `json:"default_recommended"`
PackagePath string `json:"package_path"`
Category string `json:"category"` // "compiler", "linter", "refactor", "test"
Required bool `json:"required"`
InstallGuide InstallInstructions `json:"install_guide"`
Timeout time.Duration `json:"timeout,omitempty"`
Disabled bool `json:"disabled,omitempty"`
}
ToolSpec defines inspection metadata and upgrade guidance for an external utility.
func DefaultRegistry ¶
func DefaultRegistry() []ToolSpec
DefaultRegistry returns the catalog of all external tools tracked by GoDoctor.
type ToolStatus ¶
type ToolStatus struct {
ID string `json:"id"`
DisplayName string `json:"display_name"`
Status Status `json:"status"` // OK, OUTDATED, MISSING, UNKNOWN
BinaryPath string `json:"binary_path,omitempty"`
InstalledVersion string `json:"installed_version,omitempty"`
RecommendedVersion string `json:"recommended_version"`
Satisfies bool `json:"satisfies"`
UpgradeCommand string `json:"upgrade_command,omitempty"`
Category string `json:"category,omitempty"`
Required bool `json:"required"`
}
ToolStatus represents the evaluation result of an external utility.
type Version ¶
type Version struct {
Raw string
Major int
Minor int
Patch int
Prerelease string
IsDevel bool
CommitHash string
}
Version models a parsed semantic version string.
func ParseVersion ¶
ParseVersion converts raw version strings (e.g. "v1.24.0", "go1.26.3", "v2.12.2-rc1", "devel (abc1234)") into a structured Version.
type VersionCache ¶
type VersionCache struct {
// contains filtered or unexported fields
}
VersionCache is a thread-safe, TTL-based cache for tool version evaluation results.
func NewVersionCache ¶
func NewVersionCache(ttl time.Duration) *VersionCache
NewVersionCache initializes a VersionCache with a specified TTL.
func (*VersionCache) Get ¶
func (c *VersionCache) Get(toolID, binaryPath string) (ToolStatus, bool)
Get retrieves a cached ToolStatus if valid and not expired. If binaryPath is provided, verifies that the binary's mtime matches the cached mtime.
func (*VersionCache) Set ¶
func (c *VersionCache) Set(toolID, binaryPath string, status ToolStatus)
Set stores a ToolStatus in the cache with the current binary mtime.