runner

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanCache added in v0.8.0

func CleanCache() error

CleanCache deletes all cached files.

func CleanProjectCache added in v0.8.0

func CleanProjectCache(cfgPath string) error

CleanProjectCache deletes cached files related to the current config file.

func CleanTaskCache added in v0.8.0

func CleanTaskCache(cfgPath string, task string) error

CleanTaskCache deletes cached files related to the given task.

func IsFailedCondition

func IsFailedCondition(err error) bool

IsFailedCondition checks if an error was because of a failed condition.

func IsUnspecifiedClause

func IsUnspecifiedClause(err error) bool

IsUnspecifiedClause checks if an error was because a clause is not defined.

Types

type Arg

type Arg struct {
	Passable `yaml:",inline"`
}

Arg represents a command-line argument.

func (*Arg) Evaluate

func (a *Arg) Evaluate() (string, error)

Evaluate determines an argument's value.

type Args

type Args []*Arg

Args represents an ordered set of arguments as specified in the config.

func (*Args) Lookup

func (a *Args) Lookup(name string) (*Arg, bool)

Lookup finds an Arg by name.

func (*Args) UnmarshalYAML

func (a *Args) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML unmarshals an ordered set of options and assigns names.

type Command

type Command struct {
	// Exec is the script to execute.
	Exec string `yaml:"exec"`

	// Print is the text that will be printed when the command is executed.
	Print string `yaml:"print"`

	// Quiet means that no text/hint will be printed before execution. Command
	// output is still printed, similar to '--quiet' flag.
	Quiet bool `yaml:"quiet,omitempty"`

	// Dir is the directory of the command.
	Dir string `yaml:"dir"`
}

Command is a command passed to the shell.

func (*Command) UnmarshalYAML

func (c *Command) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML allows strings to be interpreted as Do actions.

type Config

type Config struct {
	Name    string                 `yaml:"name"`
	Usage   string                 `yaml:"usage"`
	EnvFile marshal.Slice[EnvFile] `yaml:"env-file"`
	// The Interpreter field must be read before the config struct can be parsed
	// completely from YAML. To do so, the config text parses it elsewhere in the
	// code base independently from this struct.
	//
	// It is included here only so that strict unmarshaling does not fail.
	Interpreter string `yaml:"interpreter"`

	Tasks   map[string]*Task `yaml:"tasks"`
	Options Options          `yaml:"options,omitempty"`
}

Config is a struct representing the format for configuration settings.

func Parse

func Parse(text []byte) (*Config, error)

Parse loads the contents of a config file into a struct.

func ParseComplete

func ParseComplete(meta *ParseConfig) (*Config, error)

ParseComplete parses the file completely with env file parsing and interpolation.

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML unmarshals and assigns names to options and tasks.

type Context added in v0.6.0

type Context struct {
	// CfgPath is the full path of the configuration file.
	CfgPath string

	// Logger is responsible for logging actions as they occur. It is required to
	// be defined for a Context.
	Logger *ui.Logger

	// Interpreter specifies how a command is meant to be executed.
	Interpreter []string
	// contains filtered or unexported fields
}

Context contains contextual information about a run.

func (Context) Dir added in v0.7.0

func (c Context) Dir() string

Dir is the directory that defines the config file, which is the relative directory for all command execution.

func (Context) TaskNames added in v0.6.3

func (c Context) TaskNames() []string

TaskNames returns the list of task names in the stack, in order. Private tasks are filtered out.

func (Context) WithTask added in v0.8.0

func (c Context) WithTask(t *Task) Context

WithTask adds a sub-task to the task stack.

type EnvFile added in v0.7.0

type EnvFile struct {
	Path     string `yaml:"path"`
	Required bool   `yaml:"required"`
}

EnvFile is a dotenv file that should be parsed during configuration start.

func (*EnvFile) UnmarshalYAML added in v0.7.0

func (f *EnvFile) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML allows a string to represent a required path.

type Option

type Option struct {
	Passable `yaml:",inline"`

	Short    string
	Private  bool
	Required bool
	Rewrite  string

	// Used to determine value
	Environment   string
	DefaultValues marshal.Slice[Value] `yaml:"default"`
	// contains filtered or unexported fields
}

Option represents an abstract command line option.

func FindAllOptions

func FindAllOptions(t *Task, cfg *Config) ([]*Option, error)

FindAllOptions returns a list of options relevant for a given config.

func (*Option) Dependencies

func (o *Option) Dependencies() []string

Dependencies returns a list of options that are required explicitly. This does not include interpolations.

func (*Option) Equal added in v0.7.0

func (o *Option) Equal(other *Option) bool

Equal provides a method of checking option equality for testing purposes only.

func (*Option) Evaluate

func (o *Option) Evaluate(ctx Context, vars map[string]string) (string, error)

Evaluate determines an option's value.

The order of priority is:

  1. Command-line option passed
  2. Environment variable set
  3. The first item in the default value list with a valid when clause

Values may also be cached to avoid re-running commands.

func (*Option) StaticDefault added in v0.7.2

func (o *Option) StaticDefault() (string, bool)

StaticDefault returns the default value, if static.

func (*Option) UnmarshalYAML

func (o *Option) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML ensures that the option definition is valid.

type Options

type Options []*Option

Options represents an ordered set of options as specified in the config.

func (*Options) Lookup

func (o *Options) Lookup(name string) (*Option, bool)

Lookup finds an Option by name.

func (*Options) UnmarshalYAML

func (o *Options) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML unmarshals an ordered set of options and assigns names.

type ParseConfig added in v0.8.0

type ParseConfig struct {
	Args        []string
	CfgPath     string
	CfgText     []byte
	Flags       map[string]string
	Interpreter []string
	TaskName    string
}

ParseConfig is the configuration for parsing the configuration file.

type Passable added in v0.7.0

type Passable struct {
	Usage         string                `yaml:"usage"`
	Type          string                `yaml:"type"`
	ValuesAllowed marshal.Slice[string] `yaml:"values"`

	// Computed members not specified in yaml file
	Name   string `yaml:"-"`
	Passed string `yaml:"-"`
}

Passable is a list of allowable values for an option or argument.

type Run

type Run struct {
	When           WhenList                `yaml:",omitempty"`
	Command        marshal.Slice[*Command] `yaml:",omitempty"`
	SubTaskList    marshal.Slice[*SubTask] `yaml:"task,omitempty"`
	SetEnvironment map[string]*string      `yaml:"set-environment,omitempty"`

	// Computed members not specified in yaml file
	Tasks []Task `yaml:"-"`
}

Run defines a a single runnable item within a task.

func (*Run) UnmarshalYAML

func (r *Run) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML allows simple commands to represent run structs.

type SubTask

type SubTask struct {
	Name    string
	Args    marshal.Slice[string]
	Options map[string]string
}

SubTask is a description of a sub-task with passed options.

func (*SubTask) UnmarshalYAML

func (s *SubTask) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML allows unmarshaling a string to represent the subtask name.

type Task

type Task struct {
	Args    Args    `yaml:"args,omitempty"`
	Options Options `yaml:"options,omitempty"`

	RunList     marshal.Slice[*Run] `yaml:"run"`
	Finally     marshal.Slice[*Run] `yaml:"finally,omitempty"`
	Usage       string              `yaml:"usage,omitempty"`
	Description string              `yaml:"description,omitempty"`
	Private     bool                `yaml:"private"`
	Quiet       bool                `yaml:"quiet"`

	Source marshal.Slice[string] `yaml:"source"`
	Target marshal.Slice[string] `yaml:"target"`

	// Computed members not specified in yaml file
	Name string            `yaml:"-"`
	Vars map[string]string `yaml:"-"`
}

Task is a single task to be run by CLI.

func (*Task) AllRunItems

func (t *Task) AllRunItems() marshal.Slice[*Run]

AllRunItems returns all run items referenced, including `run` and `finally`.

func (*Task) Dependencies

func (t *Task) Dependencies() []string

Dependencies returns a list of options that are required explicitly. This does not include interpolations.

func (*Task) Execute

func (t *Task) Execute(ctx Context) (err error)

Execute runs the Run scripts in the task.

func (*Task) UnmarshalYAML

func (t *Task) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML unmarshals and assigns names to options.

type Value

type Value struct {
	When    WhenList
	Command string
	Value   string
}

Value represents a value candidate for an option. When the when condition is true, either the command or value will be used.

func (*Value) UnmarshalYAML

func (v *Value) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML allows plain strings to represent a full struct. The value of the string is used as the Default field.

type When

type When struct {
	Command   marshal.Slice[string] `yaml:",omitempty"`
	Exists    marshal.Slice[string] `yaml:",omitempty"`
	NotExists marshal.Slice[string] `yaml:"not-exists,omitempty"`
	OS        marshal.Slice[string] `yaml:",omitempty"`

	Environment map[string]marshal.Slice[*string] `yaml:",omitempty"`
	Equal       map[string]marshal.Slice[string]  `yaml:",omitempty"`
	NotEqual    map[string]marshal.Slice[string]  `yaml:"not-equal,omitempty"`
}

When defines the conditions for running a task.

func (*When) Dependencies

func (w *When) Dependencies() []string

Dependencies returns a list of options that are required explicitly. This does not include interpolations.

func (*When) UnmarshalYAML

func (w *When) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML warns about deprecated features.

func (*When) Validate

func (w *When) Validate(ctx Context, vars map[string]string) error

Validate returns an error if any when clauses fail.

type WhenList

type WhenList marshal.Slice[When]

WhenList is a list of when items with custom yaml unmarshaling.

func (*WhenList) Dependencies

func (l *WhenList) Dependencies() []string

Dependencies returns a list of options that are required explicitly. This does not include interpolations.

func (*WhenList) UnmarshalYAML

func (l *WhenList) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML allows single items to be used as lists.

func (*WhenList) Validate

func (l *WhenList) Validate(ctx Context, vars map[string]string) error

Validate returns an error if any when clauses fail.

Jump to

Keyboard shortcuts

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