versioncheck

package
v0.34.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package versioncheck provides tools for discovering, inspecting, comparing semantic versions, and generating actionable diagnostic upgrade recommendations for GoDoctor external utilities.

Index

Constants

View Source
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.

View Source
const (
	DevelVersion      = "devel"
	DevelParenVersion = "(devel)"
)

Devel string constants

View Source
const DefaultCacheTTL = 5 * time.Minute

DefaultCacheTTL defines the default duration (5 minutes) to retain version check results.

Variables

DefaultCache is the global shared cache instance.

View Source
var DefaultChecker = NewChecker()

DefaultChecker is the package-level default Checker instance.

View Source
var (

	// GenericSemverRe fallback semver pattern
	GenericSemverRe = regexp.MustCompile(`v?([0-9]+\.[0-9]+(?:\.[0-9]+)?(?:-[0-9a-zA-Z.+_-]+)?)`)
)

Functions

func BuildUpgradeCommand

func BuildUpgradeCommand(spec ToolSpec, recommended string) string

BuildUpgradeCommand constructs a clean install or upgrade command for a tool.

func ExtractVersion

func ExtractVersion(text string, re *regexp.Regexp) string

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.

func Satisfies

func Satisfies(installed Version, constraint string) bool

Satisfies determines if the installed version satisfies the recommended constraint. Supports:

  • "latest" or empty constraint (always satisfied if installed)
  • Range constraint e.g. ">=1.24.0" or ">=1.24"
  • Exact / Minimum pinned version e.g. "v2.12.2" or "1.64.0"

Types

type Checker

type Checker struct {
	// contains filtered or unexported fields
}

Checker coordinates binary discovery, version extraction, semver evaluation, and caching.

func NewChecker

func NewChecker(opts ...Option) *Checker

NewChecker initializes a new Checker with optional overrides.

func (*Checker) CheckAll

func (c *Checker) CheckAll(ctx context.Context, specs ...ToolSpec) ([]ToolStatus, error)

CheckAll evaluates all provided tool specifications (or DefaultRegistry if empty).

func (*Checker) CheckTool

func (c *Checker) CheckTool(ctx context.Context, spec ToolSpec) (ToolStatus, error)

CheckTool inspects a single tool spec and returns its ToolStatus.

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

func WithNoCache(noCache bool) Option

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.

func CheckAll

func CheckAll(ctx context.Context, cfg *config.Config) ([]ToolStatus, error)

CheckAll evaluates all tools, applying custom versions, package paths, timeouts, and filtering disabled tools from GoDoctor config if supplied.

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

func ParseVersion(vStr string) Version

ParseVersion converts raw version strings (e.g. "v1.24.0", "go1.26.3", "v2.12.2-rc1", "devel (abc1234)") into a structured Version.

func (Version) Compare

func (v Version) Compare(target Version) int

Compare compares version v to target. Returns:

  • -1 if v < target
  • 0 if v == target
  • +1 if v > target

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL