glistr

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2022 License: MIT Imports: 4 Imported by: 0

README

glistr

Go Reference

Like Listr, but for go

glistr is a package designed to emulate Listr in go.

For example:

package main

func main() {
	tl := glistr.NewTaskList(
		glistr.Task{
			Name: "Task",
			Exec: func(ctx *glistr.Context) error {
				time.Sleep(time.Second * 2) // do stuff here!
				return nil
			},
		}
	)

	tl.Run()
}

Each task has a name, and a function that takes in a *glistr.Context and returns an error.

glistr also provides functions for stopping, failing, and skipping tasks, as well as updating their current displayed action.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

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

Context provides a way to pass data about what the task is doing to the tasklist.

func (*Context) Fail

func (c *Context) Fail(err error)

Fail stops the task where it is currently at, and panics on an error.

func (*Context) SetCurrentAction

func (c *Context) SetCurrentAction(action string)

SetCurrentAction sets the current action/message (as the Message parameter in the config) to be displayed by the spinner.

func (*Context) Skip

func (c *Context) Skip(reason string)

Skip skips the task where it is currently at.

func (*Context) Stop

func (c *Context) Stop()

Stop stops the task where it is currently at. It does this by panicing on a nil error, so it reports as done.

type Task

type Task struct {
	Name string
	Exec func(*Context) error
}

Task is a task to be done. Tasks have a name, and a function to execute. This function returns an error if it fails. Otherwise, it returns nil.

type TaskList

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

func NewTaskList

func NewTaskList(tasks ...Task) *TaskList

NewTaskList creates a new TaskList.

func (*TaskList) Run

func (t *TaskList) Run() error

Run runs the tasklist.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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