task

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package task implements a task runner for omni-only commands. It parses Taskfile.yml format and executes only omni internal commands.

Index

Constants

This section is empty.

Variables

View Source
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

View Source
var DefaultTaskfiles = []string{
	"Taskfile.yml",
	"Taskfile.yaml",
	"taskfile.yml",
	"taskfile.yaml",
}

DefaultTaskfiles lists the default taskfile names to search for

Functions

func EvaluateDynamicVar

func EvaluateDynamicVar(v any) (string, error)

EvaluateDynamicVar evaluates a dynamic variable (sh command result) For omni, we only support static values, not shell execution

func MergeVars

func MergeVars(maps ...map[string]any) map[string]any

MergeVars merges multiple variable maps (later takes precedence)

func Run

func Run(ctx context.Context, w io.Writer, taskNames []string, opts Options) error

Run executes the task runner

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

func (*CobraCommandRunner) Run

func (r *CobraCommandRunner) Run(ctx context.Context, w io.Writer, args []string) error

Run executes a command using Cobra

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

func (*Command) UnmarshalYAML

func (c *Command) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements custom unmarshaling for Command

type CommandRunner

type CommandRunner interface {
	Run(ctx context.Context, w io.Writer, args []string) error
}

CommandRunner is the interface for running omni commands

type DefaultCommandRunner

type DefaultCommandRunner struct{}

DefaultCommandRunner runs omni commands via the command registry

func (*DefaultCommandRunner) Run

func (r *DefaultCommandRunner) Run(ctx context.Context, w io.Writer, args []string) error

Run executes an omni command (default implementation) This will be overridden to use the actual omni command registry

type Dependency

type Dependency struct {
	Task string         `yaml:"task"`
	Vars map[string]any `yaml:"vars"`
}

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

func NewExecutor(w io.Writer, tf *Taskfile, opts Options) *Executor

NewExecutor creates a new task executor

func (*Executor) ListTasks

func (e *Executor) ListTasks() error

ListTasks prints available tasks

func (*Executor) RunTask

func (e *Executor) RunTask(ctx context.Context, name string) error

RunTask executes a task and its dependencies

func (*Executor) SetCommandRunner

func (e *Executor) SetCommandRunner(runner CommandRunner)

SetCommandRunner sets a custom command runner (for testing)

func (*Executor) ShowSummary

func (e *Executor) ShowSummary(taskNames []string) error

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

func (*HybridCommandRunner) Run

func (r *HybridCommandRunner) Run(ctx context.Context, w io.Writer, args []string) error

Run executes a command, routing to omni or shell as appropriate

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) Run

func (m *MockCommandRunner) Run(ctx context.Context, w io.Writer, args []string) error

Run records the command and returns mocked output/error

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

type Precondition struct {
	Sh  string `yaml:"sh"`
	Msg string `yaml:"msg"`
}

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

func (*ShellCommandRunner) Run

func (r *ShellCommandRunner) Run(ctx context.Context, w io.Writer, args []string) error

Run executes a command via the system shell

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

func ParseTaskfile(path string) (*Taskfile, error)

ParseTaskfile parses a Taskfile.yml file

func (*Taskfile) GetTask

func (tf *Taskfile) GetTask(name string) *Task

GetTask returns a task by name, checking aliases

func (*Taskfile) ListTaskNames

func (tf *Taskfile) ListTaskNames() []string

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

Jump to

Keyboard shortcuts

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