bindown

package
v4.11.2 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CurrentSystem = System(runtime.GOOS + "/" + runtime.GOARCH)

CurrentSystem is the system that bindown is running on

View Source
var GoDists string

Functions

func EncodeYaml

func EncodeYaml(w io.Writer, v any) (errOut error)

func FileExists added in v4.8.0

func FileExists(path string) bool

FileExists asserts that a file exist or symlink exists. Returns false for symlinks pointing to non-existent files.

func MapKeys added in v4.6.1

func MapKeys[M ~map[K]V, K comparable, V any](m M) []K

func SortBySemverOrString added in v4.3.0

func SortBySemverOrString(vals []string)

func Unique added in v4.3.0

func Unique[V comparable](vals, buf []V) []V

Unique appends unique values from vals to buf and returns buf

Types

type AddDependencyFromTemplateOpts

type AddDependencyFromTemplateOpts struct {
	TemplateSource string
	DependencyName string
	Vars           map[string]string
}

AddDependencyFromTemplateOpts options for AddDependencyFromTemplate

type Config

type Config struct {
	// The directory where bindown will cache downloads and extracted files. This is relative to the directory where
	// the configuration file resides. cache paths should always use / as a delimiter even on Windows or other
	// operating systems where the native delimiter isn't /.
	Cache string `json:"cache,omitempty" yaml:"cache,omitempty"`

	// The directory that bindown installs files to. This is relative to the directory where the configuration file
	// resides. install_directory paths should always use / as a delimiter even on Windows or other operating systems
	// where the native delimiter isn't /.
	InstallDir string `json:"install_dir,omitempty" yaml:"install_dir,omitempty"`

	// List of systems supported by this config. Systems are in the form of os/architecture.
	Systems []System `json:"systems,omitempty" yaml:"systems,omitempty"`

	// Dependencies available for bindown to install.
	Dependencies map[string]*Dependency `json:"dependencies,omitempty" yaml:",omitempty"`

	// Templates that can be used by dependencies in this file.
	Templates map[string]*Dependency `json:"templates,omitempty" yaml:",omitempty"`

	// Upstream sources for templates.
	TemplateSources map[string]string `json:"template_sources,omitempty" yaml:"template_sources,omitempty"`

	// Checksums of downloaded files.
	URLChecksums map[string]string `json:"url_checksums,omitempty" yaml:"url_checksums,omitempty"`

	Filename string `json:"-" yaml:"-"`
}

func ConfigFromYAML

func ConfigFromYAML(ctx context.Context, data []byte) (*Config, error)

func NewConfig

func NewConfig(ctx context.Context, cfgSrc string, noDefaultDirs bool) (*Config, error)

NewConfig loads a config from a URL

func (*Config) AddChecksums

func (c *Config) AddChecksums(dependencies []string, systems []System) error

AddChecksums downloads, calculates checksums and adds them to the config's URLChecksums. AddChecksums skips urls that already exist in URLChecksums.

func (*Config) AddDependencyFromTemplate

func (c *Config) AddDependencyFromTemplate(ctx context.Context, templateName string, opts *AddDependencyFromTemplateOpts) (*Dependency, map[string][]string, error)

AddDependencyFromTemplate adds a dependency to the config. Returns a map of known values for template vars

func (*Config) BinName

func (c *Config) BinName(depName string, system System) (string, error)

BinName returns the bin name for a downloader on a given system

func (*Config) BuildDependency

func (c *Config) BuildDependency(depName string, system System) (*Dependency, error)

BuildDependency returns a dependency with templates and overrides applied and variables interpolated for the given system.

func (*Config) ClearCache

func (c *Config) ClearCache() error

func (*Config) CopyTemplateFromSource

func (c *Config) CopyTemplateFromSource(ctx context.Context, src, srcTemplate, destName string) error

CopyTemplateFromSource copies a template from source

func (*Config) DependencyNames added in v4.10.0

func (c *Config) DependencyNames() []string

func (*Config) DependencySystems

func (c *Config) DependencySystems(depName string) ([]System, error)

DependencySystems returns the supported systems of either the config or the dependency if one is not empty if both are not empty, it returns the intersection of the lists

func (*Config) DownloadDependencies added in v4.10.0

func (c *Config) DownloadDependencies(deps []string, system System, opts *ConfigDownloadDependenciesOpts) error

func (*Config) ExtractDependencies added in v4.10.0

func (c *Config) ExtractDependencies(deps []string, system System, opts *ConfigExtractDependenciesOpts) error

func (*Config) InstallDependencies added in v4.8.0

func (c *Config) InstallDependencies(deps []string, system System, opts *ConfigInstallDependenciesOpts) error

func (*Config) ListTemplates

func (c *Config) ListTemplates(ctx context.Context, templateSource string) ([]string, error)

ListTemplates lists templates available in this config or one of its template sources.

func (*Config) MissingDependencyVars

func (c *Config) MissingDependencyVars(depName string) ([]string, error)

MissingDependencyVars returns a list of vars that are required but undefined

func (*Config) PruneChecksums

func (c *Config) PruneChecksums() error

PruneChecksums removes checksums for dependencies that are not used by any configured system.

func (*Config) SetDependencyVars

func (c *Config) SetDependencyVars(depName string, vars map[string]string) error

SetDependencyVars sets the value of a dependency's var. Adds or Updates the var.

func (*Config) SetTemplateVars

func (c *Config) SetTemplateVars(tmplName string, vars map[string]string) error

SetTemplateVars sets the value of a template's var. Adds or Updates the var.

func (*Config) UnsetDependencyVars

func (c *Config) UnsetDependencyVars(depName string, vars []string) error

UnsetDependencyVars removes a dependency var. Noop if the var doesn't exist.

func (*Config) UnsetTemplateVars

func (c *Config) UnsetTemplateVars(tmplName string, vars []string) error

UnsetTemplateVars removes a template var. Noop if the var doesn't exist.

func (*Config) Validate

func (c *Config) Validate(depName string, systems []System) (errOut error)

Validate installs the downloader to a temporary directory and returns an error if it was unsuccessful.

func (*Config) WrapDependencies added in v4.10.0

func (c *Config) WrapDependencies(deps []string, opts *ConfigWrapDependenciesOpts) error

func (*Config) WriteFile

func (c *Config) WriteFile(outputJSON bool) (errOut error)

type ConfigDownloadDependenciesOpts added in v4.10.0

type ConfigDownloadDependenciesOpts struct {
	Force                bool
	AllowMissingChecksum bool
	AllDeps              bool
	Stdout               io.Writer
}

type ConfigExtractDependenciesOpts added in v4.10.0

type ConfigExtractDependenciesOpts struct {
	AllowMissingChecksum bool
	AllDeps              bool
	Stdout               io.Writer
}

type ConfigInstallDependenciesOpts added in v4.8.0

type ConfigInstallDependenciesOpts struct {
	Output               string
	TargetDir            string
	Stdout               io.Writer
	Force                bool
	AllowMissingChecksum bool
	ToCache              bool
	AllDeps              bool
}

ConfigInstallDependenciesOpts provides options for Config.InstallDependencies

type ConfigInstallDependencyOpts

type ConfigInstallDependencyOpts struct {
	// TargetPath is the path where the executable should end up
	TargetPath string
	// Force - install even if it already exists
	Force bool
	// AllowMissingChecksum - whether to allow missing checksum
	AllowMissingChecksum bool
	// ToCache - if set, the dependency will be installed to a cache directory. ToCache overrides TargetPath.
	ToCache bool
}

ConfigInstallDependencyOpts provides options for Config.InstallDependency

type ConfigWrapDependenciesOpts added in v4.10.0

type ConfigWrapDependenciesOpts struct {
	Output               string
	BindownExec          string
	BindownTag           string
	BindownWrapped       string
	BaseURL              string
	AllowMissingChecksum bool
	AllDeps              bool
	Stdout               io.Writer
}

type Dependency

type Dependency struct {
	// The homepage for this dependency. Informational only.
	Homepage *string `json:"homepage,omitempty" yaml:",omitempty"`

	// A description of the dependency. Informational only.
	Description *string `json:"description,omitempty" yaml:",omitempty"`

	// A template for this dependency. Value is the name of a template in the templates section of this config.
	// Any unset fields in this dependency will be set by values from the template. Overrides in the dependency
	// and its template are concatenated with the template's overrides coming first. Vars and substitutions
	// are both combined with the dependency's value taking precedence.
	Template *string `json:"template,omitempty" yaml:",omitempty"`

	Overrideable `json:",inline" yaml:",inline"`

	// List of systems this dependency supports. Systems are in the form of os/architecture.
	Systems []System `json:"systems,omitempty" yaml:"systems,omitempty"`

	// A list of variables that must be present for an install to succeed
	RequiredVars []string `json:"required_vars,omitempty" yaml:"required_vars,omitempty"`
	// contains filtered or unexported fields
}

type DependencyOverride

type DependencyOverride struct {
	// Limits the override to configurations matching all of the matchers. Keys may be "os", "arch" or any variable name.
	// Values are an array of values to match. Any matching value will match. If a value can be interpreted as a
	// semantic version it will be treated as such.
	OverrideMatcher map[string][]string `json:"matcher" yaml:"matcher,omitempty"`

	// Values to override the parent dependency
	Dependency Overrideable `json:"dependency" yaml:"dependency,omitempty"`
}

type Overrideable

type Overrideable struct {
	// The url to download a dependency from.
	URL *string `json:"url,omitempty" yaml:",omitempty"`

	// The path in the downloaded archive where the binary is located. Default is ./<bin>
	ArchivePath *string `json:"archive_path,omitempty" yaml:"archive_path,omitempty"`

	// The name of the binary to be installed. Default is the name of the dependency.
	BinName *string `json:"bin,omitempty" yaml:"bin,omitempty"`

	// Whether to create a symlink to the bin instead of copying it.
	Link *bool `json:"link,omitempty" yaml:",omitempty"`

	// A list of variables that can be used in 'url', 'archive_path' and 'bin'.
	//
	// Two variables are always added based on the current environment: 'os' and 'arch'. Those are the operating
	// system and architecture as defined by go's GOOS and GOARCH variables. I should document what those are
	// somewhere.
	//
	// You can reference a variable using golang template syntax. For example, you could have a url set to
	// `https://example.org/mydependency/v{{.version}}/mydependency-{{.os}}-{{.arch}}.tar.gz`.  If you define the var
	// 'version: 1.2.3' and run bindown on a 64-bit Linux system, it will download
	// `https://example.org/mydependency/v1.2.3/mydependency-linux-amd64.tar.gz`.
	Vars map[string]string `json:"vars,omitempty" yaml:",omitempty"`

	// Overrides allows you to override values depending on the os and architecture of the target system.
	Overrides []DependencyOverride `json:"overrides,omitempty" yaml:",omitempty"`

	// Substitutions will substitute values from vars. The key is the name of the variable to substitute. The value is
	// a map of substitutions. { "os": { "linux": "Linux", "darwin": "MacOS" } } is an example of a substitution that
	// will update the os variable.
	Substitutions map[string]map[string]string `json:"substitutions,omitempty" yaml:",omitempty"`
}

type System

type System string

System is a string that represents a target system in the form of "os/architecture"

func (System) Arch

func (s System) Arch() string

func (System) OS

func (s System) OS() string

Jump to

Keyboard shortcuts

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