tools

package
v1.23.15 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateInlineTempScript added in v1.23.15

func CreateInlineTempScript(
	hookName, ext, content string,
) (string, error)

CreateInlineTempScript creates a temp file for an inline hook script with executable permissions. The caller is responsible for cleaning up the returned file.

func EnsureInstalled

func EnsureInstalled(ctx context.Context, tools ...ExternalTool) error

EnsureInstalled checks that all tools are installed, returning an error if one or more tools are not.

func ExecuteCommand

func ExecuteCommand(ctx context.Context, commandRunner exec.CommandRunner, cmd string, args ...string) (string, error)

func ExtractVersion

func ExtractVersion(cliOutput string) (semver.Version, error)

ExtractVersion extracts a major.minor.patch version number from a typical CLI version flag output.

minor and patch version numbers are both optional, treated as 0 if not found.

func WithInstalledCheckCache

func WithInstalledCheckCache(ctx context.Context) context.Context

Types

type ErrSemver

type ErrSemver struct {
	ToolName    string
	VersionInfo VersionInfo
}

func (*ErrSemver) Error

func (err *ErrSemver) Error() string

type ExecutionContext added in v1.23.15

type ExecutionContext struct {
	// Cwd is the working directory for execution.
	Cwd string

	// EnvVars is the merged environment for the process, including
	// resolved secrets and the azd environment.
	EnvVars []string

	// BoundaryDir is the project or service root directory.
	// Executors may walk upward from the script to BoundaryDir
	// to discover dependency files (requirements.txt, package.json).
	BoundaryDir string

	// Interactive controls whether stdin is attached.
	Interactive *bool

	// StdOut overrides the default stdout for the process.
	StdOut io.Writer

	// InlineScript contains the raw script content for inline hooks.
	// When set, the executor creates a temp file in Prepare() with
	// the appropriate extension and content wrapper (e.g., shebang
	// for bash). When empty, scriptPath is used directly as a file
	// path.
	InlineScript string

	// HookName is the descriptive name of the hook (e.g.,
	// "preprovision"). Used by executors for temp file naming to
	// aid debuggability.
	HookName string
}

ExecutionContext provides the per-invocation execution environment for a hook. The HooksRunner constructs this from the validated HookConfig, resolving secrets, merging directories, and building the environment.

type ExternalTool

type ExternalTool interface {
	CheckInstalled(ctx context.Context) error
	InstallUrl() string
	Name() string
}

func Unique

func Unique(tools []ExternalTool) []ExternalTool

Unique filters a slice of tools such that a tool with a given name only appears once.

type HookExecutor added in v1.23.15

type HookExecutor interface {
	// Prepare performs pre-execution setup such as runtime validation,
	// virtual environment creation, dependency installation, or temp
	// file creation for inline scripts.
	Prepare(ctx context.Context, scriptPath string, execCtx ExecutionContext) error

	// Execute runs the hook at the given path.
	Execute(ctx context.Context, scriptPath string, execCtx ExecutionContext) (exec.RunResult, error)

	// Cleanup removes any temporary resources created during Prepare.
	// Called by the hooks runner after Execute completes, regardless
	// of success or failure. Implementations must be safe to call
	// even when Prepare was not called or created no resources.
	Cleanup(ctx context.Context) error
}

HookExecutor is the unified interface for all hook execution. Every executor follows a three-phase lifecycle:

  1. Prepare — validate prerequisites, resolve tools, create temp files
  2. Execute — run the hook
  3. Cleanup — remove temporary resources created during Prepare

type MissingToolErrors

type MissingToolErrors struct {
	Errs      []error
	ToolNames []string
}

MissingToolErrors wraps a set of errors discovered when probing for tools and implements the Error interface to pretty print the underlying errors. We use this instead of the existing `multierr` package we use elsewhere, because we want to control the error string (the default one produced by multierr is not as nice as what we do here).

func (*MissingToolErrors) Error

func (m *MissingToolErrors) Error() string

type VersionInfo

type VersionInfo struct {
	MinimumVersion semver.Version
	UpdateCommand  string
}

Directories

Path Synopsis
Package language provides project file discovery and dependency management for multi-language hook scripts.
Package language provides project file discovery and dependency management for multi-language hook scripts.

Jump to

Keyboard shortcuts

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