tasks

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvGitRoot    = "MOTF_GIT_ROOT"
	EnvModulePath = "MOTF_MODULE_PATH"
	EnvModuleName = "MOTF_MODULE_NAME"
	EnvConfigPath = "MOTF_CONFIG_PATH"
	EnvBinary     = "MOTF_BINARY"
)

Environment variable names for built-in variables

View Source
const (
	ScopeModule = "module"
	ScopeRoot   = "root"
	ScopeGit    = "git"
)

Task scope constants

View Source
const DefaultShell = "sh"

DefaultShell is the default shell when none is specified

Variables

View Source
var Shells = map[string]ShellConfig{
	"sh":   {Binary: "sh", Args: []string{"-c"}},
	"bash": {Binary: "bash", Args: []string{"-c"}},
	"pwsh": {Binary: "pwsh", Args: []string{"-Command"}},
	"cmd":  {Binary: "cmd", Args: []string{"/C"}},
}

Shells is the registry of supported shells

Functions

func GetShellArgs

func GetShellArgs(shell, script string) (binary string, args []string, err error)

GetShellArgs returns the binary and arguments needed to execute a script with the given shell. Returns an error if the shell is not supported.

func ModuleNameFromPath added in v0.8.0

func ModuleNameFromPath(modulePath string) string

ModuleNameFromPath extracts the module name from an absolute module path. It returns the last component of the path (e.g., "/path/to/storage-account" -> "storage-account").

func SupportedShells

func SupportedShells() []string

SupportedShells returns a sorted list of supported shell names

Types

type EnvBuilder added in v0.8.0

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

EnvBuilder constructs environment variables for task execution. It starts with the current process environment and adds MOTF_* built-in variables.

func NewEnvBuilder added in v0.8.0

func NewEnvBuilder() *EnvBuilder

NewEnvBuilder creates a new EnvBuilder with empty built-in variables.

func (*EnvBuilder) Build added in v0.8.0

func (b *EnvBuilder) Build() []string

Build returns the complete environment for task execution. It includes the current process environment plus all MOTF_* built-in variables.

func (*EnvBuilder) WithBinary added in v0.8.0

func (b *EnvBuilder) WithBinary(binary string) *EnvBuilder

WithBinary sets the MOTF_BINARY variable.

func (*EnvBuilder) WithConfigPath added in v0.8.0

func (b *EnvBuilder) WithConfigPath(configPath string) *EnvBuilder

WithConfigPath sets the MOTF_CONFIG_PATH variable.

func (*EnvBuilder) WithGitRoot added in v0.8.0

func (b *EnvBuilder) WithGitRoot(gitRoot string) *EnvBuilder

WithGitRoot sets the MOTF_GIT_ROOT variable.

func (*EnvBuilder) WithModuleName added in v0.8.0

func (b *EnvBuilder) WithModuleName(moduleName string) *EnvBuilder

WithModuleName sets the MOTF_MODULE_NAME variable. If empty, it will be derived from the module path if available.

func (*EnvBuilder) WithModulePath added in v0.8.0

func (b *EnvBuilder) WithModulePath(modulePath string) *EnvBuilder

WithModulePath sets the MOTF_MODULE_PATH variable.

type Runner

type Runner struct {
	Tasks map[string]*TaskConfig
	Env   []string // Environment variables for task execution (includes MOTF_* built-ins)
}

Runner executes custom tasks

func NewRunner

func NewRunner(tasks map[string]*TaskConfig, env []string) *Runner

NewRunner creates a new task runner with the given task definitions

func (*Runner) GetTask

func (r *Runner) GetTask(name string) *TaskConfig

GetTask returns the task config for the given name, or nil if not found

func (*Runner) ListTasks

func (r *Runner) ListTasks() []string

ListTasks returns all task names

func (*Runner) Run

func (r *Runner) Run(taskName, workDir string) error

Run executes a task by name in the given working directory

func (*Runner) RunWithOutput added in v0.8.0

func (r *Runner) RunWithOutput(taskName, workDir string, stdout, stderr io.Writer) error

RunWithOutput executes a task with custom output writers

type ShellConfig

type ShellConfig struct {
	Binary string
	Args   []string // args before the script
}

ShellConfig defines how to invoke a shell

type TaskConfig

type TaskConfig struct {
	Description string `yaml:"description"`
	Shell       string `yaml:"shell"`
	Command     string `yaml:"command"`
	Scope       string `yaml:"scope"`
}

TaskConfig represents a custom task definition

func (*TaskConfig) EffectiveScope added in v0.9.0

func (tc *TaskConfig) EffectiveScope() string

EffectiveScope returns the task's scope, defaulting to "module" if unset.

func (*TaskConfig) ValidateScope added in v0.9.0

func (tc *TaskConfig) ValidateScope() error

ValidateScope returns an error if the scope value is not recognized.

Jump to

Keyboard shortcuts

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