command

package
v0.14.1-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoCommandForPath is returned when no command is found for a path.
	ErrNoCommandForPath = errors.New("no command for path")

	// ErrCommandExecution is returned when command execution fails.
	ErrCommandExecution = errors.New("command execution")

	// ErrEmptyCommand is returned when a command is empty.
	ErrEmptyCommand = errors.New("empty command")

	// ErrHookExecution is returned when hook execution fails.
	ErrHookExecution = errors.New("hook execution")
)
View Source
var (
	DefaultConfig = MustNewConfig(defaultProfiles, defaultRules)
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Profiles map[string]*profile.Profile `validate:"dive" yaml:"profiles,omitempty"`
	Rules    []*rule.Rule                `validate:"dive" yaml:"rules,omitempty"`
}

func MustNewConfig

func MustNewConfig(ps map[string]*profile.Profile, rs []*rule.Rule) *Config

func NewConfig

func NewConfig(ps map[string]*profile.Profile, rs []*rule.Rule) (*Config, error)

func (*Config) EnsureDefaults

func (c *Config) EnsureDefaults()

func (*Config) Validate

func (c *Config) Validate() *ConfigError

type ConfigError

type ConfigError struct {
	Path *yaml.Path // YAML path to the error.
	Err  error
}

func (ConfigError) Error

func (e ConfigError) Error() string

type Event

type Event any

Event represents an event related to command execution.

type EventCancel

type EventCancel struct{}

EventCancel indicates that a command execution has been canceled.

type EventEnd

type EventEnd Output

EventEnd indicates that a command execution has ended. This event carries the output of the command execution, which could be an error if the command failed.

type EventStart

type EventStart Type

EventStart indicates that a command execution has started.

type Output

type Output struct {
	Error     error
	Stdout    string
	Stderr    string
	Resources []*kube.Resource
	Type      Type
}

type Runner

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

Runner wraps one or more Rule objects. It manages:

  • File-to-command mappings.
  • Filesystem notifications / watching.
  • Concurrent command execution.

func NewRunner

func NewRunner(path string, opts ...RunnerOpt) (*Runner, error)

NewRunner creates a new Runner.

func (*Runner) Close

func (cr *Runner) Close()

func (*Runner) GetCurrentProfile

func (cr *Runner) GetCurrentProfile() *profile.Profile

func (*Runner) Run

func (cr *Runner) Run() Output

RunFirstMatch executes the first matching command for the given path. If path is a file, it checks for direct matches. If path is a directory, it checks all files in the directory for matches.

func (*Runner) RunContext

func (cr *Runner) RunContext(ctx context.Context) Output

RunContext executes the first matching command for the given path with the provided context. If path is a file, it checks for direct matches. If path is a directory, it checks all files in the directory for matches. The context can be used for cancellation, timeouts, and tracing.

func (*Runner) RunOnEvent

func (cr *Runner) RunOnEvent()

RunOnEvent listens for file system events and runs the command in response. The output should be collected via Runner.Subscribe.

func (*Runner) RunPlugin

func (cr *Runner) RunPlugin(name string) Output

RunPlugin executes a plugin by name.

func (*Runner) RunPluginContext

func (cr *Runner) RunPluginContext(ctx context.Context, name string) Output

RunPluginContext executes a plugin by name with the provided context.

func (*Runner) String

func (cr *Runner) String() string

func (*Runner) Subscribe

func (cr *Runner) Subscribe(ch chan<- Event)

Subscribe allows other components to listen for command events.

func (*Runner) Watch

func (cr *Runner) Watch() error

type RunnerOpt

type RunnerOpt func(cr *Runner) error

func WithProfile

func WithProfile(name string, p *profile.Profile) RunnerOpt

WithProfile sets a specific profile to use.

func WithRules

func WithRules(rs []*rule.Rule) RunnerOpt

WithRules sets multiple rules from which the first matching rule will be used.

type Static

type Static struct {
	Resources []*kube.Resource
	// contains filtered or unexported fields
}

func NewStatic

func NewStatic(input string) (*Static, error)

func (*Static) Close

func (rg *Static) Close()

func (*Static) GetCurrentProfile

func (rg *Static) GetCurrentProfile() *profile.Profile

func (*Static) Run

func (rg *Static) Run() Output

func (*Static) RunOnEvent

func (rg *Static) RunOnEvent()

func (*Static) RunPlugin

func (rg *Static) RunPlugin(_ string) Output

func (*Static) String

func (rg *Static) String() string

func (*Static) Subscribe

func (rg *Static) Subscribe(ch chan<- Event)

type Type

type Type int
const (
	// TypeRun indicates a command execution.
	TypeRun Type = iota
	// TypePlugin indicates a plugin execution.
	TypePlugin
)

Jump to

Keyboard shortcuts

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