task

package module
v3.47.7 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2026 License: MIT Imports: 45 Imported by: 0

README ΒΆ

πŸš€ Quick Start

Get started with Taskr in just a few commands:

install via brew
brew tap vikbert/taskr
brew install taskr
install via go
go install github.com/vikbert/taskr/v3/cmd/taskr@latest
install via shell
sh -c "$(curl --location https://taskr-io.vercel.app/install.sh)" -- -d
install via binary
open https://github.com/vikbert/taskr/releases

πŸ‘‰ Create a Taskfile.yml

Getting started from this article.

You can fix the schema validation issue in IDE by add this line in Taskfile.yml, if you want to keep both task and taskr in use.

# yaml-language-server: $schema=https://taskr-io.vercel.app/schema.json
version: "3"

just add the declaration of yaml-language-server on the top of your Taskfile.yml

πŸ› οΈ Development

git clone https://github.com/vikbert/taskr.git
cd taskr
go install github.com/vikbert/taskr/v3/cmd/taskr@latest

# Download dependencies
taskr mod

# Install development tools
taskr install:mockery
taskr gotestsum:install

# you can do force-installation after your changes in source code
taskr reinstall

🎯 Key Enhancements

  • βœ… Performance Optimization - Pre-allocated capacity, fast paths, 30% improvement for large project lists
  • βœ… New Category - Categorize the related tasks by using category
  • βœ… New Index - Order the tasks by index
  • βœ… New banner printing - Print project name as project banner

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (
	DefaultTaskGroup = "General"
	MinColumnWidth   = 4
	TabWidth         = 8
	TabPadding       = 2
)

Constants for task listing

View Source
const (
	// MaximumTaskCall is the max number of times a task can be called.
	// This exists to prevent infinite loops on cyclic dependencies
	MaximumTaskCall = 1000
)

Variables ΒΆ

View Source
var DefaultTaskfile string
View Source
var ErrPreconditionFailed = errors.New("task: precondition not met")

ErrPreconditionFailed is returned when a precondition fails

Functions ΒΆ

func Completion ΒΆ

func Completion(completion string) (string, error)

func FilterOutInternal ΒΆ

func FilterOutInternal(task *ast.Task) bool

FilterOutInternal removes all tasks that are marked as internal.

func FilterOutNoDesc ΒΆ

func FilterOutNoDesc(task *ast.Task) bool

FilterOutNoDesc removes all tasks that do not contain a description.

func InitTaskfile ΒΆ

func InitTaskfile(path string) (string, error)

InitTaskfile creates a new Taskfile at path.

path can be either a file path or a directory path. If path is a directory, path/Taskfile.yml will be created.

The final file path is always returned and may be different from the input path.

func ShouldIgnore ΒΆ

func ShouldIgnore(path string) bool

Types ΒΆ

type Call ΒΆ

type Call struct {
	Task     string
	Vars     *ast.Vars
	Silent   bool
	Indirect bool // True if the task was called by another task
}

Call is the parameters to a task call

type Compiler ΒΆ

type Compiler struct {
	Dir            string
	Entrypoint     string
	UserWorkingDir string

	TaskfileEnv  *ast.Vars
	TaskfileVars *ast.Vars

	Logger *logger.Logger
	// contains filtered or unexported fields
}

func (*Compiler) FastGetVariables ΒΆ

func (c *Compiler) FastGetVariables(t *ast.Task, call *Call) (*ast.Vars, error)

func (*Compiler) GetTaskfileVariables ΒΆ

func (c *Compiler) GetTaskfileVariables() (*ast.Vars, error)

func (*Compiler) GetVariables ΒΆ

func (c *Compiler) GetVariables(t *ast.Task, call *Call) (*ast.Vars, error)

func (*Compiler) HandleDynamicVar ΒΆ

func (c *Compiler) HandleDynamicVar(v ast.Var, dir string, e []string) (string, error)

func (*Compiler) ResetCache ΒΆ

func (c *Compiler) ResetCache()

ResetCache clear the dynamic variables cache

type Executor ΒΆ

type Executor struct {
	// Flags
	Dir                 string
	Entrypoint          string
	TempDir             TempDir
	Force               bool
	ForceAll            bool
	Insecure            bool
	Download            bool
	Offline             bool
	TrustedHosts        []string
	Timeout             time.Duration
	CacheExpiryDuration time.Duration
	RemoteCacheDir      string
	Watch               bool
	Verbose             bool
	Silent              bool
	DisableFuzzy        bool
	AssumeYes           bool
	AssumeTerm          bool // Used for testing
	Dry                 bool
	Summary             bool
	Parallel            bool
	Color               bool
	Concurrency         int
	Interval            time.Duration
	Failfast            bool

	// I/O
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer

	// Internal
	Taskfile           *ast.Taskfile
	Logger             *logger.Logger
	Compiler           *Compiler
	Output             output.Output
	OutputStyle        ast.Output
	TaskSorter         sort.Sorter
	UserWorkingDir     string
	EnableVersionCheck bool
	// contains filtered or unexported fields
}

An Executor is used for processing Taskfile(s) and executing the task(s) within them.

func NewExecutor ΒΆ

func NewExecutor(opts ...ExecutorOption) *Executor

NewExecutor creates a new Executor and applies the given functional options to it.

func (*Executor) CompiledTask ΒΆ

func (e *Executor) CompiledTask(call *Call) (*ast.Task, error)

CompiledTask returns a copy of a task, but replacing variables in almost all properties using the Go template package.

func (*Executor) CompiledTaskForTaskList ΒΆ

func (e *Executor) CompiledTaskForTaskList(call *Call) (*ast.Task, error)

func (*Executor) FastCompiledTask ΒΆ

func (e *Executor) FastCompiledTask(call *Call) (*ast.Task, error)

FastCompiledTask is like CompiledTask, but it skippes dynamic variables.

func (*Executor) FindMatchingTasks ΒΆ

func (e *Executor) FindMatchingTasks(call *Call) []*MatchingTask

FindMatchingTasks returns a list of tasks that match the given call. A task matches a call if its name is equal to the call's task name or if it matches a wildcard pattern. The function returns a list of MatchingTask structs, each containing a task and a list of wildcards that were matched.

func (*Executor) GetHash ΒΆ

func (e *Executor) GetHash(t *ast.Task) (string, error)

func (*Executor) GetTask ΒΆ

func (e *Executor) GetTask(call *Call) (*ast.Task, error)

GetTask will return the task with the name matching the given call from the taskfile. If no task is found, it will search for tasks with a matching alias. If multiple tasks contain the same alias or no matches are found an error is returned.

func (*Executor) GetTaskList ΒΆ

func (e *Executor) GetTaskList(filters ...FilterFunc) ([]*ast.Task, error)

func (*Executor) InterceptInterruptSignals ΒΆ

func (e *Executor) InterceptInterruptSignals()

NOTE(@andreynering): This function intercepts SIGINT and SIGTERM signals so the Task process is not killed immediately and processes running have time to do cleanup work.

func (*Executor) ListTaskNames ΒΆ

func (e *Executor) ListTaskNames(allTasks bool) error

ListTaskNames prints only the task names in a Taskfile. Only tasks with a non-empty description are printed if allTasks is false. Otherwise, all task names are printed.

func (*Executor) ListTasks ΒΆ

func (e *Executor) ListTasks(o ListOptions) (bool, error)

ListTasks prints a list of tasks. Tasks that match the given filters will be excluded from the list. The function returns a boolean indicating whether tasks were found and an error if one was encountered while preparing the output.

func (*Executor) Options ΒΆ

func (e *Executor) Options(opts ...ExecutorOption)

Options loops through the given ExecutorOption functions and applies them to the Executor.

func (*Executor) Run ΒΆ

func (e *Executor) Run(ctx context.Context, calls ...*Call) error

Run runs Task

func (*Executor) RunTask ΒΆ

func (e *Executor) RunTask(ctx context.Context, call *Call) error

RunTask runs a task by its name

func (*Executor) Setup ΒΆ

func (e *Executor) Setup() error

func (*Executor) Status ΒΆ

func (e *Executor) Status(ctx context.Context, calls ...*Call) error

Status returns an error if any the of given tasks is not up-to-date

func (*Executor) ToEditorOutput ΒΆ

func (e *Executor) ToEditorOutput(tasks []*ast.Task, noStatus bool, nested bool) (*editors.Namespace, error)

ToEditorOutput converts tasks to editor-friendly format with optional status checking

type ExecutorOption ΒΆ

type ExecutorOption interface {
	ApplyToExecutor(*Executor)
}

An ExecutorOption is any type that can apply a configuration to an Executor.

func WithAssumeTerm ΒΆ

func WithAssumeTerm(assumeTerm bool) ExecutorOption

WithAssumeTerm is used for testing purposes to simulate a terminal.

func WithAssumeYes ΒΆ

func WithAssumeYes(assumeYes bool) ExecutorOption

WithAssumeYes tells the Executor to assume "yes" for all prompts.

func WithCacheExpiryDuration ΒΆ

func WithCacheExpiryDuration(duration time.Duration) ExecutorOption

WithCacheExpiryDuration sets the duration after which the cache is considered expired. By default, the cache is 0 (disabled).

func WithColor ΒΆ

func WithColor(color bool) ExecutorOption

WithColor tells the Executor whether or not to output using colorized strings.

func WithConcurrency ΒΆ

func WithConcurrency(concurrency int) ExecutorOption

WithConcurrency sets the maximum number of tasks that the Executor can run in parallel.

func WithDir ΒΆ

func WithDir(dir string) ExecutorOption

WithDir sets the working directory of the Executor. By default, the directory is set to the user's current working directory.

func WithDisableFuzzy ΒΆ

func WithDisableFuzzy(disableFuzzy bool) ExecutorOption

WithDisableFuzzy tells the Executor to disable fuzzy matching for task names.

func WithDownload ΒΆ

func WithDownload(download bool) ExecutorOption

WithDownload forces the Executor to download a fresh copy of the taskfile from the remote source.

func WithDry ΒΆ

func WithDry(dry bool) ExecutorOption

WithDry tells the Executor to output the commands that would be run without actually running them.

func WithEntrypoint ΒΆ

func WithEntrypoint(entrypoint string) ExecutorOption

WithEntrypoint sets the entrypoint (main Taskfile) of the Executor. By default, Task will search for one of the default Taskfiles in the given directory.

func WithFailfast ΒΆ

func WithFailfast(failfast bool) ExecutorOption

WithFailfast tells the Executor whether or not to check the version of

func WithForce ΒΆ

func WithForce(force bool) ExecutorOption

WithForce ensures that the Executor always runs a task, even when fingerprinting or prompts would normally stop it.

func WithForceAll ΒΆ

func WithForceAll(forceAll bool) ExecutorOption

WithForceAll ensures that the Executor always runs all tasks (including subtasks), even when fingerprinting or prompts would normally stop them.

func WithIO ΒΆ

func WithIO(rw io.ReadWriter) ExecutorOption

WithIO sets the Executor's standard input, output, and error to the same io.ReadWriter.

func WithInsecure ΒΆ

func WithInsecure(insecure bool) ExecutorOption

WithInsecure allows the Executor to make insecure connections when reading remote taskfiles. By default, insecure connections are rejected.

func WithInterval ΒΆ

func WithInterval(interval time.Duration) ExecutorOption

WithInterval sets the interval at which the Executor will wait for duplicated events before running a task.

func WithOffline ΒΆ

func WithOffline(offline bool) ExecutorOption

WithOffline stops the Executor from being able to make network connections. It will still be able to read local files and cached copies of remote files.

func WithOutputStyle ΒΆ

func WithOutputStyle(outputStyle ast.Output) ExecutorOption

WithOutputStyle sets the output style of the Executor. By default, the output style is set to the style defined in the Taskfile.

func WithParallel ΒΆ

func WithParallel(parallel bool) ExecutorOption

WithParallel tells the Executor to run tasks given in the same call in parallel.

func WithRemoteCacheDir ΒΆ

func WithRemoteCacheDir(dir string) ExecutorOption

WithRemoteCacheDir sets the directory where remote taskfiles are cached.

func WithSilent ΒΆ

func WithSilent(silent bool) ExecutorOption

WithSilent tells the Executor to suppress all output except for the output of the tasks that are run.

func WithStderr ΒΆ

func WithStderr(stderr io.Writer) ExecutorOption

WithStderr sets the Executor's standard error io.Writer.

func WithStdin ΒΆ

func WithStdin(stdin io.Reader) ExecutorOption

WithStdin sets the Executor's standard input io.Reader.

func WithStdout ΒΆ

func WithStdout(stdout io.Writer) ExecutorOption

WithStdout sets the Executor's standard output io.Writer.

func WithSummary ΒΆ

func WithSummary(summary bool) ExecutorOption

WithSummary tells the Executor to output a summary of the given tasks instead of running them.

func WithTaskSorter ΒΆ

func WithTaskSorter(sorter sort.Sorter) ExecutorOption

WithTaskSorter sets the sorter that the Executor will use to sort tasks. By default, the sorter is set to sort tasks alphabetically, but with tasks with no namespace (in the root Taskfile) first.

func WithTempDir ΒΆ

func WithTempDir(tempDir TempDir) ExecutorOption

WithTempDir sets the temporary directory that will be used by Executor for storing temporary files like checksums and cached remote files. By default, the temporary directory is set to the user's temporary directory.

func WithTimeout ΒΆ

func WithTimeout(timeout time.Duration) ExecutorOption

WithTimeout sets the Executor's timeout for fetching remote taskfiles. By default, the timeout is set to 10 seconds.

func WithTrustedHosts ΒΆ

func WithTrustedHosts(trustedHosts []string) ExecutorOption

WithTrustedHosts configures the Executor with a list of trusted hosts for remote Taskfiles. Hosts in this list will not prompt for user confirmation.

func WithVerbose ΒΆ

func WithVerbose(verbose bool) ExecutorOption

WithVerbose tells the Executor to output more information about the tasks that are run.

func WithVersionCheck ΒΆ

func WithVersionCheck(enableVersionCheck bool) ExecutorOption

WithVersionCheck tells the Executor whether or not to check the version of

func WithWatch ΒΆ

func WithWatch(watch bool) ExecutorOption

WithWatch tells the Executor to keep running in the background and watch for changes to the fingerprint of the tasks that are run. When changes are detected, a new task run is triggered.

type FilterFunc ΒΆ

type FilterFunc func(task *ast.Task) bool

type ListOptions ΒΆ

type ListOptions struct {
	ListOnlyTasksWithDescriptions bool
	ListAllTasks                  bool
	FormatTaskListAsJSON          bool
	NoStatus                      bool
	Nested                        bool
}

ListOptions collects list-related options

func NewListOptions ΒΆ

func NewListOptions(list, listAll, listAsJson, noStatus, nested bool) ListOptions

NewListOptions creates a new ListOptions instance

func (ListOptions) Filters ΒΆ

func (o ListOptions) Filters() []FilterFunc

Filters returns the slice of FilterFunc which filters a list of ast.Task according to the given ListOptions

func (ListOptions) ShouldListTasks ΒΆ

func (o ListOptions) ShouldListTasks() bool

ShouldListTasks returns true if one of the options to list tasks has been set to true

type MatchingTask ΒΆ

type MatchingTask struct {
	Task      *ast.Task
	Wildcards []string
}

MatchingTask represents a task that matches a given call. It includes the task itself and a list of wildcards that were matched.

type TempDir ΒΆ

type TempDir struct {
	Remote      string
	Fingerprint string
}

Jump to

Keyboard shortcuts

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