executor

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package executor is the core execution engine responsible for resolving variable dependencies, substituting values securely into shell commands, and dispatching those commands to the local shell environment or clipboard.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectDependencies

func CollectDependencies(cheat *parser.Cheat, index *parser.CheatIndex) ([]string, map[string][]parser.VarDef)

CollectDependencies gathers all variable definitions and their topological ordering.

func CollectVarDefinitions

func CollectVarDefinitions(cheat *parser.Cheat, index *parser.CheatIndex) map[string][]parser.VarDef

CollectVarDefinitions gathers all var definitions from imports and local cheat.

func EvaluateCondition

func EvaluateCondition(condition string, scope map[string]string) bool

EvaluateCondition evaluates a condition expression against the scope.

func FindAllDependencies

func FindAllDependencies(usedVars []string, varDefs map[string][]parser.VarDef) map[string]bool

FindAllDependencies finds transitive closure of all needed variables.

func FindAllVars

func FindAllVars(cmd string, syntax string) []string

FindAllVars finds ALL variable references in a command, ignoring quoting.

func ReplaceVar

func ReplaceVar(cmd, varName, replacement string, syntax string) string

ReplaceVar replaces variable references in cmd with replacement.

func SubstituteVars

func SubstituteVars(s string, scope map[string]string, syntax string) string

SubstituteVars replaces variables in a string using the given scope. The syntax parameter controls which variable forms are replaced:

  • "dollar": replaces $name
  • "angle": replaces <name>
  • "both": replaces both $name and <name>

func TopologicalSort

func TopologicalSort(usedVars []string, varDefs map[string][]parser.VarDef, allNeeded map[string]bool) []string

TopologicalSort orders variables by their dependencies.

Types

type Clipboard

type Clipboard interface {
	Copy(text string) error
}

Clipboard defines the interface for clipboard operations

type Executor

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

Executor handles shell command execution and variable substitution

func NewExecutor

func NewExecutor(index *parser.CheatIndex) *Executor

NewExecutor creates a new executor with the given cheat index

func (*Executor) BuildFinalCommand

func (e *Executor) BuildFinalCommand(cheat *parser.Cheat) string

BuildFinalCommand substitutes all variables in a cheat's command

func (*Executor) Execute

func (e *Executor) Execute(command string) error

Execute runs a command interactively with inherited stdin/stdout/stderr

func (*Executor) Index

func (e *Executor) Index() *parser.CheatIndex

Index returns the cheat index

func (*Executor) Output

func (e *Executor) Output(command string) error

Output handles command output based on the configured mode

func (*Executor) OutputWithMode

func (e *Executor) OutputWithMode(command string, mode OutputMode) error

OutputWithMode handles command output with an explicit mode

func (*Executor) RunShell

func (e *Executor) RunShell(command string) (string, error)

RunShell executes a shell command and returns stdout

func (*Executor) Shell

func (e *Executor) Shell() string

Shell returns the configured shell

func (*Executor) WithClipboard

func (e *Executor) WithClipboard(c Clipboard) *Executor

WithClipboard sets a custom clipboard implementation (useful for testing)

type OutputMode

type OutputMode string

OutputMode represents how the final command should be handled

const (
	OutputPrint OutputMode = "print"
	OutputCopy  OutputMode = "copy"
	OutputExec  OutputMode = "exec"
)

type ShellRunner

type ShellRunner interface {
	RunShell(command string) (string, error)
	Execute(command string) error
}

ShellRunner defines the interface for shell command execution

Jump to

Keyboard shortcuts

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