Documentation
¶
Index ¶
- Constants
- Variables
- type Event
- type EventDispatcher
- func (ed *EventDispatcher[T]) AddHandler(ctx context.Context, name Event, handler EventHandlerFn[T]) error
- func (ed *EventDispatcher[T]) Invoke(ctx context.Context, name Event, eventArgs T, action InvokeFn) error
- func (ed *EventDispatcher[T]) RaiseEvent(ctx context.Context, name Event, eventArgs T) error
- func (ed *EventDispatcher[T]) RemoveHandler(ctx context.Context, name Event, handler EventHandlerFn[T]) error
- type EventHandlerFn
- type HookConfig
- type HookFilterPredicateFn
- type HookPlatformType
- type HookType
- type HookValidationResult
- type HookWarning
- type HooksConfig
- type HooksManager
- func (h *HooksManager) GetAll(hooks map[string][]*HookConfig) ([]*HookConfig, error)
- func (h *HooksManager) GetByParams(hooks map[string][]*HookConfig, prefix HookType, commands ...string) ([]*HookConfig, error)
- func (h *HooksManager) ValidateHooks(ctx context.Context, allHooks map[string][]*HookConfig) *HookValidationResult
- type HooksRunner
- type InvokeFn
- type ScriptLocation
- type ShellType
Constants ¶
const ( ShellTypeBash ShellType = "sh" ShellTypePowershell ShellType = "pwsh" ScriptTypeUnknown ShellType = "" ScriptLocationInline ScriptLocation = "inline" ScriptLocationPath ScriptLocation = "path" ScriptLocationUnknown ScriptLocation = "" // Executes pre hooks HookTypePre HookType = "pre" // Execute post hooks HookTypePost HookType = "post" HookTypeNone HookType = "" HookPlatformWindows HookPlatformType = "windows" HookPlatformPosix HookPlatformType = "posix" )
Variables ¶
var ( ErrScriptTypeUnknown error = errors.New( "unable to determine script type. Ensure 'Shell' parameter is set in configuration options", ) ErrRunRequired error = errors.New("run is always required") ErrUnsupportedScriptType error = errors.New("script type is not valid. Only '.sh' and '.ps1' are supported") )
var (
ErrInvalidEvent = errors.New("invalid event name for the current type")
)
Functions ¶
This section is empty.
Types ¶
type EventDispatcher ¶
type EventDispatcher[T any] struct { // contains filtered or unexported fields }
func NewEventDispatcher ¶
func NewEventDispatcher[T any](validEventNames ...Event) *EventDispatcher[T]
func (*EventDispatcher[T]) AddHandler ¶
func (ed *EventDispatcher[T]) AddHandler(ctx context.Context, name Event, handler EventHandlerFn[T]) error
Adds an event handler for the specified event name
func (*EventDispatcher[T]) Invoke ¶
func (ed *EventDispatcher[T]) Invoke(ctx context.Context, name Event, eventArgs T, action InvokeFn) error
Invokes an action and raises an event before and after the action
func (*EventDispatcher[T]) RaiseEvent ¶
func (ed *EventDispatcher[T]) RaiseEvent(ctx context.Context, name Event, eventArgs T) error
Raises the specified event and calls any registered event handlers
func (*EventDispatcher[T]) RemoveHandler ¶
func (ed *EventDispatcher[T]) RemoveHandler(ctx context.Context, name Event, handler EventHandlerFn[T]) error
Removes the event handler for the specified event name
type HookConfig ¶
type HookConfig struct {
// Internal name of the hook running for a given command
Name string `yaml:",omitempty"`
// The type of script hook (bash or powershell)
Shell ShellType `yaml:"shell,omitempty"`
// The inline script to execute or path to existing file
Run string `yaml:"run,omitempty"`
// When set to true will not halt command execution even when a script error occurs.
ContinueOnError bool `yaml:"continueOnError,omitempty"`
// When set to true will bind the stdin, stdout & stderr to the running console
Interactive bool `yaml:"interactive,omitempty"`
// When running on windows use this override config
Windows *HookConfig `yaml:"windows,omitempty"`
// When running on linux/macos use this override config
Posix *HookConfig `yaml:"posix,omitempty"`
// Environment variables in this list are added to the hook script and if the value is a akvs:// reference
// it will be resolved to the secret value
Secrets map[string]string `yaml:"secrets,omitempty"`
// contains filtered or unexported fields
}
Azd hook configuration
func (*HookConfig) IsPowerShellHook ¶
func (hc *HookConfig) IsPowerShellHook() bool
IsPowerShellHook determines if a hook configuration uses PowerShell
func (*HookConfig) IsUsingDefaultShell ¶
func (hc *HookConfig) IsUsingDefaultShell() bool
IsUsingDefaultShell returns true if the hook is using the OS default shell because no shell was explicitly configured
type HookFilterPredicateFn ¶
type HookFilterPredicateFn func(scriptName string, hookConfig *HookConfig) bool
type HookPlatformType ¶
type HookPlatformType string
type HookType ¶
type HookType string
The type of hooks. Supported values are 'pre' and 'post'
func InferHookType ¶
type HookValidationResult ¶
type HookValidationResult struct {
Warnings []HookWarning
}
HookValidationResult contains warnings found during hook validation
type HookWarning ¶
HookWarning represents a validation warning for hooks
type HooksConfig ¶ added in v1.23.14
type HooksConfig map[string][]*HookConfig
HooksConfig is an alias for map of hook names to slices of hook configurations. It supports unmarshalling both legacy single-hook and newer multi-hook formats.
func (HooksConfig) MarshalYAML ¶ added in v1.23.14
func (ch HooksConfig) MarshalYAML() (any, error)
MarshalYAML marshals hook configuration to YAML, supporting both single-hook configuration and multiple-hooks configuration.
func (*HooksConfig) UnmarshalYAML ¶ added in v1.23.14
func (ch *HooksConfig) UnmarshalYAML(unmarshal func(any) error) error
UnmarshalYAML converts hook configuration from YAML, supporting both single-hook configuration and multiple-hooks configuration.
type HooksManager ¶
type HooksManager struct {
// contains filtered or unexported fields
}
Hooks enable support to invoke integration scripts before & after commands Scripts can be invoked at the project or service level or
func NewHooksManager ¶
func NewHooksManager( cwd string, commandRunner exec.CommandRunner, ) *HooksManager
NewHooks creates a new instance of CommandHooks When `cwd` is empty defaults to current shell working directory
func (*HooksManager) GetAll ¶
func (h *HooksManager) GetAll(hooks map[string][]*HookConfig) ([]*HookConfig, error)
Gets an array of all hook configurations Will return an error if any configuration errors are found
func (*HooksManager) GetByParams ¶
func (h *HooksManager) GetByParams( hooks map[string][]*HookConfig, prefix HookType, commands ...string, ) ([]*HookConfig, error)
Gets an array of hook configurations matching the specified hook type and commands Will return an error if any configuration errors are found
func (*HooksManager) ValidateHooks ¶
func (h *HooksManager) ValidateHooks(ctx context.Context, allHooks map[string][]*HookConfig) *HookValidationResult
ValidateHooks validates hook configurations and returns any warnings
type HooksRunner ¶
type HooksRunner struct {
// contains filtered or unexported fields
}
Hooks enable support to invoke integration scripts before & after commands Scripts can be invoked at the project or service level or
func NewHooksRunner ¶
func NewHooksRunner( hooksManager *HooksManager, commandRunner exec.CommandRunner, envManager environment.Manager, console input.Console, cwd string, hooks map[string][]*HookConfig, env *environment.Environment, serviceLocator ioc.ServiceLocator, ) *HooksRunner
NewHooks creates a new instance of CommandHooks When `cwd` is empty defaults to current shell working directory
func (*HooksRunner) GetScript ¶
func (h *HooksRunner) GetScript(hookConfig *HookConfig, envVars []string) (tools.Script, error)
Gets the script to execute based on the hook configuration values For inline scripts this will also create a temporary script file to execute
func (*HooksRunner) Invoke ¶
Invokes an action run runs any registered pre or post script hooks for the specified command.
func (*HooksRunner) RunHooks ¶
func (h *HooksRunner) RunHooks( ctx context.Context, hookType HookType, options *tools.ExecOptions, commands ...string, ) error
Invokes any registered script hooks for the specified hook type and command.
type ScriptLocation ¶
type ScriptLocation string