env

package
v0.0.0-...-9bc967a Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRecover

func CheckRecover(cause interface{}, cb func(int, error)) bool

CheckRecover checks the value of cause, calling the given callback if it's an exitCode error. It returns true if we should re-panic the cause.

It's mainly useful for testing, normally you'd use HandleExitWithCode.

func Exit

func Exit(code int, msg string, args ...interface{})

Exit exits with the given code and error message.

Defer HandleExitWithCode in main to catch this and get the right behavior.

func ExitCause

func ExitCause(code int, err error, msg string, args ...interface{})

ExitCause exits with the given code and error message, automatically wrapping the underlying error passed as well.

Defer HandleExitWithCode in main to catch this and get the right behavior.

func HandleExitWithCode

func HandleExitWithCode()

HandleExitWithCode handles panics of type exitCode, printing the status message and existing with the given exit code, or re-raising if not an exitCode error.

This should be the first defer in your main function.

Types

type Env

type Env struct {

	// Platform is our current platform
	Platform versions.PlatformItem

	// VerifiySum indicates whether or not we should run checksums.
	VerifySum bool
	// NoDownload forces us to not contact GCS, looking only
	// at local files instead.
	NoDownload bool
	// ForceDownload forces us to ignore local files and always
	// contact GCS & re-download.
	ForceDownload bool

	// Client is our remote client for contacting GCS.
	Client *remote.Client

	// Log allows us to log.
	Log logr.Logger

	// Version is the version(s) that we want to download
	// (may be automatically retrieved later on).
	Version versions.Spec

	// Store is used to load/store entries to/from disk.
	Store *store.Store

	// FS is the file system to read from/write to for provisioning temp files
	// for storing the archives temporarily.
	FS afero.Afero

	// Out is the place to write output text to
	Out io.Writer
	// contains filtered or unexported fields
}

Env represents an environment for downloading and otherwise manipulating envtest binaries.

In general, the methods will use the Exit{,Cause} functions from this package to indicate errors. Catch them with a `defer HandleExitWithCode()`.

func (*Env) CheckCoherence

func (e *Env) CheckCoherence()

CheckCoherence checks that this environment has filled-out, coherent settings (e.g. NoDownload & ForceDownload aren't both set).

func (*Env) EnsureBaseDirs

func (e *Env) EnsureBaseDirs(ctx context.Context)

EnsureBaseDirs ensures that the base packed and unpacked directories exist.

This should be the first thing called after CheckCoherence.

func (*Env) EnsureVersionIsSet

func (e *Env) EnsureVersionIsSet(ctx context.Context)

EnsureVersionIsSet ensures that we have a non-wildcard version configured.

If necessary, it will enumerate on-disk and remote versions to accomplish this, finding a version that matches our version selector and platform. It will always yield a concrete version, it *may* yield a concrete platorm as well.

func (*Env) ExistsAndValid

func (e *Env) ExistsAndValid() bool

ExistsAndValid checks if our current (concrete) version & platform exist on disk (unless ForceDownload is set, in which cause it always returns false).

Must be called after EnsureVersionIsSet so that we have a concrete Version selected. Must have a concrete platform, or ForceDownload must be set.

func (*Env) Fetch

func (e *Env) Fetch(ctx context.Context)

Fetch ensures that the requested platform and version are on disk. You must call EnsureVersionIsSet before calling this method.

If ForceDownload is set, we always download, otherwise we only download if we're missing the version on disk.

func (*Env) LatestVersion

func (e *Env) LatestVersion(ctx context.Context) (versions.Concrete, versions.PlatformItem)

LatestVersion returns the latest version matching our version selector and platform from the remote server, with the correspoding checksum for later use as well.

func (*Env) ListVersions

func (e *Env) ListVersions(ctx context.Context)

ListVersions prints out all available versions matching this Env's platform & version selector (respecting NoDownload to figure out whether or not to match remote versions).

func (*Env) PathMatches

func (e *Env) PathMatches(value string) bool

PathMatches checks if the path (e.g. from the environment variable) matches this version & platform selector, and if so, returns true.

func (*Env) PrintInfo

func (e *Env) PrintInfo(printFmt PrintFormat)

PrintInfo prints out information about a single, current version and platform, according to the given formatting info.

func (*Env) Remove

func (e *Env) Remove(ctx context.Context)

Remove removes the data for our version selector & platform from disk.

func (*Env) Sideload

func (e *Env) Sideload(ctx context.Context, input io.Reader)

Sideload takes an input stream, and loads it as if it had been a downloaded .tar.gz file for the current *concrete* version and platform.

type PrintFormat

type PrintFormat int

PrintFormat indicates how to print out fetch and switch results. It's a valid pflag.Value so it can be used as a flag directly.

const (
	// PrintOverview prints human-readable data,
	// including path, version, arch, and checksum (when available).
	PrintOverview PrintFormat = iota
	// PrintPath prints *only* the path, with no decoration.
	PrintPath
	// PrintEnv prints the path with the corresponding env variable, so that
	// you can source the output like
	// `source $(fetch-envtest switch -p env 1.20.x)`.
	PrintEnv
)

func (*PrintFormat) Set

func (f *PrintFormat) Set(val string) error

Set sets the value of this as a flag.

func (PrintFormat) String

func (f PrintFormat) String() string

func (PrintFormat) Type

func (PrintFormat) Type() string

Type is the type of this value as a flag.

Jump to

Keyboard shortcuts

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