action

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2025 License: Apache-2.0 Imports: 32 Imported by: 12

Documentation

Overview

Package action provides implementations of discovering and running actions.

Index

Constants

View Source
const ConfigImagesKey = "images"

ConfigImagesKey is a field name in launchr.Config file.

Variables

This section is empty.

Functions

func CastSliceAnyToTyped added in v0.17.1

func CastSliceAnyToTyped[T any](orig []any) []T

CastSliceAnyToTyped converts []any slice to a typed slice.

func CastSliceTypedToAny added in v0.17.1

func CastSliceTypedToAny(slice any) []any

CastSliceTypedToAny converts an unknown slice to []any slice.

func ConvertInputToTplVars added in v0.1.2

func ConvertInputToTplVars(input *Input, ac *DefAction) map[string]any

ConvertInputToTplVars creates a map with input variables suitable for template engine.

func InputArgSlice added in v0.17.1

func InputArgSlice[T any](input *Input, name string) []T

InputArgSlice is a helper function to get an argument of specific type slice.

func InputOptSlice added in v0.17.1

func InputOptSlice[T any](input *Input, name string) []T

InputOptSlice is a helper function to get an option of specific type slice.

func WithDefaultRuntime added in v0.17.1

func WithDefaultRuntime(m Manager, a *Action)

WithDefaultRuntime adds a default Runtime for an action.

Types

type Action

type Action struct {
	ID string // ID is a unique action id provided by [IDProvider].
	// contains filtered or unexported fields
}

Action is an action definition with a contextual id (name), working directory path and a runtime context such as input arguments and options.

func New added in v0.17.1

func New(idp IDProvider, l Loader, fsdir string, fpath string) *Action

New creates a new action.

func NewFromYAML added in v0.17.1

func NewFromYAML(id string, b []byte) *Action

NewFromYAML creates a new action from yaml content.

func (*Action) ActionDef added in v0.1.2

func (a *Action) ActionDef() *DefAction

ActionDef returns action definition.

func (*Action) Clone added in v0.1.2

func (a *Action) Clone() *Action

Clone returns a copy of an action.

func (*Action) DefinitionEncoded added in v0.1.2

func (a *Action) DefinitionEncoded() ([]byte, error)

DefinitionEncoded returns encoded action file content.

func (*Action) Dir added in v0.1.2

func (a *Action) Dir() string

Dir returns an action file directory.

func (*Action) EnsureLoaded added in v0.1.2

func (a *Action) EnsureLoaded() (err error)

EnsureLoaded loads an action file with replaced arguments and options.

func (*Action) Execute added in v0.1.2

func (a *Action) Execute(ctx context.Context) error

Execute runs action in the specified environment.

func (*Action) Filepath added in v0.1.2

func (a *Action) Filepath() string

Filepath returns action file path.

func (*Action) GetProcessors added in v0.7.0

func (a *Action) GetProcessors() map[string]ValueProcessor

GetProcessors returns processors map.

func (*Action) ImageBuildInfo added in v0.1.2

func (a *Action) ImageBuildInfo(image string) *types.BuildDefinition

ImageBuildInfo implements ImageBuildResolver.

func (*Action) Input added in v0.17.1

func (a *Action) Input() *Input

Input returns action input.

func (*Action) JSONSchema added in v0.1.2

func (a *Action) JSONSchema() jsonschema.Schema

JSONSchema returns json schema of an action.

func (*Action) Raw added in v0.14.0

func (a *Action) Raw() (*Definition, error)

Raw returns unprocessed action definition. It is faster and may produce fewer errors. It may be helpful if needed to peek inside the action file to read header.

func (*Action) Reset added in v0.1.2

func (a *Action) Reset()

Reset unsets loaded action to force reload.

func (*Action) Runtime added in v0.17.1

func (a *Action) Runtime() Runtime

Runtime returns environment to run the action.

func (*Action) RuntimeDef added in v0.17.1

func (a *Action) RuntimeDef() *DefRuntime

RuntimeDef returns runtime definition with replaced variables.

func (*Action) SetInput added in v0.1.2

func (a *Action) SetInput(input *Input) (err error)

SetInput saves arguments and options for later processing in run, templates, etc.

func (*Action) SetProcessors added in v0.7.0

func (a *Action) SetProcessors(list map[string]ValueProcessor) error

SetProcessors sets the value processors for an Action.

func (*Action) SetRuntime added in v0.17.1

func (a *Action) SetRuntime(r Runtime)

SetRuntime sets environment to run the action.

func (*Action) SetWorkDir added in v0.17.1

func (a *Action) SetWorkDir(wd string)

SetWorkDir sets action working directory.

func (*Action) ValidateInput added in v0.1.2

func (a *Action) ValidateInput(input *Input) error

ValidateInput validates action input.

func (*Action) WorkDir added in v0.5.5

func (a *Action) WorkDir() string

WorkDir returns action working directory.

type AlterActionsPlugin added in v0.14.0

type AlterActionsPlugin interface {
	launchr.Plugin
	AlterActions() error
}

AlterActionsPlugin is a launchr plugin to alter registered actions.

type ChainImageBuildResolver added in v0.1.2

type ChainImageBuildResolver []ImageBuildResolver

ChainImageBuildResolver is a image build resolver that takes first available image in the chain.

func (ChainImageBuildResolver) ImageBuildInfo added in v0.1.2

func (r ChainImageBuildResolver) ImageBuildInfo(image string) *types.BuildDefinition

ImageBuildInfo implements ImageBuildResolver.

type ConfigImages added in v0.1.0

type ConfigImages map[string]*types.BuildDefinition

ConfigImages is a container to parse launchr.Config in yaml format.

type ContainerNameProvider added in v0.3.0

type ContainerNameProvider struct {
	Prefix       string
	RandomSuffix bool
}

ContainerNameProvider provides an ability to generate a random container name

func (ContainerNameProvider) Get added in v0.3.0

func (p ContainerNameProvider) Get(name string) string

Get generates a new container name

type ContainerRuntime added in v0.17.1

type ContainerRuntime interface {
	Runtime
	// SetContainerNameProvider sets container name provider.
	SetContainerNameProvider(ContainerNameProvider)
	// AddImageBuildResolver adds an image build resolver to a chain.
	AddImageBuildResolver(ImageBuildResolver)
	// SetImageBuildCacheResolver sets an image build cache resolver
	// to check when image must be rebuilt.
	SetImageBuildCacheResolver(*ImageBuildCacheResolver)
}

ContainerRuntime is an interface for container runtime.

func NewContainerRuntime added in v0.17.1

func NewContainerRuntime(t driver.Type) ContainerRuntime

NewContainerRuntime creates a new action container runtime.

func NewContainerRuntimeDocker added in v0.17.1

func NewContainerRuntimeDocker() ContainerRuntime

NewContainerRuntimeDocker creates a new action Docker runtime.

type DecorateWithFn added in v0.1.2

type DecorateWithFn = func(m Manager, a *Action)

DecorateWithFn is a type alias for functions accepted in a [Manager.Decorate] interface method.

func WithContainerRuntimeConfig added in v0.17.1

func WithContainerRuntimeConfig(cfg launchr.Config, prefix string) DecorateWithFn

WithContainerRuntimeConfig configures a ContainerRuntime.

type DefAction added in v0.1.2

type DefAction struct {
	Title       string         `yaml:"title"`
	Description string         `yaml:"description"`
	Aliases     []string       `yaml:"alias"`
	Arguments   ParametersList `yaml:"arguments"`
	Options     ParametersList `yaml:"options"`

	// @todo remove deprecated
	Command    StrSliceOrStr          `yaml:"command"`     // Deprecated: use [Definition.Runtime]
	Image      string                 `yaml:"image"`       // Deprecated: use [Definition.Runtime]
	Build      *types.BuildDefinition `yaml:"build"`       // Deprecated: use [Definition.Runtime]
	ExtraHosts StrSlice               `yaml:"extra_hosts"` // Deprecated: use [Definition.Runtime]
	Env        EnvSlice               `yaml:"env"`         // Deprecated: use [Definition.Runtime]
	User       string                 `yaml:"user"`        // Deprecated: use [Definition.Runtime]
}

DefAction holds action configuration.

func (*DefAction) JSONSchema added in v0.1.2

func (a *DefAction) JSONSchema() jsonschema.Schema

JSONSchema returns jsonschema.Schema for the arguments and options of the action.

func (*DefAction) UnmarshalYAML added in v0.1.2

func (a *DefAction) UnmarshalYAML(n *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse action definition.

type DefArrayItems added in v0.17.1

type DefArrayItems struct {
	Type jsonschema.Type `yaml:"type"`
}

DefArrayItems stores array type related information.

type DefParameter added in v0.17.1

type DefParameter struct {
	Title       string          `yaml:"title"`
	Description string          `yaml:"description"`
	Type        jsonschema.Type `yaml:"type"`
	Default     any             `yaml:"default"`
	Enum        []any           `yaml:"enum"`
	Items       *DefArrayItems  `yaml:"items"`

	// Action specific behavior for parameters.
	// Name is an action unique parameter name used.
	Name string `yaml:"name"`
	// Shorthand is a short name 1 syllable name used in Console.
	// @todo test definition, validate, catch panic if overlay, add to readme.
	Shorthand string `yaml:"shorthand"`
	// Required indicates if the parameter is mandatory.
	// It's not correct json schema, and it's processed to a correct place later.
	Required bool `yaml:"required"`
	// Process is an array of [ValueProcessor] to a value.
	Process []DefValueProcessor `yaml:"process"`
	// contains filtered or unexported fields
}

DefParameter stores command argument or option declaration.

func (*DefParameter) InitProcessors added in v0.17.2

func (p *DefParameter) InitProcessors(list map[string]ValueProcessor) error

InitProcessors creates ValueProcessor handlers according to the definition.

func (*DefParameter) JSONSchema added in v0.17.1

func (p *DefParameter) JSONSchema() map[string]any

JSONSchema returns json schema definition of an option.

func (*DefParameter) UnmarshalYAML added in v0.17.1

func (p *DefParameter) UnmarshalYAML(n *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse DefParameter.

type DefRuntime added in v0.17.1

type DefRuntime struct {
	Type      DefRuntimeType `yaml:"type"`
	Container *DefRuntimeContainer
}

DefRuntime contains action runtime configuration.

func (*DefRuntime) UnmarshalYAML added in v0.17.1

func (r *DefRuntime) UnmarshalYAML(n *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse runtime definition.

type DefRuntimeContainer added in v0.17.1

type DefRuntimeContainer struct {
	Command    StrSliceOrStr          `yaml:"command"`
	Image      string                 `yaml:"image"`
	Build      *types.BuildDefinition `yaml:"build"`
	ExtraHosts StrSlice               `yaml:"extra_hosts"`
	Env        EnvSlice               `yaml:"env"`
	User       string                 `yaml:"user"`
}

DefRuntimeContainer has container-specific runtime configuration.

func (*DefRuntimeContainer) UnmarshalYAML added in v0.17.1

func (r *DefRuntimeContainer) UnmarshalYAML(n *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse runtime container definition.

type DefRuntimeType added in v0.17.1

type DefRuntimeType string

DefRuntimeType is a runtime type.

func (*DefRuntimeType) UnmarshalYAML added in v0.17.1

func (r *DefRuntimeType) UnmarshalYAML(n *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse runtime type.

type DefValueProcessor added in v0.17.1

type DefValueProcessor struct {
	ID string `yaml:"processor"`
	// contains filtered or unexported fields
}

DefValueProcessor stores information about processor and options that should be applied to processor.

func (*DefValueProcessor) UnmarshalYAML added in v0.17.1

func (p *DefValueProcessor) UnmarshalYAML(n *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse DefValueProcessor.

type DefaultIDProvider added in v0.14.0

type DefaultIDProvider struct{}

DefaultIDProvider is a default action id provider. It generates action id by a filepath.

func (DefaultIDProvider) GetID added in v0.14.0

func (idp DefaultIDProvider) GetID(a *Action) string

GetID implements IDProvider interface. It parses action filename and returns CLI command name. Empty string if the command name can't be generated.

type Definition added in v0.1.2

type Definition struct {
	Version string      `yaml:"version"`
	WD      string      `yaml:"working_directory"`
	Action  *DefAction  `yaml:"action"`
	Runtime *DefRuntime `yaml:"runtime"`
}

Definition is a representation of an action file.

func NewDefFromYaml added in v0.17.1

func NewDefFromYaml(b []byte) (*Definition, error)

NewDefFromYaml creates an action file definition from yaml configuration. It returns pointer to Definition or nil on error.

func NewDefFromYamlTpl added in v0.17.1

func NewDefFromYamlTpl(b []byte) (*Definition, error)

NewDefFromYamlTpl creates an action file definition from yaml configuration as NewDefFromYaml but considers that it has unescaped template values.

func (*Definition) Content added in v0.1.2

func (d *Definition) Content() ([]byte, error)

Content implements Loader interface.

func (*Definition) Load added in v0.1.2

func (d *Definition) Load(_ LoadContext) (*Definition, error)

Load implements Loader interface.

func (*Definition) LoadRaw added in v0.1.2

func (d *Definition) LoadRaw() (*Definition, error)

LoadRaw implements Loader interface.

func (*Definition) UnmarshalYAML added in v0.1.2

func (d *Definition) UnmarshalYAML(node *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse action definition.

type Discovery

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

Discovery defines a common functionality for discovering action files.

func NewDiscovery added in v0.5.4

func NewDiscovery(fs DiscoveryFS, ds DiscoveryStrategy) *Discovery

NewDiscovery creates an instance of action discovery.

func NewYamlDiscovery

func NewYamlDiscovery(fs DiscoveryFS) *Discovery

NewYamlDiscovery is an implementation of discovery for searching yaml files.

func (*Discovery) Discover

func (ad *Discovery) Discover(ctx context.Context) ([]*Action, error)

Discover traverses the file structure for a given discovery path. Returns array of Action. If an action is invalid, it's ignored.

func (*Discovery) SetActionIDProvider added in v0.14.0

func (ad *Discovery) SetActionIDProvider(idp IDProvider)

SetActionIDProvider sets discovery specific action id provider.

type DiscoveryFS added in v0.5.5

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

DiscoveryFS is a file system to discover actions.

func NewDiscoveryFS added in v0.5.5

func NewDiscoveryFS(fs fs.FS, wd string) DiscoveryFS

NewDiscoveryFS creates a DiscoveryFS given fs - a filesystem to discover and wd - working directory for an action, leave empty for current path.

func (DiscoveryFS) FS added in v0.5.5

func (f DiscoveryFS) FS() fs.FS

FS implements launchr.ManagedFS.

func (DiscoveryFS) Open added in v0.5.5

func (f DiscoveryFS) Open(name string) (fs.File, error)

Open implements fs.FS and decorates the launchr.ManagedFS.

func (DiscoveryFS) OpenCallback added in v0.17.1

func (f DiscoveryFS) OpenCallback(name string) FileLoadFn

OpenCallback returns callback to FileOpen a file.

type DiscoveryPlugin added in v0.5.4

type DiscoveryPlugin interface {
	launchr.Plugin
	DiscoverActions(ctx context.Context) ([]*Action, error)
}

DiscoveryPlugin is a launchr plugin to discover actions.

type DiscoveryStrategy added in v0.5.4

type DiscoveryStrategy interface {
	IsValid(name string) bool
	Loader(l FileLoadFn, p ...LoadProcessor) Loader
}

DiscoveryStrategy is a way files will be discovered and loaded.

type EnvSlice

type EnvSlice []string

EnvSlice is an array of runtime vars or key-value.

func (*EnvSlice) UnmarshalYAML

func (l *EnvSlice) UnmarshalYAML(n *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse runtime []string or map[string]string.

type FileLoadFn added in v0.5.4

type FileLoadFn func() (fs.File, error)

FileLoadFn is a type for loading a file.

type FnRuntime added in v0.17.1

type FnRuntime func(ctx context.Context, a *Action) error

FnRuntime is a function type implementing Runtime.

func (FnRuntime) Clone added in v0.17.1

func (fn FnRuntime) Clone() Runtime

Clone implements Runtime interface.

func (FnRuntime) Close added in v0.17.1

func (fn FnRuntime) Close() error

Close implements Runtime interface.

func (FnRuntime) Execute added in v0.17.1

func (fn FnRuntime) Execute(ctx context.Context, a *Action) error

Execute implements Runtime interface.

func (FnRuntime) Init added in v0.17.1

func (fn FnRuntime) Init(_ context.Context, _ *Action) error

Init implements Runtime interface.

type GenericValueProcessor added in v0.17.2

type GenericValueProcessor[T ValueProcessorOptions] struct {
	Types []jsonschema.Type
	Fn    GenericValueProcessorHandler[T]
}

GenericValueProcessor is a common ValueProcessor.

func (GenericValueProcessor[T]) Handler added in v0.17.2

Handler implements ValueProcessor interface.

func (GenericValueProcessor[T]) IsApplicable added in v0.17.2

func (p GenericValueProcessor[T]) IsApplicable(t jsonschema.Type) bool

IsApplicable implements ValueProcessor interface.

func (GenericValueProcessor[T]) OptionsType added in v0.17.2

func (p GenericValueProcessor[T]) OptionsType() ValueProcessorOptions

OptionsType implements ValueProcessor interface.

type GenericValueProcessorHandler added in v0.17.2

type GenericValueProcessorHandler[T ValueProcessorOptions] func(v any, opts T, ctx ValueProcessorContext) (any, error)

GenericValueProcessorHandler is an extension of ValueProcessorHandler to have typed ValueProcessorOptions.

type IDProvider added in v0.14.0

type IDProvider interface {
	GetID(a *Action) string
}

IDProvider provides an ID for an action. It is used to generate an ID from an action declaration. DefaultIDProvider is the default implementation based on action filepath.

type ImageBuildCacheResolver added in v0.6.0

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

ImageBuildCacheResolver is responsible for checking image build hash sums to rebuild images.

func NewImageBuildCacheResolver added in v0.6.0

func NewImageBuildCacheResolver(cfg launchr.Config) *ImageBuildCacheResolver

NewImageBuildCacheResolver creates ImageBuildCacheResolver from global configuration.

func (*ImageBuildCacheResolver) Destroy added in v0.6.0

func (r *ImageBuildCacheResolver) Destroy() error

Destroy removes the sum file from the persistent storage.

func (*ImageBuildCacheResolver) DirHash added in v0.6.0

func (r *ImageBuildCacheResolver) DirHash(path string) (string, error)

DirHash calculates the hash of a directory specified by the path parameter.

func (*ImageBuildCacheResolver) EnsureLoaded added in v0.6.0

func (r *ImageBuildCacheResolver) EnsureLoaded() (err error)

EnsureLoaded makes sure the sum file is loaded.

func (*ImageBuildCacheResolver) GetSum added in v0.6.0

func (r *ImageBuildCacheResolver) GetSum(tag string) string

GetSum returns a sum for an image tag.

func (*ImageBuildCacheResolver) Save added in v0.6.0

func (r *ImageBuildCacheResolver) Save() error

Save saves the sum file to the persistent storage.

func (*ImageBuildCacheResolver) SetSum added in v0.6.0

func (r *ImageBuildCacheResolver) SetSum(tag string, sum string)

SetSum adds sum for a tag. Provide empty sum to remove it.

type ImageBuildResolver added in v0.1.2

type ImageBuildResolver interface {
	// ImageBuildInfo takes image as name and provides build definition for that.
	ImageBuildInfo(image string) *types.BuildDefinition
}

ImageBuildResolver is an interface to resolve image build info from its source.

type Input added in v0.1.2

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

Input is a container for action input arguments and options.

func NewInput added in v0.17.1

func NewInput(a *Action, args InputParams, opts InputParams, io launchr.Streams) *Input

NewInput creates new input with named Arguments args and named Options opts. Options are filled with default values.

func (*Input) Arg added in v0.17.1

func (input *Input) Arg(name string) any

Arg returns argument by a name.

func (*Input) Args added in v0.1.2

func (input *Input) Args() InputParams

Args returns input named and processed arguments.

func (*Input) ArgsChanged added in v0.17.2

func (input *Input) ArgsChanged() InputParams

ArgsChanged returns arguments that were set manually by user (not processed).

func (*Input) ArgsPositional added in v0.17.1

func (input *Input) ArgsPositional() []string

ArgsPositional returns positional arguments set by user (not processed).

func (*Input) IsArgChanged added in v0.17.1

func (input *Input) IsArgChanged(name string) bool

IsArgChanged checks if an argument was changed by user.

func (*Input) IsOptChanged added in v0.17.1

func (input *Input) IsOptChanged(name string) bool

IsOptChanged checks if an option was changed by user.

func (*Input) IsValidated added in v0.17.1

func (input *Input) IsValidated() bool

IsValidated returns input status.

func (*Input) Opt added in v0.17.1

func (input *Input) Opt(name string) any

Opt returns option by a name.

func (*Input) Opts added in v0.1.2

func (input *Input) Opts() InputParams

Opts returns options with default values and processed.

func (*Input) OptsChanged added in v0.17.1

func (input *Input) OptsChanged() InputParams

OptsChanged returns options that were set manually by user (not processed).

func (*Input) SetArg added in v0.17.1

func (input *Input) SetArg(name string, val any)

SetArg sets an argument value.

func (*Input) SetOpt added in v0.17.1

func (input *Input) SetOpt(name string, val any)

SetOpt sets an option value.

func (*Input) SetValidated added in v0.17.1

func (input *Input) SetValidated(v bool)

SetValidated marks input as validated.

func (*Input) Streams added in v0.17.1

func (input *Input) Streams() launchr.Streams

Streams returns input io.

func (*Input) UnsetArg added in v0.17.1

func (input *Input) UnsetArg(name string)

UnsetArg unsets the arguments and recalculates default and positional values.

func (*Input) UnsetOpt added in v0.17.1

func (input *Input) UnsetOpt(name string)

UnsetOpt unsets the option and recalculates default values.

type InputParams added in v0.17.1

type InputParams = map[string]any

InputParams is a type alias for action arguments/options.

func ArgsPosToNamed added in v0.17.1

func ArgsPosToNamed(a *Action, args []string) (InputParams, error)

ArgsPosToNamed creates named arguments input.

type LaunchrConfigImageBuildResolver added in v0.1.2

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

LaunchrConfigImageBuildResolver is a resolver of image build in launchr.Config file.

func (LaunchrConfigImageBuildResolver) ImageBuildInfo added in v0.1.2

ImageBuildInfo implements ImageBuildResolver.

type LoadContext added in v0.2.1

type LoadContext struct {
	Action *Action
}

LoadContext stores relevant and isolated data needed for processors.

type LoadProcessor

type LoadProcessor interface {
	// Process gets an input action file data and returns a processed result.
	Process(LoadContext, []byte) ([]byte, error)
}

LoadProcessor is an interface for processing input on load.

func NewPipeProcessor

func NewPipeProcessor(p ...LoadProcessor) LoadProcessor

NewPipeProcessor creates a new processor containing several processors that handles input consequentially.

type Loader

type Loader interface {
	// Content returns the raw file content.
	Content() ([]byte, error)
	// Load parses Content to a Definition with substituted values.
	Load(LoadContext) (*Definition, error)
	// LoadRaw parses Content to a Definition raw values. Template strings are escaped.
	LoadRaw() (*Definition, error)
}

Loader is an interface for loading an action file.

type Manager added in v0.0.9

type Manager interface {
	launchr.Service
	// All returns all actions copied and decorated.
	All() map[string]*Action
	// Get returns a copy of an action from the manager with default decorators.
	Get(id string) (*Action, bool)
	// Add saves an action in the manager.
	Add(*Action) error
	// Delete deletes the action from the manager.
	Delete(id string)
	// Decorate decorates an action with given behaviors and returns its copy.
	// If functions withFn are not provided, default functions are applied.
	Decorate(a *Action, withFn ...DecorateWithFn) *Action
	// GetIDFromAlias returns a real action ID by its alias. If not, returns alias.
	GetIDFromAlias(alias string) string

	// GetActionIDProvider returns global application action id provider.
	GetActionIDProvider() IDProvider
	// SetActionIDProvider sets global application action id provider.
	// This id provider will be used as default on [Action] discovery process.
	SetActionIDProvider(p IDProvider)

	// AddValueProcessor adds processor to list of available processors
	AddValueProcessor(name string, vp ValueProcessor)
	// GetValueProcessors returns list of available processors
	GetValueProcessors() map[string]ValueProcessor

	// DefaultRuntime provides the default action runtime.
	DefaultRuntime() Runtime
	// Run executes an action in foreground.
	Run(ctx context.Context, a *Action) (RunInfo, error)
	// RunBackground executes an action in background.
	RunBackground(ctx context.Context, a *Action, runID string) (RunInfo, chan error)
	// RunInfoByAction returns all running actions by action id.
	RunInfoByAction(aid string) []RunInfo
	// RunInfoByID returns an action matching run id.
	RunInfoByID(id string) (RunInfo, bool)
}

Manager handles actions and its execution.

func NewManager added in v0.0.9

func NewManager(withFns ...DecorateWithFn) Manager

NewManager constructs a new action manager.

type ManagerUnsafe added in v0.14.0

type ManagerUnsafe interface {
	Manager
	// AllUnsafe returns all original action values from the storage.
	// Use this method only if you need read-only access to the actions without allocating new memory.
	// Warning: It is unsafe to manipulate these actions directly as they are the original instances
	// affecting the entire application.
	// Normally, for action execution you should use the [Manager.Get] or [Manager.All] methods,
	// which provide actions configured for execution.
	AllUnsafe() map[string]*Action
	// GetUnsafe returns the original action value from the storage.
	GetUnsafe(id string) (*Action, bool)
}

ManagerUnsafe is an extension of the Manager interface that provides unsafe access to actions. Warning: Use this with caution!

type ParametersList added in v0.17.1

type ParametersList []*DefParameter

ParametersList is used for custom yaml parsing of arguments list.

func (*ParametersList) JSONSchema added in v0.17.1

func (l *ParametersList) JSONSchema() (map[string]any, []string)

JSONSchema collects all arguments json schema definition and also returns fields that are required.

func (*ParametersList) UnmarshalYAML added in v0.17.1

func (l *ParametersList) UnmarshalYAML(nodeList *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse for ParametersList.

type RunInfo added in v0.1.2

type RunInfo struct {
	ID     string
	Action *Action
	Status string
}

RunInfo stores information about a running action.

type Runtime added in v0.17.1

type Runtime interface {
	// Init prepares the runtime.
	Init(ctx context.Context, a *Action) error
	// Execute runs action a in the environment and operates with io through streams.
	Execute(ctx context.Context, a *Action) error
	// Close does wrap up operations.
	Close() error
	// Clone creates the same runtime, but in initial state.
	Clone() Runtime
}

Runtime is an interface for action execution environment.

func NewFnRuntime added in v0.17.1

func NewFnRuntime(fn FnRuntime) Runtime

NewFnRuntime creates runtime as a go function.

type RuntimeFlags added in v0.17.1

type RuntimeFlags interface {
	Runtime
	// FlagsDefinition provides definitions for action environment specific flags.
	FlagsDefinition() ParametersList
	// UseFlags sets environment configuration.
	UseFlags(flags InputParams) error
	// ValidateInput validates input arguments in action definition.
	ValidateInput(a *Action, input *Input) error
}

RuntimeFlags is an interface to define environment specific runtime configuration.

type StrSlice

type StrSlice []string

StrSlice is an array of strings for command execution.

func (*StrSlice) UnmarshalYAML

func (l *StrSlice) UnmarshalYAML(n *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse a string or a list of strings.

type StrSliceOrStr added in v0.1.2

type StrSliceOrStr []string

StrSliceOrStr is an array of strings for command execution.

func (*StrSliceOrStr) UnmarshalYAML added in v0.1.2

func (l *StrSliceOrStr) UnmarshalYAML(n *yaml.Node) (err error)

UnmarshalYAML implements yaml.Unmarshaler to parse a string or a list of strings.

type StringID added in v0.17.1

type StringID string

StringID is an IDProvider with constant string id.

func (StringID) GetID added in v0.17.1

func (idp StringID) GetID(_ *Action) string

GetID implements IDProvider interface to return itself.

type TestCaseValueProcessor added in v0.17.2

type TestCaseValueProcessor struct {
	Name    string
	Yaml    string
	ErrInit error
	ErrProc error
	Args    InputParams
	Opts    InputParams
	ExpArgs InputParams
	ExpOpts InputParams
}

TestCaseValueProcessor is a common test case behavior for ValueProcessor.

func (TestCaseValueProcessor) Test added in v0.17.2

func (tt TestCaseValueProcessor) Test(t *testing.T, am Manager)

Test runs the test for ValueProcessor.

type ValueProcessor added in v0.7.0

type ValueProcessor interface {
	IsApplicable(valueType jsonschema.Type) bool
	OptionsType() ValueProcessorOptions
	Handler(opts ValueProcessorOptions) ValueProcessorHandler
}

ValueProcessor defines an interface for processing a value based on its type and some options.

type ValueProcessorContext added in v0.17.2

type ValueProcessorContext struct {
	ValOrig   any                   // ValOrig is the value before processing.
	IsChanged bool                  // IsChanged indicates if the value was input by user.
	Options   ValueProcessorOptions // Options is the [ValueProcessor] configuration.
	DefParam  *DefParameter         // DefParam is the definition of the currently processed parameter.
	Action    *Action               // Action is the related action definition.
}

ValueProcessorContext is related context data for ValueProcessor.

type ValueProcessorHandler added in v0.17.2

type ValueProcessorHandler func(v any, ctx ValueProcessorContext) (any, error)

ValueProcessorHandler is an actual implementation of ValueProcessor that processes the incoming value.

type ValueProcessorOptions added in v0.17.2

type ValueProcessorOptions interface {
	Validate() error
}

ValueProcessorOptions is a common type for value processor options

type ValueProcessorOptionsEmpty added in v0.17.2

type ValueProcessorOptionsEmpty struct{}

ValueProcessorOptionsEmpty when ValueProcessor doesn't have options.

func (*ValueProcessorOptionsEmpty) Validate added in v0.17.2

func (o *ValueProcessorOptionsEmpty) Validate() error

Validate implements ValueProcessorOptions interface.

type YamlDiscoveryStrategy added in v0.5.4

type YamlDiscoveryStrategy struct {
	TargetRgx *regexp.Regexp
}

YamlDiscoveryStrategy is a yaml discovery strategy.

func (YamlDiscoveryStrategy) IsValid added in v0.5.4

func (y YamlDiscoveryStrategy) IsValid(name string) bool

IsValid implements DiscoveryStrategy.

func (YamlDiscoveryStrategy) Loader added in v0.5.4

Loader implements DiscoveryStrategy.

type YamlFileLoader added in v0.17.1

type YamlFileLoader struct {
	YamlLoader
	FileOpen FileLoadFn // FileOpen lazy loads the content of the file.
}

YamlFileLoader loads action yaml from a file.

func (*YamlFileLoader) Content added in v0.17.1

func (l *YamlFileLoader) Content() ([]byte, error)

Content implements Loader interface.

func (*YamlFileLoader) Load added in v0.17.1

func (l *YamlFileLoader) Load(ctx LoadContext) (res *Definition, err error)

Load implements Loader interface.

func (*YamlFileLoader) LoadRaw added in v0.17.1

func (l *YamlFileLoader) LoadRaw() (*Definition, error)

LoadRaw implements Loader interface.

type YamlLoader added in v0.17.1

type YamlLoader struct {
	Bytes     []byte        // Bytes represents yaml content bytes.
	Processor LoadProcessor // Processor processes variables inside the file.
	// contains filtered or unexported fields
}

YamlLoader loads action yaml from a string.

func (*YamlLoader) Content added in v0.17.1

func (l *YamlLoader) Content() ([]byte, error)

Content implements Loader interface.

func (*YamlLoader) Load added in v0.17.1

func (l *YamlLoader) Load(ctx LoadContext) (res *Definition, err error)

Load implements Loader interface.

func (*YamlLoader) LoadRaw added in v0.17.1

func (l *YamlLoader) LoadRaw() (*Definition, error)

LoadRaw implements Loader interface.

Jump to

Keyboard shortcuts

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