Documentation
¶
Overview ¶
Package tools provides structures and methods for managing tool configurations, including downloading, validating, and executing tools in various environments. It supports different strategies for tool management such as upgrading, forcing installation, or skipping based on conditions and tags.
The package handles various aspects of tool setup, including resolving sources, handling aliases, managing environment variables, applying templates, and validating tool configurations. It also supports working with different platforms, allowing platform-specific handling of tools.
Index ¶
- Variables
- func ErrCausesEarlyReturn(err error) bool
- func ExtensionsToHint(exts Extensions) match.Hint
- func ToVersion(version string) *semver.Version
- type Aliases
- type Checker
- type Checksum
- type Condition
- type Defaults
- type Exe
- type Extensions
- type Fallbacks
- type Mode
- type Settings
- type Skip
- type Strategy
- type Tags
- type Tool
- func (t *Tool) ApplyDefaults(d Defaults)
- func (t *Tool) CheckSkipConditions(withTags, withoutTags []string) error
- func (t *Tool) Download() (string, file.File, error)
- func (t *Tool) Exists() bool
- func (t *Tool) Resolve(withTags, withoutTags []string) error
- func (t *Tool) TemplateFirst() error
- func (t *Tool) TemplateLast() error
- func (t *Tool) ToTemplateMap(flatten ...map[string]any) map[string]any
- func (t *Tool) UnmarshalYAML(value *yaml.Node) error
- func (t *Tool) Validate() error
- type Tools
- type Version
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAlreadyExists indicates that the tool already exists in the system. ErrAlreadyExists = errors.New("tool already exists") // ErrUpToDate indicates that the tool is already up to date. ErrUpToDate = errors.New("tool is up to date") // ErrRequiresUpdate indicates that the tool requires an update. ErrRequiresUpdate = errors.New("tool requires update") // ErrDoesHaveTags indicates that the tool has tags that are in the excluded tags list. ErrDoesHaveTags = errors.New("tool contains excluded tags") // ErrDoesNotHaveTags indicates that the tool does not contain required tags. ErrDoesNotHaveTags = errors.New("tool does not contain included tags") // ErrSkipped indicates that the tool has been skipped due to conditions. ErrSkipped = errors.New("tool skipped") // ErrFailed indicates that the tool has failed to install or resolve. ErrFailed = errors.New("tool failed") )
Functions ¶
func ErrCausesEarlyReturn ¶
ErrCausesEarlyReturn checks if the error should cause early return.
func ExtensionsToHint ¶
func ExtensionsToHint(exts Extensions) match.Hint
ExtensionsToHint converts a list of extensions into a match.Hint.
Types ¶
type Aliases ¶
type Aliases = unmarshal.SingleOrSliceType[string]
Aliases represents a tool's alias names.
type Checker ¶
type Checker struct {
// Test defines the commands that should be run to test or validate the tool's functionality.
Test command.Commands
// Checksum is used for verifying the integrity of the tool (e.g., via a hash).
Checksum Checksum
}
Checker represents a tool checker configuration.
type Checksum ¶
type Checksum struct {
// Path to the checksum file.
Path string
// Enabled specifies whether checksum verification is enabled.
Enabled bool
}
Checksum represents a checksum configuration.
type Condition ¶
type Condition struct {
// Condition is a string that represents a boolean expression (e.g., "true" or "false") that determines whether the
// operation should be skipped.
Condition string
// Reason provides an optional explanation for why the operation is being skipped.
Reason string
}
Condition defines a condition and an optional reason for skipping an operation.
type Defaults ¶
type Defaults struct {
// Exe specifies default executable details such as patterns for identifying the binary.
Exe Exe
// Output specifies the default output path for the tool.
Output string
// Platform defines default platform-specific settings (e.g., OS and architecture).
Platform detect.Platform
// Values contains default custom values for the tool configuration.
Values map[string]any
// Fallbacks defines default fallback configurations or sources in case the primary configuration fails.
Fallbacks []string
// Hints provide default matching patterns or heuristics for the tool.
Hints match.Hints
// Source defines the default source configuration for fetching the tool (e.g., GitHub, local files).
Source sources.Source
// Tags are default labels or markers for categorizing the tool.
Tags Tags
// Strategy defines the default deployment or fetching strategy for the tool.
Strategy Strategy
// Extensions lists default additional file extensions related to the tool.
Extensions []string
// Env defines default environment variables applied when running the tool.
Env env.Env
// Mode specifies the default operating mode for the tool (e.g., silent mode, verbose mode).
Mode Mode
// Version specifies the default version details for the tool.
Version Version
}
Defaults holds default configuration values for a tool. These values can be applied to a tool configuration to provide sensible defaults for executable paths, output locations, platform-specific settings, and more.
func (*Defaults) Initialize ¶
Initialize detects the current platform and applies platform-specific defaults to the Defaults struct. It also sets up default extensions based on the detected platform.
type Exe ¶
type Exe struct {
// Name is the name under which the binary will be stored in the output folder.
Name string
// Patterns specifies the patterns used to locate the binary in the downloaded folder.
// This can either be a single string or a slice of strings.
Patterns unmarshal.SingleOrSliceType[string]
}
Exe represents the configuration for the executable, including the name under which the binary will be stored and the patterns to search for the binary within the downloaded files.
type Extensions ¶
type Extensions = unmarshal.SingleOrSliceType[string]
Extensions represents a collection of file extensions.
type Fallbacks ¶
type Fallbacks = unmarshal.SingleOrSliceType[sources.Type]
Fallbacks represents a collection of fallback sources for the tool. It can either be a single source type or a slice of source types, allowing flexibility in specifying multiple fallback methods if the primary source fails.
type Mode ¶
type Mode string
Mode represents the operational mode for a tool, determining how the tool is handled. It could specify different behaviors such as extracting the tool from an archive or searching for the tool.
type Skip ¶
type Skip []Condition
Skip represents a list of conditions under which certain operations (e.g., downloading, testing) should be skipped.
type Strategy ¶
type Strategy string
Strategy represents the strategy for handling tool installation or upgrades.
const ( // None indicates no strategy, meaning no action will be taken if the tool already exists. None Strategy = "none" // Upgrade indicates that the tool should only be upgraded if a newer version is available. Upgrade Strategy = "upgrade" // Force indicates that the tool should be installed or updated regardless of its current state. Force Strategy = "force" )
type Tags ¶
type Tags []string
Tags represents a list of tags associated with a tool. Tags can be used to categorize or filter tools based on specific labels or keywords.
func (Tags) Has ¶
Has checks if any of the provided tags are present in the Tags list. Returns true if at least one tag matches.
type Tool ¶
type Tool struct {
// Name of the tool, usually a short identifier or title.
Name string
// Description of the tool, giving more context about its purpose.
Description string
// Version specifies the version of the tool.
Version Version
// Path represents the URL or file path where the tool can be fetched or downloaded from.
Path string
// Output defines the output path where the tool will be installed or extracted.
Output string
// Exe specifies the executable details for the tool, such as patterns or names for locating the binary.
Exe Exe
// Platform defines the platform-specific details for the tool, including OS and architecture constraints.
Platform detect.Platform
// Aliases represent alternative names or shortcuts for the tool.
Aliases Aliases
// Values contains custom values or variables used in the tool's configuration.
Values map[string]any
// Fallbacks defines fallback configurations in case the primary configuration fails.
Fallbacks Fallbacks
// Hints provide additional matching patterns or heuristics for the tool.
Hints match.Hints
// Source defines the source configuration, which determines how the tool is fetched (e.g., GitHub, local files).
Source sources.Source
// Tags are labels or markers that can be used to categorize or filter the tool.
Tags Tags
// Strategy defines how the tool is deployed, fetched, or managed (e.g., download strategies, handling retries).
Strategy Strategy
// Extensions lists additional files or behaviors that are tied to the tool.
Extensions Extensions
// Skip defines conditions under which certain steps (e.g., downloading, testing) are skipped.
Skip Skip
// Post defines commands that should be run after the main operation, such as post-installation steps.
Post command.Commands
// Mode defines the operating mode for the tool, potentially controlling behavior such as silent mode or verbose
// mode.
Mode Mode
// Settings contains custom settings or options that modify the behavior of the tool.
Settings Settings
// Env defines the environment variables that are applied when running the tool.
Env env.Env
// Check defines a set of instructions for verifying the tool's integrity or functionality.
Check Checker
// NoVerifySSL specifies whether SSL verification should be disabled when fetching the tool.
NoVerifySSL bool `yaml:"no_verify_ssl"`
}
Tool represents a single tool configuration. It contains various fields that specify details such as the tool's name, version, path, execution settings, platform-specific settings, environment variables, and custom strategies for downloading, testing, or deploying.
func (*Tool) ApplyDefaults ¶
ApplyDefaults applies default values to the Tool configuration. If a field is empty or nil, it is replaced with the corresponding default from the Defaults struct. TODO(Idelchi): Improve - what if someone wants a value to be ""? TODO(Idelchi): Perhaps SetSliceIfNil should be SetSliceIfZero?
func (*Tool) CheckSkipConditions ¶
CheckSkipConditions verifies whether the tool should be skipped based on its tags or strategy.
func (*Tool) Resolve ¶
Resolve attempts to resolve the tool's source and strategy based on the provided tags. It handles fallbacks and applies templating to the tool's fields as needed.
func (*Tool) TemplateFirst ¶
Template applies templating to various fields of the Tool struct, such as version, path, and checksum. It processes these fields using Go templates and updates them with the templated values.
func (*Tool) TemplateLast ¶
func (*Tool) UnmarshalYAML ¶
UnmarshalYAML implements custom unmarshaling for Tool with KnownFields check. This allows the Tool to be unmarshaled from YAML while verifying that only known fields are present, ensuring stricter validation and preventing unexpected fields.
type Version ¶
type Version struct {
// Version holds the string representation of the parsed version.
Version string
// Commands contains the list of command strategies used to extract the version.
Commands unmarshal.SingleOrSliceType[string]
// Patterns contains the list of regex patterns for parsing the version from output strings.
Patterns unmarshal.SingleOrSliceType[string]
}
Version represents the version configuration for a tool.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package sources provides abstractions for handling various types of installation sources, including GitHub repositories, direct URLs, Go projects, and command-based sources.
|
Package sources provides abstractions for handling various types of installation sources, including GitHub repositories, direct URLs, Go projects, and command-based sources. |
|
command
Package command provides utilities to manage and execute shell commands.
|
Package command provides utilities to manage and execute shell commands. |
|
common
Package common provides shared utilities and types used across various modules, including functions for handling downloads, metadata management, file operations, and installation processes.
|
Package common provides shared utilities and types used across various modules, including functions for handling downloads, metadata management, file operations, and installation processes. |
|
github
Package github provides functionality for interacting with GitHub repositories, including fetching release information, matching assets to specific requirements, and downloading files from repository releases.
|
Package github provides functionality for interacting with GitHub repositories, including fetching release information, matching assets to specific requirements, and downloading files from repository releases. |
|
go
Package goc provides functionality for handling Go-based installations and managing Go commands using GitHub repositories.
|
Package goc provides functionality for handling Go-based installations and managing Go commands using GitHub repositories. |
|
url
Package url provides functionality to handle URLs as sources for downloading and managing files.
|
Package url provides functionality to handle URLs as sources for downloading and managing files. |