matr

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "v0.2.0"

Functions

func Arg

func Arg(ctx context.Context, idx int, defaultStr string) (string, bool)

Arg returns the handler arg at the given position from the context

func Args

func Args(ctx context.Context) []string

Args returns the handler args from the context

func Deps

func Deps(ctx context.Context, fns ...HandlerFunc) error

Deps is a helper function to run the given dependent handlers

func Run

func Run()

Run is the primary entrypoint to matrs cli tool. This is where the matrfile path is resolved, compiled and executed

Types

type Cmd

type Cmd struct {
	*exec.Cmd
}

func Sh

func Sh(cmdStr string, args ...interface{}) *Cmd

Sh is a helper function for executing shell commands

type ContextKey

type ContextKey string

ContextKey is used to identify matr values in the context

type HandlerFunc

type HandlerFunc func(c context.Context, args []string) error

The HandlerFunc type is an adapter to allow the use of ordinary functions as a matr task Handler.

type Matr

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

Matr is the root structure

func New

func New() *Matr

New creates a new Matr struct instance and returns a point to it

func (*Matr) Handle

func (m *Matr) Handle(task *Task)

Handle registers a new task handler with matr. The Handler will then be referenceable by the provided name, if a task is named "default" or "" that function will be called if no function name is provided. The default function is also a good place to output usage information for the available tasks. CallOptions can be used to allow for before and after Handler middleware functions.

func (*Matr) OnExit

func (m *Matr) OnExit(fn func(ctx context.Context, err error))

OnExit executes a final function before matr exits

func (*Matr) PrintUsage

func (m *Matr) PrintUsage(cmd string)

PrintUsage is a helper function to output the usage docs to stdout

func (*Matr) Run

func (m *Matr) Run(ctx context.Context, args ...string) error

Run will execute the requested task function with the provided context and arguments.

func (*Matr) TaskNames

func (m *Matr) TaskNames() []string

TaskNames returns a silce of the available task names

type Task

type Task struct {
	Name    string
	Summary string
	Doc     string
	Handler HandlerFunc
}

Task struct that holds registered handler

Jump to

Keyboard shortcuts

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