runner

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 {
	ValueWithList `yaml:",inline"`

	Usage string

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

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(interface{}) 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(interface{}) error) error

UnmarshalYAML allows strings to be interpreted as Do actions.

type CommandList

type CommandList []Command

CommandList is a list of commands with custom yaml unamrshaling.

func (*CommandList) UnmarshalYAML

func (cl *CommandList) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML allows single items to be used as lists.

type Config

type Config struct {
	Name  string `yaml:"name"`
	Usage string `yaml:"usage"`
	// 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 *Metadata,
	taskName string,
	args []string,
	flags map[string]string,
) (*Config, error)

ParseComplete parses the file completely with interpolation.

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unmarshals and assigns names to options and tasks.

type Context added in v0.6.0

type Context struct {
	// 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) PushTask added in v0.6.0

func (r *Context) PushTask(t *Task)

PushTask adds a sub-task to the task stack.

func (*Context) TaskNames added in v0.6.3

func (r *Context) TaskNames() []string

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

type Metadata

type Metadata struct {
	CfgText             []byte
	Interpreter         []string
	Directory           string
	InstallCompletion   string
	UninstallCompletion string
	PrintHelp           bool
	PrintVersion        bool
	Logger              *ui.Logger
}

Metadata contains global configuration settings.

Metadata should be instantiated using NewMetadata.

func NewMetadata added in v0.6.0

func NewMetadata() *Metadata

NewMetadata creates a metadata struct with a default logger.

func (*Metadata) Set

func (m *Metadata) Set(o OptGetter) error

Set sets the metadata based on options.

type OptGetter

type OptGetter interface {
	Bool(string) bool
	String(string) string
}

OptGetter pulls various options based on a name. These options will generally come from the command line.

type Option

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

	Short    string
	Type     string
	Usage    string
	Private  bool
	Required bool

	// Used to determine value
	Environment   string
	DefaultValues ValueList `yaml:"default"`

	// Computed members not specified in yaml file
	Name   string `yaml:"-"`
	Passed string `yaml:"-"`
	// 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) 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) UnmarshalYAML

func (o *Option) UnmarshalYAML(unmarshal func(interface{}) 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(interface{}) error) error

UnmarshalYAML unmarshals an ordered set of options and assigns names.

type Run

type Run struct {
	When           WhenList           `yaml:",omitempty"`
	Command        CommandList        `yaml:",omitempty"`
	SubTaskList    SubTaskList        `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(interface{}) error) error

UnmarshalYAML allows simple commands to represent run structs.

type RunList

type RunList []*Run

RunList is a list of run items with custom yaml unmarshaling.

func (*RunList) UnmarshalYAML

func (rl *RunList) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML allows single items to be used as lists.

type SubTask

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

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

func (*SubTask) UnmarshalYAML

func (s *SubTask) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML allows unmarshaling a string to represent the subtask name.

type SubTaskList

type SubTaskList []*SubTask

SubTaskList is a list of subtasks with custom yaml unmarshaling.

func (*SubTaskList) UnmarshalYAML

func (l *SubTaskList) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML allows single items to be used as lists.

type Task

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

	RunList     RunList `yaml:"run"`
	Finally     RunList `yaml:"finally,omitempty"`
	Usage       string  `yaml:",omitempty"`
	Description string  `yaml:",omitempty"`
	Private     bool
	Quiet       bool

	// 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() RunList

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(interface{}) 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(interface{}) error) error

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

type ValueList

type ValueList []Value

ValueList is a slice of values with custom unmarshaling.

func (*ValueList) UnmarshalYAML

func (vl *ValueList) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML allows single items to be used as lists.

type ValueWithList

type ValueWithList struct {
	ValuesAllowed marshal.StringList `yaml:"values"`
}

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

type When

type When struct {
	Command   marshal.StringList `yaml:",omitempty"`
	Exists    marshal.StringList `yaml:",omitempty"`
	NotExists marshal.StringList `yaml:"not-exists,omitempty"`
	OS        marshal.StringList `yaml:",omitempty"`

	Environment map[string]marshal.NullableStringList `yaml:",omitempty"`
	Equal       map[string]marshal.StringList         `yaml:",omitempty"`
	NotEqual    map[string]marshal.StringList         `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(interface{}) 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 []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(interface{}) 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