bintool

package
v0.0.0-...-31701ed Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BinTool

type BinTool struct {
	// contains filtered or unexported fields
}

BinTool represents a single binary tool/versioncmd combination with the information needed to check and/or install the tool if desired.

The struct provides a set of utilities for checking the existence of a valid versioncmd of the command and installing the command in a way that is scoped to the project at hand, if desired.

func Must

func Must(t *BinTool, err error) *BinTool

Must provides a utility for asserting that methods returning a BinTool and an error have no error. If there is an error, this call will panic.

func New

func New(command, version, url string, opts ...Option) (*BinTool, error)

New initializes a BinTool with the provided command, versioncmd, and download url. Additional options may be provided to configure things such as the versioncmd test command, file extensions and folder containing the binary tool.

The command, url, and versioncmd command may all use text templates to define their formats. If any of these templates fails to compile or evaluate, this call will return an error.

func NewGo

func NewGo(pkg, version string, opts ...Option) (*BinTool, error)

NewGo initializes a BinTool with the provided go package and versioncmd. Additional options may be provided to configure things such as the versioncmd test command and folder containing the binary tool.

func (*BinTool) BinPath

func (t *BinTool) BinPath() string

BinPath returns the absolute path to the binary.

func (*BinTool) Ensure

func (t *BinTool) Ensure() error

Ensure checks to see if a valid versioncmd of the tool is installed, and downloads/installs it if it isn't already.

func (*BinTool) Install

func (t *BinTool) Install() error

Install unconditionally downloads and installs the tool to the configured folder.

If you don't want to download the tool every time, you may prefer Ensure() instead.

func (*BinTool) IsInstalled

func (t *BinTool) IsInstalled() bool

IsInstalled checks whether the correct versioncmd of the tool is currently installed as defined by the versioncmd command.

type Option

type Option func(t *BinTool) error

Option configures a BinTool with optional settings.

func WithArchiveExt

func WithArchiveExt(ext string) Option

WithArchiveExt defines a custom extension to use when identifying an archive via the ArchiveExt template variable. The default archive extension is .tar.gz except for Windows, where it is .zip.

func WithBinExt

func WithBinExt(ext string) Option

WithBinExt defines a custom extension to use when identifying a binary executable via the BinExt template variable. The default binary extension is empty for all operating systems except Windows, where it is .exe.

func WithFolder

func WithFolder(folder string) Option

WithFolder defines a custom folder path where the tool is expected to exist and where it should be installed if desired. Paths will be normalized to the operating system automatically, so unix-style paths are recommended.

func WithVersionCmd

func WithVersionCmd(cmd string) Option

WithVersionCmd defines a custom command used to test the versioncmd of the command for purposes of determining if the command is installed. The provided command is a template that can use any of the template parameters that are available to the url. If no command is provided, the versioncmd check will be skipped.

The default test command is "{{.FullCmd}} --versioncmd".

Jump to

Keyboard shortcuts

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