spell

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package spell provides incantations for different kinds.

Index

Constants

View Source
const (
	// KindNameBinary is the Kind name for binary spells.
	KindNameBinary = "binary"
	// KindNameGoCode is the Kind name for Go code spells.
	KindNameGoCode = "go.code"
	// KindNameGoModule is the Kind name for Go module spells.
	KindNameGoModule = "go.module"
	// KindNameUnknown is the name for a unknown spell Kind.
	KindNameUnknown = "unknown"
)
View Source
const (
	// ErrExec indicates that a GoCode spell incantation returned an error during the code execution.
	ErrExec = wErr.ErrString("error returned during execution")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Binary

type Binary interface {
	Incantation

	// Env returns additional environment variables.
	Env() map[string]string
}

Binary is a Incantation for commands which are using a binary executable.

type ErrGoCode

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

ErrGoCode represents a GoCode error.

func (*ErrGoCode) Error

func (e *ErrGoCode) Error() string

func (*ErrGoCode) Is

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

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

func (*ErrGoCode) Unwrap

func (e *ErrGoCode) Unwrap() error

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

type GoCode

type GoCode interface {
	Incantation

	// Cast casts itself.
	Cast() (interface{}, error)
}

GoCode is a Incantation for actions that can be casted without a cast.Caster. It is a special incantations in that it allows to use Go code as spell while still being compatible to the incantation API. Note that the Incantation.Formula of a GoCode must always return an empty slice, otherwise it is a "normal" Incantation that requires a cast.Caster.

Seen from the abstract "Harry Potter" view this is equal to a "non-verbal" spell that is a special technique that can be used for spells that have been specially designed to be used non-verbally.

References

(1) https://en.wikipedia.org/wiki/Magic_in_Harry_Potter#Spellcasting
(2) https://www.reddit.com/r/harrypotter/comments/4z9rwl/what_is_the_difference_between_a_spell_charm

type GoModule

type GoModule interface {
	Binary

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

GoModule is a Binary for binary command executables managed by a Go module.

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

type Incantation

type Incantation interface {
	// Formula returns all parameters of a spell.
	Formula() []string

	// Kind returns the Kind of a spell.
	Kind() Kind

	// Options returns the options of a spell.
	Options() interface{}
}

Incantation is the abstract representation of flags and parameters for a command or action. It is mainly handled by a cast.Caster that provides the corresponding information about the command like the path to the executable.

The separation of parameters from commands enables a flexible usage, e.g. when the parameters can be reused for a different command.

The abstract view and naming is inspired by the fantasy novel "Harry Potter" in which it is almost only possible to cast a magic spell through a incantation.

References

(1) https://en.wikipedia.org/wiki/Incantation
(2) https://en.wikipedia.org/wiki/Magic_in_Harry_Potter#Spellcasting
(3) https://scifi.stackexchange.com/a/33234
(4) https://harrypotter.fandom.com/wiki/Spell
(5) https://diffsense.com/diff/incantation/spell

type Kind

type Kind uint32

Kind defines the kind of a spell.

const (
	// KindBinary is the Kind for binary spells.
	KindBinary Kind = iota
	// KindGoCode is the Kind for Go code spells.
	KindGoCode
	// KindGoModule is the Kind for Go module spells.
	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 generic Options to spell incantation options.
	Apply(Options) (Options, error)
}

Mixin allows to compose functions that process Options of spell incantations.

type Options

type Options interface{}

Options is a generic representation for spell incantation options.

Directories

Path Synopsis
fs
clean
Package clean provides a spell incantation to remove directories in a filesystem.
Package clean provides a spell incantation to remove directories in a filesystem.
Package goimports provides a spell incantation for the "golang.org/x/tools/cmd/goimports" Go module command that allows to update Go import lines, add missing ones and remove unreferenced ones.
Package goimports provides a spell incantation for the "golang.org/x/tools/cmd/goimports" Go module command that allows to update Go import lines, add missing ones and remove unreferenced ones.
Package golang provides spell incantations for Go toolchain commands.
Package golang provides spell incantations for Go toolchain commands.
build
Package build provides a spell incantation for the "build" command of the Go toolchain.
Package build provides a spell incantation for the "build" command of the Go toolchain.
test
Package test provide a spell incantation for the "test" command of the Go toolchain.
Package test provide a spell incantation for the "test" command of the Go toolchain.
Package golangcilint provides a spell incantation for the "github.com/golangci/golangci-lint/cmd/golangci-lint" Go module command, a fast, parallel runner for dozens of Go linters that uses caching, supports YAML configurations and has integrations with all major IDEs.
Package golangcilint provides a spell incantation for the "github.com/golangci/golangci-lint/cmd/golangci-lint" Go module command, a fast, parallel runner for dozens of Go linters that uses caching, supports YAML configurations and has integrations with all major IDEs.
Package gox provides a spell incantation for the "github.com/mitchellh/gox" Go module command, a dead simple, no frills Go cross compile tool that behaves a lot like the standard Go toolchain "build" command.
Package gox provides a spell incantation for the "github.com/mitchellh/gox" Go module command, a dead simple, no frills Go cross compile tool that behaves a lot like the standard Go toolchain "build" command.

Jump to

Keyboard shortcuts

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