ast

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimestampLayout = "[2006-01-02T15:04:05.000Z]"

DefaultTimestampLayout is the Go time layout used when `timestamps: true` is set (at any scope). ISO 8601 extended, UTC, zero-padded millisecond precision, square-bracketed so the prefix is visually separable from cmd content. See SPEC §Output Timestamps.

View Source
const NamespaceSeparator = ":"

NamespaceSeparator contains the character that separates namespaces

View Source
const TimestampMarkerEnvVar = "RITE_TIMESTAMPS_HANDLED"

TimestampMarkerEnvVar is the marker variable rite injects into a cmd's environ whenever its output is being wrapped by a TimestampWriter. A nested rite invocation that sees this variable set to "1" skips its own timestamp wrapping entirely — otherwise every level of nesting would add another prefix and multi-level `rite`-calls-`rite` chains would emit `[ts] [ts] [ts] line`. See SPEC §Output Timestamps / "Nested invocations".

Variables

View Source
var (
	V3 = semver.MustParse("3")
	// V4 marks the first unsupported future schema version. `doVersionChecks`
	// rejects any schema `>= V4` so a Ritefile authored against a future
	// schema fails loudly on an older rite instead of silently degrading to
	// v3 semantics — the same fail-loudly philosophy as the v2 rejection
	// below V3.
	V4 = semver.MustParse("4")
)
View Source
var ErrIncludedRitefilesCantHaveDotenvs = errors.New("rite: Included Ritefiles can't have dotenv declarations. Please, move the dotenv declaration to the main Ritefile")

ErrIncludedRitefilesCantHaveDotenvs is returned when an included Ritefile contains dotenvs

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	Cmd         string      `yaml:"cmd"`
	Task        string      `yaml:"task"`
	For         *For        `yaml:"for"`
	If          string      `yaml:"if"`
	Silent      bool        `yaml:"silent"`
	Set         []string    `yaml:"set"`
	Shopt       []string    `yaml:"shopt"`
	Vars        *Vars       `yaml:"vars"`
	IgnoreError bool        `yaml:"ignore_error"`
	Defer       bool        `yaml:"defer"`
	Platforms   []*Platform `yaml:"platforms"`
}

Cmd is a task command

func (*Cmd) DeepCopy

func (c *Cmd) DeepCopy() *Cmd

func (*Cmd) UnmarshalYAML

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

type Defer

type Defer struct {
	Cmd    string `yaml:"defer"`
	Task   string `yaml:"task"`
	Vars   *Vars  `yaml:"vars"`
	Silent bool   `yaml:"silent"`
}

func (*Defer) UnmarshalYAML

func (d *Defer) UnmarshalYAML(node *yaml.Node) error

type Dep

type Dep struct {
	Task   string `yaml:"task"`
	For    *For   `yaml:"for"`
	Vars   *Vars  `yaml:"vars"`
	Silent bool   `yaml:"silent"`
}

Dep is a task dependency

func (*Dep) DeepCopy

func (d *Dep) DeepCopy() *Dep

func (*Dep) UnmarshalYAML

func (d *Dep) UnmarshalYAML(node *yaml.Node) error

type Enum

type Enum struct {
	Ref   string   `yaml:"ref"`
	Value []string `yaml:"-"`
}

Enum represents an enum constraint for a required variable. It can either be a static list of values or a reference to another variable.

func (*Enum) DeepCopy

func (e *Enum) DeepCopy() *Enum

func (*Enum) UnmarshalYAML

func (e *Enum) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler interface.

type ErrInvalidPlatform

type ErrInvalidPlatform struct {
	Platform string
}

func (*ErrInvalidPlatform) Error

func (err *ErrInvalidPlatform) Error() string

type For

type For struct {
	From   string  `yaml:"-"`
	List   []any   `yaml:"-"`
	Matrix *Matrix `yaml:"matrix"`
	Var    string  `yaml:"var"`
	Split  string  `yaml:"split"`
	As     string  `yaml:"as"`
}

func (*For) DeepCopy

func (f *For) DeepCopy() *For

func (*For) UnmarshalYAML

func (f *For) UnmarshalYAML(node *yaml.Node) error

type Glob

type Glob struct {
	Glob   string `yaml:"-"`
	Negate bool   `yaml:"-"`
}

func (*Glob) UnmarshalYAML

func (g *Glob) UnmarshalYAML(node *yaml.Node) error

type Include

type Include struct {
	Namespace      string   `yaml:"-"`
	Ritefile       string   `yaml:"taskfile"`
	Dir            string   `yaml:"dir"`
	Optional       bool     `yaml:"optional"`
	Internal       bool     `yaml:"internal"`
	Aliases        []string `yaml:"aliases"`
	Excludes       []string `yaml:"excludes"`
	AdvancedImport bool     `yaml:"-"`
	Vars           *Vars    `yaml:"vars"`
	Flatten        bool     `yaml:"flatten"`
	Checksum       string   `yaml:"checksum"`
}

Include represents information about included taskfiles

func (*Include) DeepCopy

func (include *Include) DeepCopy() *Include

DeepCopy creates a new instance of IncludedTaskfile and copies data by value from the source struct.

func (*Include) UnmarshalYAML

func (include *Include) UnmarshalYAML(node *yaml.Node) error

type IncludeElement

type IncludeElement orderedmap.Element[string, *Include]

An IncludeElement is a key-value pair that is used for initializing an Includes structure.

type Includes

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

Includes is an ordered map of namespaces to includes.

func NewIncludes

func NewIncludes(els ...*IncludeElement) *Includes

NewIncludes creates a new instance of Includes and initializes it with the provided set of elements, if any. The elements are added in the order they are passed.

func (*Includes) All

func (includes *Includes) All() iter.Seq2[string, *Include]

All returns an iterator that loops over all task key-value pairs. Range calls the provided function for each include in the map. The function receives the include's key and value as arguments. If the function returns an error, the iteration stops and the error is returned.

func (*Includes) Get

func (includes *Includes) Get(key string) (*Include, bool)

Get returns the value the the include with the provided key and a boolean that indicates if the value was found or not. If the value is not found, the returned include is a zero value and the bool is false.

func (*Includes) Keys

func (includes *Includes) Keys() iter.Seq[string]

Keys returns an iterator that loops over all task keys.

func (*Includes) Len

func (includes *Includes) Len() int

Len returns the number of includes in the Includes map.

func (*Includes) Set

func (includes *Includes) Set(key string, value *Include) bool

Set sets the value of the include with the provided key to the provided value. If the include already exists, its value is updated. If the include does not exist, it is created.

func (*Includes) UnmarshalYAML

func (includes *Includes) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

func (*Includes) Values

func (includes *Includes) Values() iter.Seq[*Include]

Values returns an iterator that loops over all task values.

type Location

type Location struct {
	Line     int
	Column   int
	Ritefile string
}

func (*Location) DeepCopy

func (l *Location) DeepCopy() *Location

type Matrix

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

Matrix is an ordered map of variable names to arrays of values.

func NewMatrix

func NewMatrix(els ...*MatrixElement) *Matrix

func (*Matrix) All

func (matrix *Matrix) All() iter.Seq2[string, *MatrixRow]

All returns an iterator that loops over all task key-value pairs.

func (*Matrix) DeepCopy

func (matrix *Matrix) DeepCopy() *Matrix

func (*Matrix) Get

func (matrix *Matrix) Get(key string) (*MatrixRow, bool)

func (*Matrix) Keys

func (matrix *Matrix) Keys() iter.Seq[string]

Keys returns an iterator that loops over all task keys.

func (*Matrix) Len

func (matrix *Matrix) Len() int

func (*Matrix) Set

func (matrix *Matrix) Set(key string, value *MatrixRow) bool

func (*Matrix) UnmarshalYAML

func (matrix *Matrix) UnmarshalYAML(node *yaml.Node) error

func (*Matrix) Values

func (matrix *Matrix) Values() iter.Seq[*MatrixRow]

Values returns an iterator that loops over all task values.

type MatrixElement

type MatrixElement orderedmap.Element[string, *MatrixRow]

A MatrixElement is a key-value pair that is used for initializing a Matrix structure.

type MatrixRow

type MatrixRow struct {
	Ref   string `yaml:"ref"`
	Value []any  `yaml:"-"`
}

A MatrixRow list of values for a matrix key or a reference to another variable.

type Output

type Output struct {
	// Name of the Output.
	Name string `yaml:"-"`
	// Group specific style
	Group OutputGroup `yaml:"group"`
}

Output of the Task output

func (*Output) IsSet

func (s *Output) IsSet() bool

IsSet returns true if and only if a custom output style is set.

func (*Output) UnmarshalYAML

func (s *Output) UnmarshalYAML(node *yaml.Node) error

type OutputGroup

type OutputGroup struct {
	Begin     string `yaml:"begin"`
	End       string `yaml:"end"`
	ErrorOnly bool   `yaml:"error_only"`
}

OutputGroup is the style options specific to the Group style.

func (*OutputGroup) IsSet

func (g *OutputGroup) IsSet() bool

IsSet returns true if and only if a custom output style is set.

type Platform

type Platform struct {
	OS   string `yaml:"-"`
	Arch string `yaml:"-"`
}

Platform represents GOOS and GOARCH values

func (*Platform) DeepCopy

func (p *Platform) DeepCopy() *Platform

func (*Platform) UnmarshalYAML

func (p *Platform) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler interface.

type Precondition

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

Precondition represents a precondition necessary for a task to run

func (*Precondition) DeepCopy

func (p *Precondition) DeepCopy() *Precondition

func (*Precondition) UnmarshalYAML

func (p *Precondition) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler interface.

type Prompt

type Prompt []string

func (*Prompt) UnmarshalYAML

func (p *Prompt) UnmarshalYAML(node *yaml.Node) error

type Requires

type Requires struct {
	Vars []*VarsWithValidation `yaml:"vars"`
}

Requires represents a set of required variables necessary for a task to run

func (*Requires) DeepCopy

func (r *Requires) DeepCopy() *Requires

type Ritefile added in v1.0.0

type Ritefile struct {
	Location   string          `yaml:"-"`
	Version    *semver.Version `yaml:"version"`
	Output     Output          `yaml:"output"`
	Method     string          `yaml:"method"`
	Includes   *Includes       `yaml:"includes"`
	Set        []string        `yaml:"set"`
	Shopt      []string        `yaml:"shopt"`
	Vars       *Vars           `yaml:"vars"`
	Env        *Vars           `yaml:"env"`
	Tasks      *Tasks          `yaml:"tasks"`
	Silent     bool            `yaml:"silent"`
	Dotenv     []string        `yaml:"dotenv"`
	Run        string          `yaml:"run"`
	Interval   time.Duration   `yaml:"interval"`
	Timestamps *Timestamps     `yaml:"timestamps,omitempty"`
}

Ritefile is the abstract syntax tree for a Ritefile

func (*Ritefile) Merge added in v1.0.0

func (t1 *Ritefile) Merge(t2 *Ritefile, include *Include) error

Merge merges the second Ritefile into the first

func (*Ritefile) UnmarshalYAML added in v1.0.0

func (tf *Ritefile) UnmarshalYAML(node *yaml.Node) error

type RitefileGraph added in v1.0.0

type RitefileGraph struct {
	sync.Mutex
	graph.Graph[string, *RitefileVertex]
}

func NewRitefileGraph added in v1.0.0

func NewRitefileGraph() *RitefileGraph

func (*RitefileGraph) Merge added in v1.0.0

func (tfg *RitefileGraph) Merge() (*Ritefile, error)

func (*RitefileGraph) Visualize added in v1.0.0

func (tfg *RitefileGraph) Visualize(filename string) error

type RitefileVertex added in v1.0.0

type RitefileVertex struct {
	URI      string
	Ritefile *Ritefile
}

A RitefileVertex is a vertex on the Ritefile DAG.

type Task

type Task struct {
	Task          string          `yaml:"-" hash:"ignore"`
	Cmds          []*Cmd          `yaml:"cmds"`
	Deps          []*Dep          `yaml:"deps"`
	Label         string          `yaml:"label"`
	Desc          string          `yaml:"desc"`
	Prompt        Prompt          `yaml:"prompt"`
	Summary       string          `yaml:"summary"`
	Requires      *Requires       `yaml:"requires"`
	Aliases       []string        `yaml:"aliases"`
	Sources       []*Glob         `yaml:"sources"`
	Generates     []*Glob         `yaml:"generates"`
	Status        []string        `yaml:"status"`
	Preconditions []*Precondition `yaml:"preconditions"`
	Dir           string          `yaml:"dir"`
	Set           []string        `yaml:"set"`
	Shopt         []string        `yaml:"shopt"`
	Vars          *Vars           `yaml:"vars"`
	Env           *Vars           `yaml:"env"`
	Dotenv        []string        `yaml:"dotenv"`
	Silent        *bool           `yaml:"silent,omitempty"`
	Interactive   bool            `yaml:"interactive"`
	Internal      bool            `yaml:"internal"`
	Method        string          `yaml:"method"`
	Prefix        string          `yaml:"prefix" hash:"ignore"`
	IgnoreError   bool            `yaml:"ignore_error"`
	Run           string          `yaml:"run"`
	Platforms     []*Platform     `yaml:"platforms"`
	If            string          `yaml:"if"`
	Watch         bool            `yaml:"watch"`
	Location      *Location       `yaml:"-"`
	Failfast      bool            `yaml:"failfast"`
	Timestamps    *Timestamps     `yaml:"timestamps,omitempty"`
	// Populated during merging
	Namespace            string `yaml:"-" hash:"ignore"`
	IncludeVars          *Vars  `yaml:"-"`
	IncludedRitefileVars *Vars  `yaml:"-"`

	FullName string `yaml:"-" hash:"ignore"`
}

Task represents a task

func (*Task) DeepCopy

func (t *Task) DeepCopy() *Task

DeepCopy creates a new instance of Task and copies data by value from the source struct.

func (*Task) IsSilent

func (t *Task) IsSilent() bool

IsSilent returns true if the task has silent mode explicitly enabled. Returns false if Silent is nil (not set) or explicitly set to false.

func (*Task) LocalName

func (t *Task) LocalName() string

func (*Task) Name

func (t *Task) Name() string

func (*Task) UnmarshalYAML

func (t *Task) UnmarshalYAML(node *yaml.Node) error

func (*Task) WildcardMatch

func (t *Task) WildcardMatch(name string) (bool, []string)

WildcardMatch will check if the given string matches the name of the Task and returns any wildcard values.

type TaskElement

type TaskElement orderedmap.Element[string, *Task]

A TaskElement is a key-value pair that is used for initializing a Tasks structure.

type Tasks

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

Tasks is an ordered map of task names to Tasks.

func NewTasks

func NewTasks(els ...*TaskElement) *Tasks

NewTasks creates a new instance of Tasks and initializes it with the provided set of elements, if any. The elements are added in the order they are passed.

func (*Tasks) All

func (t *Tasks) All(sorter sort.Sorter) iter.Seq2[string, *Task]

All returns an iterator that loops over all task key-value pairs in the order specified by the sorter.

func (*Tasks) Get

func (tasks *Tasks) Get(key string) (*Task, bool)

Get returns the value the the task with the provided key and a boolean that indicates if the value was found or not. If the value is not found, the returned task is a zero value and the bool is false.

func (*Tasks) Keys

func (t *Tasks) Keys(sorter sort.Sorter) iter.Seq[string]

Keys returns an iterator that loops over all task keys in the order specified by the sorter.

func (*Tasks) Len

func (tasks *Tasks) Len() int

Len returns the number of variables in the Tasks map.

func (*Tasks) Merge

func (t1 *Tasks) Merge(t2 *Tasks, include *Include, includedRitefileVars *Vars) error

func (*Tasks) Set

func (tasks *Tasks) Set(key string, value *Task) bool

Set sets the value of the task with the provided key to the provided value. If the task already exists, its value is updated. If the task does not exist, it is created.

func (*Tasks) UnmarshalYAML

func (t *Tasks) UnmarshalYAML(node *yaml.Node) error

func (*Tasks) Values

func (t *Tasks) Values(sorter sort.Sorter) iter.Seq[*Task]

Values returns an iterator that loops over all task values in the order specified by the sorter.

type Timestamps added in v1.0.4

type Timestamps struct {
	// Enabled is non-nil when the user explicitly set a value at this scope.
	// *Enabled == true means on; *Enabled == false means off.
	Enabled *bool
	// Format is the optional strftime-style format string. Empty means "use
	// the default layout" (when Enabled is *true).
	Format string
}

Timestamps is the tri-state value for the `timestamps:` knob at both the entrypoint level and the task level.

- Unset (nil) → inherit from the next-higher scope (or off if top-level). - Explicit `true` → use DefaultTimestampLayout. - Explicit `false` → off (overrides a higher-scope `true`). - Explicit strftime string → use that format.

The value is stored on a pointer so the YAML decoder can distinguish "omitted" (nil) from "false" (present, disabled). A bool-only field cannot express the override-off-a-global-on case.

func (*Timestamps) DeepCopy added in v1.0.4

func (t *Timestamps) DeepCopy() *Timestamps

DeepCopy returns a deep copy of the Timestamps value, including a fresh pointer for Enabled so callers can mutate one copy without racing the other.

func (*Timestamps) IsSet added in v1.0.4

func (t *Timestamps) IsSet() bool

IsSet reports whether the user declared a value for this scope.

func (*Timestamps) On added in v1.0.4

func (t *Timestamps) On() bool

On reports whether timestamps are enabled at this scope. Callers must check IsSet() first — On() on an unset value returns false.

func (*Timestamps) UnmarshalYAML added in v1.0.4

func (t *Timestamps) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML accepts `true`, `false`, or a strftime string.

type Var

type Var struct {
	Value  any     `yaml:"value"`
	Live   any     `yaml:"-"`
	Sh     *string `yaml:"sh"`
	Ref    string  `yaml:"ref"`
	Dir    string  `yaml:"-"`
	Export *bool   `yaml:"export"`
}

Var represents either a static or dynamic variable.

Export controls whether this variable is propagated to cmd shell environments. A nil pointer means "default" — currently equivalent to true. Users opt out of export with `export: false` in the map form (SPEC §vars/env Unification, non-exported variables section).

func (Var) Exported

func (v Var) Exported() bool

Exported reports whether v should be added to a cmd's process environ. Unset Export behaves as true (default).

func (*Var) UnmarshalYAML

func (v *Var) UnmarshalYAML(node *yaml.Node) error

type VarElement

type VarElement orderedmap.Element[string, Var]

A VarElement is a key-value pair that is used for initializing a Vars structure.

type Vars

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

Vars is an ordered map of variable names to values.

func NewVars

func NewVars(els ...*VarElement) *Vars

NewVars creates a new instance of Vars and initializes it with the provided set of elements, if any. The elements are added in the order they are passed.

func (*Vars) All

func (vars *Vars) All() iter.Seq2[string, Var]

All returns an iterator that loops over all task key-value pairs.

func (*Vars) DeepCopy

func (vs *Vars) DeepCopy() *Vars

func (*Vars) Get

func (vars *Vars) Get(key string) (Var, bool)

Get returns the value the the variable with the provided key and a boolean that indicates if the value was found or not. If the value is not found, the returned variable is a zero value and the bool is false.

func (*Vars) Keys

func (vars *Vars) Keys() iter.Seq[string]

Keys returns an iterator that loops over all task keys.

func (*Vars) Len

func (vars *Vars) Len() int

Len returns the number of variables in the Vars map.

func (*Vars) Merge

func (vars *Vars) Merge(other *Vars, include *Include)

Merge loops over other and merges its values with the variables in vars. If the include parameter is not nil and is an advanced import, the directory is set to the value of the include parameter.

Snapshots `other` under its read lock, then writes into `vars` under its write lock. Holding the two locks disjointly mirrors ReverseMerge and keeps concurrent readers/writers on either side safe — see issue #48. The bug it replaces wrote into vars.om with no lock on vars at all, which went unnoticed because graph.Merge currently serializes the include walk; the moment that parallelism is restored (#49) the racy writes become live.

func (*Vars) ReverseMerge

func (vars *Vars) ReverseMerge(other *Vars, include *Include)

ReverseMerge merges other variables with the existing variables in vars, but keeps the other variables first in order. If the include parameter is not nil and it is an advanced import, the directory is set to the value of the include parameter.

func (*Vars) Set

func (vars *Vars) Set(key string, value Var) bool

Set sets the value of the variable with the provided key to the provided value. If the variable already exists, its value is updated. If the variable does not exist, it is created.

func (*Vars) ToCacheMap

func (vars *Vars) ToCacheMap() (m map[string]any)

ToCacheMap converts Vars to an unordered map containing only the static variables

func (*Vars) UnmarshalYAML

func (vs *Vars) UnmarshalYAML(node *yaml.Node) error

func (*Vars) Values

func (vars *Vars) Values() iter.Seq[Var]

Values returns an iterator that loops over all task values.

type VarsWithValidation

type VarsWithValidation struct {
	Name string `yaml:"name"`
	Enum *Enum  `yaml:"enum"`
}

func (*VarsWithValidation) DeepCopy

func (v *VarsWithValidation) DeepCopy() *VarsWithValidation

func (*VarsWithValidation) UnmarshalYAML

func (v *VarsWithValidation) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML implements yaml.Unmarshaler interface.

Jump to

Keyboard shortcuts

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