mindl

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package mindl contains the core functionality of mindl

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
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.

View Source
var FuncMap = map[string]any{
	"title":  Title,
	"x86_64": X8664,
}

FuncMap contains template functions used by Template.

Functions

func Arch

func Arch() string

Arch returns the value of MINDL_ARCH or runtime.GOARCH.

func MakeExecutable

func MakeExecutable(target string) error

MakeExecutable marks the file at the given path executable without changing other bits.

func OS

func OS() string

OS returns the value of MINDL_OS or runtime.GOOS.

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

func Title(in string) string

Title is a simplistic implementation of the deprecated strings.Title. It does not handle unicode.

func Unarchive

func Unarchive(archive, target, output string) error

Unarchive extracts target from archive to output. For paths ending in .zip Unzip is used. Otherwise Untar is used.

func Untar

func Untar(archive, target, output string) error

Untar extracts target from a tar archive to output.

func Unzip

func Unzip(archive, target, output string) error

Unzip extracts target from a zip archive to output.

func X8664

func X8664(in string) string

X8664 returns "x86_64" if the input is "amd64", otherwise it returns the input verbatim.

Types

type CommonTool

type CommonTool struct {
	URL       string
	InArchive string
}

CommonTool records the templates used for a commonly used tool.

type Target

type Target struct {
	OS   string
	Arch string
}

Target is an OS/Arch combination.

func CurrentTarget

func CurrentTarget() Target

CurrentTarget returns the Target for the current OS and architecture.

func DeduplicateTargets

func DeduplicateTargets(targets []Target) []Target

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.

func (*ToolHandler) Move

func (th *ToolHandler) Move(dst string) error

Move moves the extracted file to dst. It attempts os.Rename first, falling back to a copy for cross-filesystem moves.

Jump to

Keyboard shortcuts

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