task

package
v0.0.0-...-b1c5812 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: Apache-2.0 Imports: 14 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Required = Validator(func(name, s string) error {
	if s == "" {
		return fmt.Errorf("argument %q is required, but was not supplied", name)
	}

	return nil
})

Required is a validator that ensures that an argument is present.

Functions

func Run

func Run(registry *Registry, arguments []string) error

Run orders the tasks be dependencies to build an execution plan and then executes each required task.

Types

type Builder

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

Builder provides a fluent way to build up a task.

func (*Builder) Arg

func (b *Builder) Arg(name string, validator ...Validator) *Builder

Arg declares an argument for the task.

func (*Builder) ContinueOnError

func (b *Builder) ContinueOnError() *Builder

ContinueOnError declares that a task should not stop the build from continuing.

func (*Builder) Defer

func (b *Builder) Defer(names ...string) *Builder

Defer declares other tasks that should run after this one.

func (*Builder) DependsOn

func (b *Builder) DependsOn(names ...string) *Builder

DependsOn declares other tasks which must run before this one.

func (*Builder) Description

func (b *Builder) Description(description string) *Builder

Description sets the description for the task.

func (*Builder) Do

func (b *Builder) Do(executor Executor)

Do declares the executor when this task runs.

func (*Builder) Hide

func (b *Builder) Hide() *Builder

Hide the task from the task list.

func (*Builder) OptionalArg

func (b *Builder) OptionalArg(name string) *Builder

OptionalArg declares an optional argument for the task.

func (*Builder) OptionalArgs

func (b *Builder) OptionalArgs(names ...string) *Builder

OptionalArgs declares optional arguments for the task.

func (*Builder) RequiredArg

func (b *Builder) RequiredArg(name string) *Builder

RequiredArg declares a required argument for the task.

func (*Builder) RequiredArgs

func (b *Builder) RequiredArgs(names ...string) *Builder

RequiredArgs declares required arguments for the task.

type Context

type Context struct {
	context.Context

	UI      *TUI
	Verbose bool
	// contains filtered or unexported fields
}

Context holds information relevant to executing tasks.

func NewContext

func NewContext(ctx context.Context, w io.Writer, taskArgs map[string]string, params ...ContextParam) *Context

NewContext makes a new Context.

func (*Context) CopyArgs

func (ctx *Context) CopyArgs() map[string]string

CopyArgs returns a copy of the current context's task arguments.

func (*Context) Get

func (ctx *Context) Get(name string) string

Get returns an argument of the given name. If one doesn't exist, a lookup in the environment will be made.

func (*Context) Log

func (ctx *Context) Log(v ...interface{})

Log formats using the default formats for its operands sends it to the log. Spaces are added between operands when neither is a string.

func (*Context) Logf

func (ctx *Context) Logf(format string, v ...interface{})

Logf formats according to a format specifier and sends it to the log.

func (*Context) Logln

func (ctx *Context) Logln(v ...interface{})

Logln formats using the default formats for its operands and sends it to the log. Spaces are always added between operands and a newline is appended.

func (*Context) Write

func (ctx *Context) Write(p []byte) (n int, err error)

Writer implements the io.Writer interface.

type ContextParam

type ContextParam = func(ctx *Context)

func WithUI

func WithUI(ui *TUI) ContextParam

func WithVerbose

func WithVerbose(verbose bool) ContextParam

type DeclaredTaskArg

type DeclaredTaskArg struct {
	Name      string
	Validator Validator
}

DeclaredTaskArg is an argument for a particular task.

type Executor

type Executor func(*Context) error

Executor executes the body of a task.

type Registry

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

Registry holds all the tasks able to be run.

func NewRegistry

func NewRegistry(opts ...RegistryOption) *Registry

NewRegistry creates a new registry.

func (*Registry) Declare

func (r *Registry) Declare(name string) *Builder

Declare a task to be registered.

func (*Registry) Register

func (r *Registry) Register(task Task)

Register a task in the Configuration.

func (*Registry) Tasks

func (r *Registry) Tasks() []Task

Tasks returns all the tasks and pseudo-tasks.

type RegistryOption

type RegistryOption func(r *Registry)

RegistryOption is an option for setting up a task registry.

func WithAutoNamespaces

func WithAutoNamespaces(v bool) RegistryOption

WithAutoNamespaces tells the registry whether to automatically create namespace tasks.

func WithNamespaceSeparator

func WithNamespaceSeparator(s string) RegistryOption

WithNamespaceSeparator sets the separator for namespaces.

func WithShouldErrorOnUnusedArgs

func WithShouldErrorOnUnusedArgs(v bool) RegistryOption

WithShouldErrorOnUnusedArgs sets whether we should return an error when unused args are detected.

type TUI

type TUI struct{}

TUI is responsible for setting coloring information.

func (*TUI) Error

func (ui *TUI) Error(msg string) string

Error colors the msg as an error.

func (*TUI) Highlight

func (ui *TUI) Highlight(msg string) string

Highlight colors the msg as a highlight.

func (*TUI) Info

func (ui *TUI) Info(msg string) string

Info colors the msg as information.

func (*TUI) Lowlight

func (ui *TUI) Lowlight(msg string) string

Lowlight colors the msg as a lowlight.

func (*TUI) Success

func (ui *TUI) Success(msg string) string

Success colors the msg as success.

func (*TUI) Warning

func (ui *TUI) Warning(msg string) string

Warning colors the msg as warning.

type Task

type Task interface {
	ContinueOnError() bool
	DeclaredArgs() []DeclaredTaskArg
	Dependencies() []string
	Description() string
	Executor() Executor
	Hidden() bool
	Name() string
	DeferredTasks() []string
}

Task represents a task to be executed

type Validator

type Validator func(string, string) error

Validator validates arguments.

func ChainValidator

func ChainValidator(validators ...Validator) Validator

ChainValidator is a validator that is the conjunction of the given validators.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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