hooks

package
v4.8.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package hooks runs user-defined shell hooks from ~/.ezstack/hooks/.

Exit-code contract:

  • pre-* hooks abort the action on non-zero exit (Run returns an error)
  • post-* hooks only warn on non-zero exit (callers should log but not fail)

Hooks are never invoked via a shell; the file at ~/.ezstack/hooks/<name> is executed directly, so it must have the executable bit set and include a shebang line if it is a script. Non-existent, non-executable, or directory entries are treated as "no hook installed" (a no-op).

Context is passed via environment variables so hooks can make informed decisions without re-parsing ezstack state:

EZS_HOOK        — hook name (e.g. "pre-push")
EZS_REPO_ROOT   — absolute path to the repo
EZS_BRANCH      — current branch (if known)
EZS_STACK_HASH  — current stack hash (if known)
EZS_STACK_NAME  — current stack name (if set)

Callers build a Context and pass it to Run. Missing fields are simply omitted from the environment.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exists

func Exists(name string) bool

Exists reports whether an executable hook with the given name is installed.

func HooksDir

func HooksDir() (string, error)

HooksDir returns the absolute path to the hooks directory. It does not create the directory.

func Run

func Run(name string, ctx *Context) error

Run executes ~/.ezstack/hooks/<name> if it exists and is executable. A non-existent hook is a no-op. A non-zero exit from a hook is returned as an error (callers decide whether that's fatal or a warning).

Hook stdout/stderr/stdin are inherited so hooks can interact with the user.

Types

type Context

type Context struct {
	RepoRoot  string
	Branch    string
	StackHash string
	StackName string
	// Extra lets callers inject additional EZS_* vars without plumbing new
	// fields through; keys are used verbatim so callers must include any
	// prefix they want.
	Extra map[string]string
}

Context carries optional metadata that ezstack exposes to hooks via env vars. All fields are optional; empty fields are not set in the environment.

Jump to

Keyboard shortcuts

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