hooks

package
v0.0.0-...-2b706d3 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecInterface

type ExecInterface interface {
	Command(env []string, stdout io.Writer, stderr io.Writer, stdin io.Reader, name string, arg ...string) ShellCommand
}

ExecInterface is an interface for running shell commands in the OS

type HookExecOpts

type HookExecOpts struct {
	Directory string
	Hook      HookScript
	Args      map[string]string
	Env       map[string]string
	Stdin     io.Reader
	Stdout    io.Writer
	Stderr    io.Writer
	Exec      ExecInterface
}

type HookExecutor

type HookExecutor interface {
	Execute(ctx context.Context, opts HookExecOpts) (response string, err error)
}

func GetHookExecutor

func GetHookExecutor(ios iostreams.IOStreamer, cfg SDKCLIConfig) HookExecutor

type HookExecutorDefaultProtocol

type HookExecutorDefaultProtocol struct {
	IO iostreams.IOStreamer
}

HookExecutorDefaultProtocol uses the original protocol between the CLI and the SDK where diagnostic info and hook responses come in via stdout. Data outside the expected JSON payload is ignored, with the exception of the 'start' hook, for which it is printed.

func (*HookExecutorDefaultProtocol) Execute

Execute processes the data received by the SDK.

type HookExecutorMessageBoundaryProtocol

type HookExecutorMessageBoundaryProtocol struct {
	IO iostreams.IOStreamer
}

HookExecutorMessageBoundaryProtocol uses a protocol between the CLI and the SDK where diagnostic info and hook responses come in via stdout, and hook responses are wrapped in a string denoting the message boundary. Only one message payload can be received.

func (*HookExecutorMessageBoundaryProtocol) Execute

Execute processes the data received by the SDK.

type HookScript

type HookScript struct {
	Command string
	Name    string
}

HookScript maps to specific hook commands listed out in hooks.json

func (HookScript) Get

func (s HookScript) Get() (string, error)

Get checks if the hook command has been initialised and returns the command string

func (HookScript) IsAvailable

func (s HookScript) IsAvailable() bool

IsAvailable returns true when the HookScript.Command exists

func (*HookScript) UnmarshalJSON

func (s *HookScript) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the Unmarshaller interface so that HookScript objects can decode themselves.

The Name field should be dynamically overwritten at SDK Config initialization time.

Read more: https://pkg.go.dev/encoding/json#Unmarshaler

type MockCommand

type MockCommand struct {
	MockStdout []byte
	MockStderr []byte
	Err        error
	Env        []string
	Args       map[string]string
	StdoutIO   io.ReadCloser
	StderrIO   io.ReadCloser
	// contains filtered or unexported fields
}

func (*MockCommand) CombinedOutput

func (c *MockCommand) CombinedOutput() ([]byte, error)

func (*MockCommand) Run

func (c *MockCommand) Run() error

func (*MockCommand) Start

func (c *MockCommand) Start() error

func (*MockCommand) StderrPipe

func (c *MockCommand) StderrPipe() (io.ReadCloser, error)

func (*MockCommand) StdoutPipe

func (c *MockCommand) StdoutPipe() (io.ReadCloser, error)

func (*MockCommand) Wait

func (c *MockCommand) Wait() error

type MockExec

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

Mock that implements ExecInterface for testing

func (*MockExec) Command

func (e *MockExec) Command(env []string, stdout io.Writer, stderr io.Writer, stdin io.Reader, name string, arg ...string) ShellCommand

type MockHookExecutor

type MockHookExecutor struct {
	mock.Mock
}

func (*MockHookExecutor) Execute

func (m *MockHookExecutor) Execute(ctx context.Context, opts HookExecOpts) (string, error)

type Protocol

type Protocol string

Protocol versions understood by the CLI

const (
	HookProtocolDefault Protocol = "default"
	HookProtocolV2      Protocol = "message-boundaries"
)

func (Protocol) String

func (p Protocol) String() string

func (Protocol) Valid

func (p Protocol) Valid() bool

Valid returns true if this protocol is understood by the CLI.

type ProtocolVersions

type ProtocolVersions []Protocol

func (ProtocolVersions) Preferred

func (pv ProtocolVersions) Preferred() Protocol

Preferred returns the first valid protocol present in the SDK config. Lower indices in the array of protocols received from the SDK config are interpreted as more recent or preferred protocol versions.

type SDKCLIConfig

type SDKCLIConfig struct {
	Runtime string `json:"runtime,omitempty"` // Optional, runtime version e.g. deno, deno1.x
	Hooks   struct {
		BuildProject  HookScript `json:"build,omitempty"`
		CheckUpdate   HookScript `json:"check-update,omitempty"`
		Deploy        HookScript `json:"deploy,omitempty"`
		Doctor        HookScript `json:"doctor,omitempty"`
		GetHooks      HookScript `json:"get-hooks,omitempty"`
		GetManifest   HookScript `json:"get-manifest,omitempty"`
		GetTrigger    HookScript `json:"get-trigger,omitempty"`
		InstallUpdate HookScript `json:"install-update,omitempty"`
		Start         HookScript `json:"start,omitempty"`
	} `json:"hooks,omitempty"`
	Config struct {
		Watch                WatchOpts        `json:"watch,omitempty"`
		SDKManagedConnection bool             `json:"sdk-managed-connection-enabled,omitempty"`
		TriggerPaths         []string         `json:"trigger-paths,omitempty"`
		SupportedProtocols   ProtocolVersions `json:"protocol-version,omitempty"`
	} `json:"config,omitempty"`

	WorkingDirectory string
}

SDKCLIConfig contains configuration for communication between the CLI and the SDK. It is set by merging the app's local hooks.json and the response from the `get-hooks` hook.

func NewSDKConfigMock

func NewSDKConfigMock() SDKCLIConfig

NewSDKConfigMock returns a mock of the SDKCLIConfig struct

func (*SDKCLIConfig) Exists

func (s *SDKCLIConfig) Exists() (bool, error)

Exists returns true when the SDKCLIConfig was successfully loaded, otherwise false with an error

type ShellCommand

type ShellCommand interface {
	Run() error
	CombinedOutput() ([]byte, error)
	StdoutPipe() (io.ReadCloser, error)
	StderrPipe() (io.ReadCloser, error)
	Start() error
	Wait() error
}

type ShellExec

type ShellExec struct{}

func (ShellExec) Command

func (sh ShellExec) Command(env []string, stdout io.Writer, stderr io.Writer, stdin io.Reader, name string, arg ...string) ShellCommand

Command creates a command ready to be run with the current processes shell

type WatchOpts

type WatchOpts struct {
	FilterRegex string   `json:"filter-regex,omitempty"`
	Paths       []string `json:"paths,omitempty"`
}

func (*WatchOpts) IsAvailable

func (w *WatchOpts) IsAvailable() bool

IsAvailable returns if watch options exist

Jump to

Keyboard shortcuts

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