Documentation
¶
Overview ¶
Package task implements a task runner for omni-only commands. It parses Taskfile.yml format and executes only omni internal commands.
Index ¶
- Variables
- func EvaluateDynamicVar(v any) (string, error)
- func MergeVars(maps ...map[string]any) map[string]any
- func Run(ctx context.Context, w io.Writer, taskNames []string, opts Options) error
- type CobraCommandRunner
- type Command
- type CommandRunner
- type DefaultCommandRunner
- type Dependency
- type DependencyResolver
- type Executor
- type HybridCommandRunner
- type MockCommandRunner
- type Options
- type Precondition
- type ShellCommandRunner
- type Task
- type Taskfile
- type VarResolver
Constants ¶
This section is empty.
Variables ¶
var CommandRunnerFactory func(dir string, allowExternal bool) CommandRunner
CommandRunnerFactory is a function that creates a command runner This allows the cmd package to inject the Cobra command runner The dir parameter is the working directory for external commands
var DefaultTaskfiles = []string{
"Taskfile.yml",
"Taskfile.yaml",
"taskfile.yml",
"taskfile.yaml",
}
DefaultTaskfiles lists the default taskfile names to search for
Functions ¶
func EvaluateDynamicVar ¶
EvaluateDynamicVar evaluates a dynamic variable (sh command result) For omni, we only support static values, not shell execution
Types ¶
type CobraCommandRunner ¶
type CobraCommandRunner struct {
// contains filtered or unexported fields
}
CobraCommandRunner runs commands using a Cobra root command
func NewCobraCommandRunner ¶
func NewCobraCommandRunner(rootCmd *cobra.Command) *CobraCommandRunner
NewCobraCommandRunner creates a command runner from a Cobra root command
type Command ¶
type Command struct {
Cmd string `yaml:"cmd"`
Task string `yaml:"task"` // Reference to another task
Silent bool `yaml:"silent"`
IgnoreError bool `yaml:"ignore_error"`
Defer bool `yaml:"defer"`
}
Command represents a command to execute
type CommandRunner ¶
CommandRunner is the interface for running omni commands
type DefaultCommandRunner ¶
type DefaultCommandRunner struct{}
DefaultCommandRunner runs omni commands via the command registry
type Dependency ¶
Dependency represents a task dependency
func (*Dependency) UnmarshalYAML ¶
func (d *Dependency) UnmarshalYAML(node *yaml.Node) error
UnmarshalYAML implements custom unmarshaling for Dependency
type DependencyResolver ¶
type DependencyResolver struct {
// contains filtered or unexported fields
}
DependencyResolver handles task dependency resolution
func NewDependencyResolver ¶
func NewDependencyResolver(tf *Taskfile) *DependencyResolver
NewDependencyResolver creates a new dependency resolver
func (*DependencyResolver) GetDirectDeps ¶
func (r *DependencyResolver) GetDirectDeps(taskName string) ([]Dependency, error)
GetDirectDeps returns direct dependencies of a task
func (*DependencyResolver) ResolveDeps ¶
func (r *DependencyResolver) ResolveDeps(taskName string) ([]string, error)
ResolveDeps returns tasks in dependency order (topological sort) Uses Kahn's algorithm for topological sorting
func (*DependencyResolver) ValidateDeps ¶
func (r *DependencyResolver) ValidateDeps(taskName string) error
ValidateDeps checks if all dependencies exist
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor handles task execution
func NewExecutor ¶
NewExecutor creates a new task executor
func (*Executor) SetCommandRunner ¶
func (e *Executor) SetCommandRunner(runner CommandRunner)
SetCommandRunner sets a custom command runner (for testing)
func (*Executor) ShowSummary ¶
ShowSummary shows detailed summary of tasks
type HybridCommandRunner ¶
type HybridCommandRunner struct {
// contains filtered or unexported fields
}
HybridCommandRunner routes commands to either omni (Cobra) or shell
func NewHybridCommandRunner ¶
func NewHybridCommandRunner(omniRunner CommandRunner, dir string) *HybridCommandRunner
NewHybridCommandRunner creates a hybrid command runner
type MockCommandRunner ¶
type MockCommandRunner struct {
Commands [][]string
Outputs map[string]string
Errors map[string]error
}
MockCommandRunner is for testing
func NewMockCommandRunner ¶
func NewMockCommandRunner() *MockCommandRunner
NewMockCommandRunner creates a mock command runner
func (*MockCommandRunner) SetError ¶
func (m *MockCommandRunner) SetError(cmd string, err error)
SetError sets an error for a command
func (*MockCommandRunner) SetOutput ¶
func (m *MockCommandRunner) SetOutput(cmd, output string)
SetOutput sets the output for a command
type Options ¶
type Options struct {
Taskfile string // Path to Taskfile.yml (default: current directory)
Dir string // Working directory
List bool // List available tasks
Verbose bool // Verbose output
DryRun bool // Show commands without executing
Force bool // Force run even if up-to-date
Silent bool // Suppress output
Summary bool // Show task summary/description
AllowExternal bool // Allow external (non-omni) commands
}
Options configures the task runner
type Precondition ¶
Precondition represents a precondition check
type ShellCommandRunner ¶
type ShellCommandRunner struct {
// contains filtered or unexported fields
}
ShellCommandRunner runs commands via the system shell
func NewShellCommandRunner ¶
func NewShellCommandRunner(dir string) *ShellCommandRunner
NewShellCommandRunner creates a shell command runner
type Task ¶
type Task struct {
Desc string `yaml:"desc"`
Summary string `yaml:"summary"`
Cmds []Command `yaml:"cmds"`
Deps []Dependency `yaml:"deps"`
Vars map[string]any `yaml:"vars"`
Status []string `yaml:"status"` // Commands to check if task is up-to-date
Sources []string `yaml:"sources"`
Generates []string `yaml:"generates"`
Dir string `yaml:"dir"`
Silent bool `yaml:"silent"`
Internal bool `yaml:"internal"` // Hide from list
Precondition *Precondition `yaml:"precondition"`
Aliases []string `yaml:"aliases"`
// contains filtered or unexported fields
}
Task represents a single task definition
type Taskfile ¶
type Taskfile struct {
Version string `yaml:"version"`
Vars map[string]any `yaml:"vars"`
Env map[string]string `yaml:"env"`
Tasks map[string]*Task `yaml:"tasks"`
Includes map[string]string `yaml:"includes"`
// contains filtered or unexported fields
}
Taskfile represents the parsed Taskfile.yml
func ParseTaskfile ¶
ParseTaskfile parses a Taskfile.yml file
func (*Taskfile) ListTaskNames ¶
ListTaskNames returns all non-internal task names
type VarResolver ¶
type VarResolver struct {
// contains filtered or unexported fields
}
VarResolver handles variable expansion in task commands
func NewVarResolver ¶
func NewVarResolver(global, task map[string]any, env map[string]string) *VarResolver
NewVarResolver creates a new variable resolver
func (*VarResolver) Expand ¶
func (r *VarResolver) Expand(s string) string
Expand expands all variables in a string