Documentation
¶
Overview ¶
Package executor provides a unified interface for executing plugins regardless of their underlying protocol (go-plugin RPC or JSON-stdio).
Index ¶
- type MockProcessRunner
- func NewDelayMockProcessRunner(delay time.Duration) *MockProcessRunner
- func NewErrorMockProcessRunner(errMsg string) *MockProcessRunner
- func NewMockProcessRunner() *MockProcessRunner
- func NewSuccessMockProcessRunner(stdout []byte) *MockProcessRunner
- func NewTimeoutMockProcessRunner() *MockProcessRunner
- type PluginExecutor
- func (e *PluginExecutor) Close()
- func (e *PluginExecutor) ExecuteInput(ctx context.Context, opts plugin.InputOptions) ([]color.Color, error)
- func (e *PluginExecutor) ExecuteOutput(ctx context.Context, palette plugin.PaletteData) (map[string][]byte, error)
- func (e *PluginExecutor) GetFlagHelp(ctx context.Context) ([]input.FlagHelp, error)
- func (e *PluginExecutor) GetWallpaperPath() string
- func (e *PluginExecutor) GetWallpaperRawPath() string
- func (e *PluginExecutor) PostExecute(ctx context.Context, writtenFiles []string) error
- func (e *PluginExecutor) PreExecute(ctx context.Context) (skip bool, reason string, err error)
- type ProcessRunner
- type RealProcessRunner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MockProcessRunner ¶
type MockProcessRunner struct {
// RunFunc allows tests to provide custom behavior
RunFunc func(ctx context.Context, path string, args []string, stdin io.Reader) (stdout, stderr []byte, err error)
// Delay simulates slow process execution
Delay time.Duration
// ShouldTimeout if true, will block until context is cancelled
ShouldTimeout bool
// CallCount tracks how many times Run was called
CallCount int
// LastPath stores the last path passed to Run
LastPath string
// LastArgs stores the last args passed to Run
LastArgs []string
}
MockProcessRunner is a mock implementation of ProcessRunner for testing.
func NewDelayMockProcessRunner ¶
func NewDelayMockProcessRunner(delay time.Duration) *MockProcessRunner
NewDelayMockProcessRunner creates a mock that simulates a slow process.
func NewErrorMockProcessRunner ¶
func NewErrorMockProcessRunner(errMsg string) *MockProcessRunner
NewErrorMockProcessRunner creates a mock that returns an error.
func NewMockProcessRunner ¶
func NewMockProcessRunner() *MockProcessRunner
NewMockProcessRunner creates a new mock process runner.
func NewSuccessMockProcessRunner ¶
func NewSuccessMockProcessRunner(stdout []byte) *MockProcessRunner
NewSuccessMockProcessRunner creates a mock that returns successful JSON output.
func NewTimeoutMockProcessRunner ¶
func NewTimeoutMockProcessRunner() *MockProcessRunner
NewTimeoutMockProcessRunner creates a mock that simulates a timeout.
type PluginExecutor ¶
type PluginExecutor struct {
// contains filtered or unexported fields
}
PluginExecutor provides a unified interface for executing plugins.
func NewWithVerbose ¶
func NewWithVerbose(pluginPath string, verbose bool) (*PluginExecutor, error)
NewWithVerbose creates a new PluginExecutor with verbose logging control.
func NewWithVerboseAndRunner ¶
func NewWithVerboseAndRunner(pluginPath string, verbose bool, runner ProcessRunner) (*PluginExecutor, error)
NewWithVerboseAndRunner creates a new PluginExecutor with a custom process runner. This constructor is primarily used for testing with mock process runners.
func (*PluginExecutor) Close ¶
func (e *PluginExecutor) Close()
Close cleans up any resources held by the executor.
func (*PluginExecutor) ExecuteInput ¶
func (e *PluginExecutor) ExecuteInput(ctx context.Context, opts plugin.InputOptions) ([]color.Color, error)
ExecuteInput runs an input plugin and returns colors.
func (*PluginExecutor) ExecuteOutput ¶
func (e *PluginExecutor) ExecuteOutput(ctx context.Context, palette plugin.PaletteData) (map[string][]byte, error)
ExecuteOutput runs an output plugin and returns generated files.
func (*PluginExecutor) GetFlagHelp ¶
GetFlagHelp retrieves flag help information from a plugin. Works for both go-plugin RPC and JSON stdio protocols.
func (*PluginExecutor) GetWallpaperPath ¶
func (e *PluginExecutor) GetWallpaperPath() string
GetWallpaperPath retrieves the canonical wallpaper path from an input plugin if available. Works for both go-plugin RPC and JSON stdio protocols.
func (*PluginExecutor) GetWallpaperRawPath ¶ added in v0.1.22
func (e *PluginExecutor) GetWallpaperRawPath() string
GetWallpaperRawPath retrieves the raw wallpaper path from an input plugin if available. This is the literal path as provided by the user before any canonicalization. Works for both go-plugin RPC and JSON stdio protocols.
func (*PluginExecutor) PostExecute ¶
func (e *PluginExecutor) PostExecute(ctx context.Context, writtenFiles []string) error
PostExecute runs the output plugin's post-execution hook.
func (*PluginExecutor) PreExecute ¶
PreExecute runs the output plugin's pre-execution hook.
type ProcessRunner ¶
type ProcessRunner interface {
// Run executes a command with the given context, arguments, stdin, and returns stdout/stderr.
Run(ctx context.Context, path string, args []string, stdin io.Reader) (stdout, stderr []byte, err error)
}
ProcessRunner defines an interface for running external processes. This abstraction allows for dependency injection and easier testing.
type RealProcessRunner ¶
type RealProcessRunner struct{}
RealProcessRunner implements ProcessRunner using actual os/exec commands.
func NewRealProcessRunner ¶
func NewRealProcessRunner() *RealProcessRunner
NewRealProcessRunner creates a new real process runner.