task

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: MIT Imports: 5 Imported by: 3

Documentation

Overview

Package task provides tasks and runner for Mage.

Index

Constants

View Source
const (
	// ErrIncompatibleRunner indicates that a command runner is not compatible for a task.
	ErrIncompatibleRunner = wErr.ErrString("incompatible command runner")

	// ErrInvalidRunnerOpts indicates invalid command runner options.
	ErrInvalidRunnerOpts = wErr.ErrString("invalid options")

	// ErrInvalidTaskOpts indicates invalid task options.
	ErrInvalidTaskOpts = wErr.ErrString("invalid options")

	// ErrRun indicates that a runner failed to run.
	ErrRun = wErr.ErrString("failed to run")

	// ErrRunnerValidation indicates that a command runner validation failed.
	ErrRunnerValidation = wErr.ErrString("validation failed")

	// ErrTaskValidation indicates that a task validation failed.
	ErrTaskValidation = wErr.ErrString("validation failed")

	// ErrUnsupportedTaskKind indicates that a task kind is not supported.
	ErrUnsupportedTaskKind = wErr.ErrString("unsupported task kind")

	// ErrUnsupportedTaskOptions indicates that the task options are not supported.
	ErrUnsupportedTaskOptions = wErr.ErrString("unsupported task kind")
)
View Source
const (
	// KindNameBase is the kind name for base tasks.
	KindNameBase = "base"
	// KindNameExec is the kind name for executable file tasks.
	KindNameExec = "executable"
	// KindNameGoModule is the kind name for Go module tasks.
	KindNameGoModule = "go.module"
	// KindNameUnknown is the name for a unknown task kind.
	KindNameUnknown = "unknown"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrRunner

type ErrRunner struct {
	// Err is a wrapped error.
	Err error
	// Kind is the error kind.
	Kind error
}

ErrRunner represents a runner error.

func (*ErrRunner) Error

func (e *ErrRunner) Error() string

func (*ErrRunner) Is

func (e *ErrRunner) Is(err error) bool

Is enables usage of errors.Is() to determine the kind of error that occurred.

func (*ErrRunner) Unwrap

func (e *ErrRunner) Unwrap() error

Unwrap returns the underlying error for usage with errors.Unwrap().

type ErrTask

type ErrTask struct {
	// Err is a wrapped error.
	Err error
	// Kind is the error kind.
	Kind error
}

ErrTask represents a task error.

func (*ErrTask) Error

func (e *ErrTask) Error() string

func (*ErrTask) Is

func (e *ErrTask) Is(err error) bool

Is enables usage of errors.Is() to determine the kind of error that occurred.

func (*ErrTask) Unwrap

func (e *ErrTask) Unwrap() error

Unwrap returns the underlying error for usage with errors.Unwrap().

type Exec

type Exec interface {
	Task

	// BuildParams builds the parameters for a command runner.
	// Parameters consist of options, flags and arguments.
	// The separation of parameters from commands enables a flexible usage, e.g. when parameters can be reused for
	// different tasks.
	//
	// References
	//
	//   (1) https://en.wikipedia.org/wiki/Command-line_interface#Anatomy_of_a_shell_CLI
	BuildParams() []string

	// Env returns the task specific environment.
	Env() map[string]string
}

Exec is a task for a executable command.

type GoModule

type GoModule interface {
	Exec

	// ID returns the identifier of a Go module.
	ID() *project.GoModuleID
}

GoModule is a task for a Go module command.

See https://golang.org/ref/mod for more details about Go modules.

type Kind

type Kind uint32

Kind defines the kind of tasks.

const (
	// KindBase is the kind for base tasks.
	KindBase Kind = iota
	// KindExec is the kind for executable file tasks.
	KindExec
	// KindGoModule is the kind for Go module tasks.
	KindGoModule
)

func ParseKind

func ParseKind(name string) (Kind, error)

ParseKind takes a kind name and returns the Kind constant.

func (Kind) MarshalText

func (k Kind) MarshalText() ([]byte, error)

MarshalText returns the textual representation of itself.

func (Kind) String

func (k Kind) String() string

func (*Kind) UnmarshalText

func (k *Kind) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler to unmarshal a textual representation of itself.

type Mixin

type Mixin interface {
	// Apply applies the mixin to task options.
	Apply(Options) (Options, error)
}

Mixin allows to compose functions that process task options.

type Options

type Options interface{}

Options is a generic representation for task options.

type Runner

type Runner interface {
	// Handles returns the supported task kind.
	Handles() Kind

	// Run runs a command.
	Run(Task) error

	// RunOut runs a command and returns its output.
	RunOut(Task) (string, error)

	// Validate validates the runner.
	Validate() error
}

Runner runs a command with parameters in a specific environment.

type RunnerExec

type RunnerExec interface {
	Runner

	// FilePath returns the path to the (binary) command executable.
	FilePath() string
}

RunnerExec is a runner for a (binary) command executable.

type Task

type Task interface {
	// Kind returns the task kind.
	Kind() Kind

	// Name returns the task name.
	Name() string

	// Options returns the task options.
	Options() Options
}

Task is a wand task for Mage.

See https://magefile.org/targets for more details about Mage targets.

Directories

Path Synopsis
fs
clean
Package clean provides a task to remove filesystem paths, e.g.
Package clean provides a task to remove filesystem paths, e.g.
Package gofumpt provides a task for the "mvdan.cc/gofumpt" Go module command.
Package gofumpt provides a task for the "mvdan.cc/gofumpt" Go module command.
Package goimports provides a task for the "golang.org/x/tools/cmd/goimports" Go module command.
Package goimports provides a task for the "golang.org/x/tools/cmd/goimports" Go module command.
Package golang provides Go toolchain tasks and runner.
Package golang provides Go toolchain tasks and runner.
build
Package build provides a task for the Go toolchain "build" command.
Package build provides a task for the Go toolchain "build" command.
env
Package env provides a task for the Go toolchain `env` command.
Package env provides a task for the Go toolchain `env` command.
install
Package install provides a task for the Go toolchain "install" command.
Package install provides a task for the Go toolchain "install" command.
test
Package test provides a task for the Go toolchain "test" command.
Package test provides a task for the Go toolchain "test" command.
Package golangcilint provides a task for the "github.com/golangci/golangci-lint/cmd/golangci-lint" Go module command.
Package golangcilint provides a task for the "github.com/golangci/golangci-lint/cmd/golangci-lint" Go module command.
Package gomodupgrade provides a task for the "github.com/oligot/go-mod-upgrade" Go module command.
Package gomodupgrade provides a task for the "github.com/oligot/go-mod-upgrade" Go module command.
Package gotool provides a runner to install and run compiled executables of Go module-based "main" packages.
Package gotool provides a runner to install and run compiled executables of Go module-based "main" packages.
Package gox provides a task for the github.com/mitchellh/gox Go module command.
Package gox provides a task for the github.com/mitchellh/gox Go module command.

Jump to

Keyboard shortcuts

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