Documentation
¶
Overview ¶
Package mindl contains the core functionality of mindl
Index ¶
- Variables
- func Arch() string
- func MakeExecutable(target string) error
- func OS() string
- func ShouldUpdate() bool
- func Template(text string, data *TemplateData) (string, error)
- func Title(in string) string
- func Unarchive(archive, target, output string) error
- func Untar(archive, target, output string) error
- func Unzip(archive, target, output string) error
- func X8664(in string) string
- type CommonTool
- type Target
- type TemplateData
- type Tool
- type ToolHandler
Constants ¶
This section is empty.
Variables ¶
var CommonTargets = []Target{
{OS: "linux", Arch: "amd64"},
{OS: "linux", Arch: "arm64"},
{OS: "darwin", Arch: "amd64"},
{OS: "darwin", Arch: "arm64"},
{OS: "windows", Arch: "amd64"},
}
CommonTargets contains common OS/Arch combinations.
var CommonTools = map[string]CommonTool{
"golangci-lint": {
URL: "https://github.com/golangci/golangci-lint/releases/download/v{{.Version}}/golangci-lint-{{.Version}}-{{.OS}}-{{.Arch}}.{{.OSArchive}}",
InArchive: "golangci-lint-{{.Version}}-{{.OS}}-{{.Arch}}/golangci-lint{{.Exe}}",
},
"mkcert": {
URL: "https://github.com/FiloSottile/mkcert/releases/download/v{{.Version}}/mkcert-v{{.Version}}-{{.OS}}-{{.Arch}}{{.Exe}}",
InArchive: "",
},
"goreleaser": {
URL: "https://github.com/goreleaser/goreleaser/releases/download/v{{.Version}}/goreleaser_{{.OS | title}}_{{.Arch | x86_64}}.{{.OSArchive}}",
InArchive: "goreleaser{{.Exe}}",
},
"kcp": {
URL: "https://github.com/kcp-dev/kcp/releases/download/v{{.Version}}/kcp_{{.Version}}_{{.OS}}_{{.Arch}}.tar.gz",
InArchive: "bin/kcp",
},
"kubectl": {
URL: "https://dl.k8s.io/v{{.Version}}/kubernetes-client-{{.OS}}-{{.Arch}}.tar.gz",
InArchive: "kubernetes/client/bin/kubectl{{.Exe}}",
},
"setup-envtest": {
URL: "https://github.com/kubernetes-sigs/controller-runtime/releases/download/v{{.Version}}/setup-envtest-{{.OS}}-{{.Arch}}{{.Exe}}",
InArchive: "",
},
}
CommonTools keys commonly used tools to their templates.
var FuncMap = map[string]any{ "title": Title, "x86_64": X8664, }
FuncMap contains template functions used by Template.
Functions ¶
func MakeExecutable ¶
MakeExecutable marks the file at the given path executable without changing other bits.
func ShouldUpdate ¶
func ShouldUpdate() bool
ShouldUpdate returns true if mindl should update the sumdb during execution. This is enabled if the environment variable MINDL_UPDATE contains a truthy value.
func Template ¶
func Template(text string, data *TemplateData) (string, error)
Template parses and executes the given text as a template with the given data.
func Title ¶
Title is a simplistic implementation of the deprecated strings.Title. It does not handle unicode.
func Unarchive ¶
Unarchive extracts target from archive to output. For paths ending in .zip Unzip is used. Otherwise Untar is used.
Types ¶
type CommonTool ¶
CommonTool records the templates used for a commonly used tool.
type Target ¶
Target is an OS/Arch combination.
func CurrentTarget ¶
func CurrentTarget() Target
CurrentTarget returns the Target for the current OS and architecture.
func DeduplicateTargets ¶
DeduplicateTargets returns a deduplicated copy of targets.
type TemplateData ¶
type TemplateData struct {
Version string `json:"version"`
OS string `json:"os"`
Arch string `json:"arch"`
// OSArchive contains an os-dependent archive extension.
// Default is `tar.gz`.
// On windows it is `zip`.
OSArchive string `json:"osarchive"`
// Exe contains `.exe` on windows.
Exe string `json:"exe"`
}
TemplateData holds template rendering context.
func NewTemplateData ¶
func NewTemplateData(os, arch string) *TemplateData
NewTemplateData returns a prepared TemplateData.
type Tool ¶
type Tool struct {
// URLTemplate is templated with [TemplateData].
// See [CommonTools] for examples.
URLTemplate string
// InArchive is the location within the archive.
// If the downloaded file is the file and not an archive leave
// InArchive empty.
InArchive string
}
Tool is the definition of a tool to download.
type ToolHandler ¶
type ToolHandler struct {
// contains filtered or unexported fields
}
ToolHandler is the handler for a tool download.
func Handle ¶
func Handle(tool Tool, td *TemplateData) (*ToolHandler, error)
Handle sets up a ToolHandler.
func (*ToolHandler) Cleanup ¶
func (th *ToolHandler) Cleanup()
Cleanup deletes the temporary files leftover by the download and extraction.
func (*ToolHandler) Download ¶
func (th *ToolHandler) Download(ctx context.Context) error
Download downloads and extracts a tool. If extractTo is empty the file is extracted to a temporary directory.
func (*ToolHandler) Hash ¶
func (th *ToolHandler) Hash(hasher sum.HashPathFunc) (string, error)
Hash runs the given hash func on the tool and returns the result.