tool

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2025 License: MIT Imports: 37 Imported by: 0

Documentation

Overview

Package tool provides core functionality for managing tool configurations.

Package tool provides core functionality for managing tool configurations.

Package tool provides core functionality for managing tool configurations.

Package tool provides core functionality for managing tool configurations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TemplateError

func TemplateError(err error, name string) error

TemplateError wraps an error with additional context about the template name.

Types

type ResolveOption added in v0.0.13

type ResolveOption func(*resolveOptions)

ResolveOption is a functional option type for the Resolve method.

func WithUpUntilVersion added in v0.0.13

func WithUpUntilVersion() ResolveOption

WithUpUntilVersion returns a ResolveOption that enables version checking up to a specific version. This option enables version comparison during tool resolution.

func WithoutURL added in v0.0.13

func WithoutURL() ResolveOption

WithoutURL returns a ResolveOption that skips URL resolution. This option disables URL-related processing during tool resolution.

func WithoutVersion added in v0.0.13

func WithoutVersion() ResolveOption

WithoutVersion returns a ResolveOption that skips version resolution. This option disables version-related processing during tool resolution.

type Tool

type Tool struct {
	// Name of the tool, usually a short identifier or title.
	Name string `json:"name"          mapstructure:"name"          single:"true" validate:"required" yaml:"name"`
	// Description of the tool, giving more context about its purpose.
	Description string `json:"description"   mapstructure:"description"                                     yaml:"description"`
	// Version specifies the version of the tool.
	Version version.Version `json:"version"       mapstructure:"version"                                         yaml:"version"`
	// Path represents the URL where the tool can be downloaded from.
	URL string `json:"url"           mapstructure:"url"                                             yaml:"url"`
	// Output defines the output path where the tool will be installed or extracted.
	Output string `json:"output"        mapstructure:"output"                                          yaml:"output"`
	// Exe specifies the executable details for the tool, such as patterns or names for locating the binary.
	Exe exe.Exe `json:"exe"           mapstructure:"exe"                                             yaml:"exe"`
	// Platform defines the platform-specific details for the tool, including OS and architecture constraints.
	Platform detect.Platform `json:"platform"      mapstructure:"platform"                                        yaml:"platform"`
	// Aliases represent alternative names or shortcuts for the tool.
	Aliases aliases.Aliases `json:"aliases"       mapstructure:"aliases"                                         yaml:"aliases"`
	// Values contains custom values or variables used in the tool's configuration.
	Values values.Values `json:"values"        mapstructure:"values"                                          yaml:"values"`
	// Fallbacks defines fallback configurations in case the primary configuration fails.
	Fallbacks fallbacks.Fallbacks `json:"fallbacks"     mapstructure:"fallbacks"                                       yaml:"fallbacks"`
	// Hints provide additional matching patterns or heuristics for the tool.
	Hints *hints.Hints `json:"hints"         mapstructure:"hints"                                           yaml:"hints"`
	// Source defines the source configuration, which determines how the tool is fetched (e.g., GitHub, local files).
	Source sources.Source `json:"source"        mapstructure:"source"                                          yaml:"source"`
	// Commands contains a set of commands that can be executed in the context of the tool.
	Commands command.Commands `json:"commands"      mapstructure:"commands"                                        yaml:"commands"`
	// Tags are labels or markers that can be used to categorize or filter the tool.
	Tags tags.Tags `json:"tags"          mapstructure:"tags"                                            yaml:"tags"`
	// Strategy defines how the tool is deployed, fetched, or managed (e.g., download strategies, handling retries).
	Strategy strategy.Strategy `json:"strategy"      mapstructure:"strategy"                                        yaml:"strategy"`
	// Skip defines conditions under which certain steps (e.g., downloading, testing) are skipped.
	Skip skip.Skip `json:"skip"          mapstructure:"skip"                                            yaml:"skip"`
	Mode mode.Mode `json:"mode"          mapstructure:"mode"                                            yaml:"mode"`
	// Env defines the environment variables that are applied when running the tool.
	Env env.Env `json:"env"           mapstructure:"env"                                             yaml:"env"`
	// NoVerifySSL specifies whether SSL verification should be disabled when fetching the tool.
	NoVerifySSL bool `json:"no-verify-ssl" mapstructure:"no-verify-ssl"                                   yaml:"no-verify-ssl"`
	// NoCache disables cache interaction
	NoCache bool `json:"no-cache"      mapstructure:"no-cache"                                        yaml:"no-cache"`
	// Inherit is used to determine which default configurations the tool should inherit from.
	Inherit *inherit.Inherit `json:"inherit"       mapstructure:"inherit"                                         yaml:"inherit"`
	// contains filtered or unexported fields
}

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 MergeLeftToRight added in v0.0.13

func MergeLeftToRight(others ...*Tool) (*Tool, error)

MergeLeftToRight merges the provided tools into a new tool, left to right.

func MergeRightToLeft added in v0.0.13

func MergeRightToLeft(others ...*Tool) (*Tool, error)

MergeRightToLeft merges the provided tools into a new tool, right to left.

func NewEmptyTool added in v0.0.13

func NewEmptyTool() *Tool

NewEmptyTool returns an empty tool to make sure that no pointers are nil.

func (Tool) AbsPath

func (t Tool) AbsPath() string

AbsPath returns the absolute path of the tool's executable.

func (*Tool) CheckSkipConditions

func (t *Tool) CheckSkipConditions(tags tags.IncludeTags) result.Result

CheckSkipConditions determines if a tool should be skipped based on its tags, strategy, and skip conditions. Returns a Result with the skip status and reason.

func (*Tool) Copied added in v0.0.13

func (t *Tool) Copied() (*Tool, error)

Copied creates and returns a deep copy of the Tool instance.

func (*Tool) CopiedYAML added in v0.0.13

func (t *Tool) CopiedYAML() (*Tool, error)

CopiedYAML creates a new Tool instance by marshaling to YAML and unmarshaling. Returns a new Tool instance created through YAML serialization.

func (*Tool) Copy

func (t *Tool) Copy() error

Copy copies the Tool instance and sets it to itself.

func (*Tool) CopyYAML added in v0.0.13

func (t *Tool) CopyYAML() error

CopyYAML performs a YAML-based copy operation on the tool. It marshals the tool to YAML and then unmarshals it back.

func (Tool) Debug added in v0.0.13

func (t Tool) Debug(tool, s string)

Debug prints debug information for the tool if the tool name matches the specified tool.

func (*Tool) DisableCache

func (t *Tool) DisableCache()

DisableCache removes the cache from the Tool instance.

func (*Tool) Download

func (t *Tool) Download(_ context.Context, progressListener getter.ProgressTracker) result.Result

Download retrieves and installs the tool using its configured source and installer. It handles progress tracking and executes any post-installation commands. Returns a Result indicating success or failure with detailed messages.

func (*Tool) EnableCache

func (t *Tool) EnableCache(cache *cache.Cache)

EnableCache sets the cache for the Tool instance.

func (Tool) Exists

func (t Tool) Exists() bool

Exists checks if the tool's executable exists in the configured output path. Returns true if the file exists and is a regular file.

func (Tool) GetCurrentVersion

func (t Tool) GetCurrentVersion() string

GetCurrentVersion attempts to retrieve the current version of the tool.

func (Tool) GetPopulator added in v0.0.13

func (t Tool) GetPopulator() sources.Populator

GetPopulator returns the last successful populator used by the tool.

func (Tool) GetStrategy

func (t Tool) GetStrategy() strategy.Strategy

GetStrategy returns the tool's strategy.

func (Tool) GetTargetVersion

func (t Tool) GetTargetVersion() string

GetTargetVersion returns the tool's target version.

func (Tool) ID

func (t Tool) ID() string

ID generates a unique identifier for the tool based on its output path and name.

func (*Tool) Marshal added in v0.0.13

func (t *Tool) Marshal() ([]byte, error)

Marshal marshals the tool into a YAML byte slice.

func (*Tool) MergeFrom added in v0.0.13

func (t *Tool) MergeFrom(others ...*Tool) error

MergeFrom merges the current tool with the provided tools, the sequence being.

tool <-- others[0] <-- others[1] <-- others[2]...

func (*Tool) MergeInto added in v0.0.13

func (t *Tool) MergeInto(others ...*Tool) error

MergeInto the current tool into the provided tools, the sequence being.

others[0] <-- others[1] <-- others[2]... <-- tool

func (*Tool) MergePlatform added in v0.0.13

func (t *Tool) MergePlatform(platform detect.Platform)

MergePlatform merges the provided platform into the tool. Only empty fields are set.

func (*Tool) MergeWithOther added in v0.0.13

func (t *Tool) MergeWithOther(other *Tool) error

MergeWithOther behaves like MergeInto, with special handling for slices that need to be appended instead of replaced.

func (*Tool) Resolve

func (t *Tool) Resolve(tags tags.IncludeTags, options ...ResolveOption) result.Result

Resolve attempts to resolve the tool's source and strategy based on the provided tags. It handles environment variables, fallbacks, templating, and validation of the tool's configuration. Returns a Result indicating success or failure with detailed messages.

func (*Tool) Result

func (t *Tool) Result() *result.Result

Result returns the current result of the Tool instance.

func (*Tool) SetResult

func (t *Tool) SetResult(res result.Result)

SetResult sets the current result of the Tool instance.

TODO(Idelchi): Get rid of currentResult. //nolint:godox // TODO comment provides valuable context for future development.

func (*Tool) TemplateFirst

func (t *Tool) TemplateFirst(tmpl *templates.Processor) error

TemplateFirst 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 (t *Tool) TemplateLast(tmpl *templates.Processor) error

TemplateLast applies templating to the remaining fields of the Tool struct. Templates:

  • Exe.Patterns
  • Commands
  • Hints patterns and weights
  • URL

func (*Tool) ToTemplateMap

func (t *Tool) ToTemplateMap(_ ...map[string]any) map[string]any

ToTemplateMap converts the Tool struct to a map suitable for templating. It adds any additional maps provided in the flatten argument to the template map.

func (*Tool) UnmarshalFrom added in v0.0.13

func (t *Tool) UnmarshalFrom(other *Tool) error

UnmarshalFrom unmarshals the tool from another tool.

func (*Tool) UnmarshalInto added in v0.0.13

func (t *Tool) UnmarshalInto(other *Tool) error

UnmarshalInto unmarshals the tool into another tool.

func (*Tool) UnmarshalYAML

func (t *Tool) UnmarshalYAML(node ast.Node) error

UnmarshalYAML implements custom YAML unmarshaling for Tool configuration. Supports both scalar values (treated as tool name) and map values.

func (*Tool) Validate

func (t *Tool) Validate() error

Validate performs structural validation of the Tool's configuration using the validator package. Returns an error if validation fails.

Jump to

Keyboard shortcuts

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