toolchain

package
v1.203.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2026 License: Apache-2.0 Imports: 57 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrToolNotFound indicates a tool was not found in the registry or local configuration.
	ErrToolNotFound = registry.ErrToolNotFound

	// ErrNoVersionsFound indicates no versions are available for a tool.
	ErrNoVersionsFound = registry.ErrNoVersionsFound

	// ErrInvalidToolSpec indicates the tool specification format is invalid.
	ErrInvalidToolSpec = registry.ErrInvalidToolSpec

	// ErrHTTPRequest indicates an HTTP request failed.
	ErrHTTPRequest = registry.ErrHTTPRequest

	// ErrHTTP404 indicates an HTTP 404 Not Found response.
	ErrHTTP404 = registry.ErrHTTP404

	// ErrRegistryParse indicates the registry file could not be parsed.
	ErrRegistryParse = registry.ErrRegistryParse

	// ErrNoPackagesInRegistry indicates the registry contains no packages.
	ErrNoPackagesInRegistry = registry.ErrNoPackagesInRegistry

	// ErrNoAssetTemplate indicates no asset template is defined for the tool.
	ErrNoAssetTemplate = registry.ErrNoAssetTemplate

	// ErrFileOperation indicates a file operation failed.
	ErrFileOperation = registry.ErrFileOperation

	// ErrToolAlreadyExists indicates the tool version already exists in .tool-versions.
	ErrToolAlreadyExists = registry.ErrToolAlreadyExists
)

Error re-exports from the registry package for backward compatibility. New code should import and use toolchain/registry errors directly.

View Source
var (
	DefaultToolVersionsFilePath = ".tool-versions"
	DefaultInstallPath          = ".tools"
)
View Source
var BuiltinAliases = map[string]string{
	"atmos": "cloudposse/atmos",
}

BuiltinAliases are always available and can be overridden in atmos.yaml. These provide convenient shortcuts for common tools.

Functions

func AddToolToVersions

func AddToolToVersions(filePath, tool, version string) error

AddToolToVersions adds a tool/version combination to the .tool-versions file If the tool already exists, it updates the version If the aliased version already exists, it skips adding the non-aliased version to prevent duplicates.

func AddToolToVersionsAsDefault

func AddToolToVersionsAsDefault(filePath, tool, version string) error

AddToolToVersionsAsDefault adds a tool and version to the .tool-versions file as the default If the tool already exists, it updates the version and sets it as default.

func AddToolVersion

func AddToolVersion(tool, version string) error

AddToolVersion contains the actual business logic for adding/updating a tool.

func AddVersionToTool

func AddVersionToTool(toolVersions *ToolVersions, tool, version string, asDefault bool)

AddVersionToTool adds a version to a tool, optionally as default (front of list).

func CleanToolsAndCaches

func CleanToolsAndCaches(toolsDir, cacheDir, tempCacheDir string) error

CleanToolsAndCaches handles the business logic for cleaning tools and cache directories. It performs file counting, deletion, and writes UI messages to stderr.

func DuExec

func DuExec() error

DuExec calculates and displays the total disk space used by installed tools.

func EmitEnv

func EmitEnv(format string, relativeFlag bool) error

EmitEnv outputs the PATH entries for installed toolchain binaries in shell-specific format. The format parameter specifies the output format (bash, fish, powershell, json, dotenv), and relativeFlag uses relative paths instead of absolute.

func EmitPath

func EmitPath(exportFlag, jsonFlag, relativeFlag bool) error

EmitPath outputs the PATH entries for installed toolchain binaries. The exportFlag outputs in shell export format, jsonFlag outputs JSON, and relativeFlag uses relative paths instead of absolute.

func ExtractTarGz

func ExtractTarGz(src, dest string) error

ExtractTarGz extracts a .tar.gz file to the given destination directory.

func GetAllVersions

func GetAllVersions(toolVersions *ToolVersions, tool string) []string

GetAllVersions returns all versions for a tool.

func GetAtmosConfig

func GetAtmosConfig() *schema.AtmosConfiguration

GetAtmosConfig returns the current Atmos configuration. Returns nil if not yet initialized.

func GetDefaultVersion

func GetDefaultVersion(toolVersions *ToolVersions, tool string) (string, bool)

GetDefaultVersion returns the default (first) version for a tool.

func GetInstallPath

func GetInstallPath() string

GetInstallPath returns the path where tools are installed. By default, it uses XDG Data directory (~/.local/share/atmos/toolchain on Linux/macOS). Falls back to .tools if XDG directory cannot be created.

func GetToolVersionsFilePath

func GetToolVersionsFilePath() string

GetToolVersionsFilePath returns the path to the tool-versions file.

func InfoExec

func InfoExec(toolName, outputFormat string) error

InfoExec handles the core logic for retrieving and formatting tool information.

func InstallSingleTool

func InstallSingleTool(owner, repo, version string, isLatest bool, showProgressBar bool) error

func ListToolVersions

func ListToolVersions(showAll bool, limit int, toolName string) error

ListToolVersions handles the logic for listing tool versions.

func LookupToolVersion

func LookupToolVersion(tool string, toolVersions *ToolVersions, resolver ToolResolver) (resolvedKey, version string, found bool)

LookupToolVersion attempts to find the version for a tool, trying both the raw name and its resolved alias. Returns the key found (raw or alias), the version, and whether it was found.

func MoveFile

func MoveFile(src, dst string) error

MoveFile tries os.Rename, but if that fails due to cross-device link, it falls back to a copy+remove.

func NewAquaRegistry

func NewAquaRegistry() registry.ToolRegistry

NewAquaRegistry creates a new Aqua registry client. This is a convenience wrapper that returns the default Aqua implementation.

func NewRegistry

func NewRegistry(atmosConfig *schema.AtmosConfiguration) (registry.ToolRegistry, error)

NewRegistry creates a ToolRegistry from the given Atmos configuration. If registries are configured, returns a CompositeRegistry. Otherwise, returns the default Aqua registry for backward compatibility.

func ParseToolVersionArg

func ParseToolVersionArg(arg string) (string, string, error)

ParseToolVersionArg parses a CLI argument in the form tool, tool@version, or owner/repo@version. Returns tool (or owner/repo), version (may be empty), and error if invalid.

func RemoveToolFromVersions

func RemoveToolFromVersions(filePath, tool, version string) error

RemoveToolFromVersions removes a tool from the .tool-versions file.

func RemoveToolVersion

func RemoveToolVersion(filePath, tool, version string) error

RemoveToolVersion removes either the entire tool or a specific version from the file. If version is empty, removes all versions of the tool.

func ResetGitHubAPI

func ResetGitHubAPI()

ResetGitHubAPI resets the global GitHub API client to the default.

func RunExecCommand

func RunExecCommand(installer ToolRunner, args []string) error

RunExecCommand contains business logic for executing tools. It does not depend on cobra.Command, only raw args.

func RunInstall

func RunInstall(toolSpec string, setAsDefault, reinstallFlag bool) error

RunInstall installs the specified tool (owner/repo@version or alias@version). If toolSpec is empty, installs all tools from .tool-versions file. The setAsDefault parameter controls whether to set the installed version as default. The reinstallFlag parameter forces reinstallation even if already installed.

func RunList

func RunList() error

RunList prints a table of tools from .tool-versions, marking installed/default versions.

func RunListAtmosVersions

func RunListAtmosVersions() ([]string, error)

RunListAtmosVersions lists all installed versions of Atmos (returns version strings).

func RunListInstalledAtmosVersions

func RunListInstalledAtmosVersions(currentVersion string) error

RunListInstalledAtmosVersions prints a formatted table of installed Atmos versions.

func RunUninstall

func RunUninstall(toolSpec string) error

RunUninstall removes tools by spec (owner/repo, tool, or ).

func SaveToolVersions

func SaveToolVersions(filePath string, toolVersions *ToolVersions) error

SaveToolVersions saves a ToolVersions struct to a .tool-versions file (asdf-compatible).

func SetAtmosConfig

func SetAtmosConfig(config *schema.AtmosConfiguration)

SetAtmosConfig injects the current Atmos configuration into the toolchain package.

func SetGitHubAPI

func SetGitHubAPI(api GitHubAPI)

SetGitHubAPI sets the global GitHub API client (for testing).

func SetToolVersion

func SetToolVersion(toolName, version string, scrollSpeed int) error

SetToolVersion handles the core logic of setting a tool version. If version is empty, it will prompt the user interactively (for GitHub release type tools).

func Unzip

func Unzip(src, dest string) error

Unzip extracts a zip archive to a destination directory. Works on Windows, macOS, and Linux.

func WhichExec

func WhichExec(toolName string) error

WhichExec prints the absolute path to the resolved tool binary for toolName (optionally with @version). Returns an error if the tool is not configured or not installed.

Types

type AquaRegistry

type AquaRegistry = aqua.AquaRegistry

AquaRegistry is a type alias for backward compatibility. New code should use toolchain/registry.ToolRegistry interface.

type DefaultToolResolver

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

DefaultToolResolver implements ToolResolver using configured aliases and registry search.

func (*DefaultToolResolver) Resolve

func (d *DefaultToolResolver) Resolve(toolName string) (string, string, error)

type File

type File = registry.File

File is a type alias for registry.File for backward compatibility.

type GitHubAPI

type GitHubAPI interface {
	FetchReleases(owner, repo string, limit int) ([]string, error)
}

GitHubAPI defines the interface for GitHub API operations.

type GitHubAPIClient

type GitHubAPIClient struct{}

GitHubAPIClient implements GitHubAPI using pkg/github.

func NewGitHubAPIClient

func NewGitHubAPIClient() *GitHubAPIClient

NewGitHubAPIClient creates a new GitHub API client.

func (*GitHubAPIClient) FetchReleases

func (g *GitHubAPIClient) FetchReleases(owner, repo string, limit int) ([]string, error)

FetchReleases fetches all available versions from GitHub API.

type Installer

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

Installer handles the installation of CLI binaries.

func NewInstaller

func NewInstaller() *Installer

NewInstaller uses the default resolver with alias support from atmosConfig.

func NewInstallerWithResolver

func NewInstallerWithResolver(resolver ToolResolver) *Installer

NewInstallerWithResolver allows injecting a custom ToolResolver (for tests).

func (*Installer) CreateLatestFile

func (i *Installer) CreateLatestFile(owner, repo, version string) error

CreateLatestFile creates a "latest" file that contains a pointer to the actual version.

func (*Installer) FindBinaryPath

func (i *Installer) FindBinaryPath(owner, repo, version string, binaryName ...string) (string, error)

FindBinaryPath searches for a binary with the given owner, repo, and version. The binaryName parameter is optional - pass empty string to auto-detect.

func (*Installer) GetResolver

func (i *Installer) GetResolver() ToolResolver

GetResolver returns the tool resolver used by this installer.

func (*Installer) Install

func (i *Installer) Install(owner, repo, version string) (string, error)

Install installs a tool from the registry.

func (*Installer) ListInstalledVersions

func (i *Installer) ListInstalledVersions(owner, repo string) ([]string, error)

ListInstalledVersions returns a list of installed versions for a specific tool.

func (*Installer) ReadLatestFile

func (i *Installer) ReadLatestFile(owner, repo string) (string, error)

ReadLatestFile reads the version from a "latest" file.

func (*Installer) Uninstall

func (i *Installer) Uninstall(owner, repo, version string) error

Uninstall removes a previously installed tool.

type ModelI

type ModelI interface {
	Items() []list.Item
}

ModelI is the minimal list model interface used by customDelegate.

type Override

type Override = registry.Override

Override is a type alias for registry.Override for backward compatibility.

type Tool

type Tool = registry.Tool

Tool is a type alias for registry.Tool for backward compatibility. New code should import and use toolchain/registry.Tool directly.

type ToolPath

type ToolPath struct {
	Tool    string `json:"tool"`
	Version string `json:"version"`
	Path    string `json:"path"`
}

ToolPath represents a tool with its version and path.

type ToolResolver

type ToolResolver interface {
	Resolve(toolName string) (owner, repo string, err error)
}

ToolResolver defines an interface for resolving tool names to owner/repo pairs This allows for mocking in tests and flexible resolution in production.

type ToolRunner

type ToolRunner interface {
	FindBinaryPath(owner, repo, version string, binaryName ...string) (string, error)
	GetResolver() ToolResolver
	CreateLatestFile(owner, repo, version string) error
	ReadLatestFile(owner, repo string) (string, error)
}

ToolRunner defines the interface for running and resolving tools (for real and mock installers).

type ToolVersionLookupResult

type ToolVersionLookupResult struct {
	ResolvedKey string // The key found (raw tool name or owner/repo alias).
	Version     string // The version string.
	Found       bool   // Whether the tool was found in toolVersions.
	UsedLatest  bool   // Whether 'latest' was used as a fallback.
}

ToolVersionLookupResult holds the result of looking up a tool version.

func LookupToolVersionOrLatest

func LookupToolVersionOrLatest(tool string, toolVersions *ToolVersions, resolver ToolResolver) ToolVersionLookupResult

LookupToolVersionOrLatest attempts to find the version for a tool, trying both the raw name and its resolved alias. If not found, but the alias resolves, returns 'latest' as the version and usedLatest=true.

type ToolVersions

type ToolVersions struct {
	Tools map[string][]string
}

ToolVersions represents the .tool-versions file format (asdf-compatible: tool -> list of versions, first is default).

func LoadToolVersions

func LoadToolVersions(filePath string) (*ToolVersions, error)

LoadToolVersions loads a .tool-versions file (asdf-compatible: tool version1 [version2 ...]).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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