task

package
v0.18.3 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: BSD-2-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const DateFormat = "20060102T150405Z"

DateFormat is the date format used by Taskwarrior in all date fields (e.g. Entry, Due, Start). All date parsing and formatting in this package uses this constant.

Variables

This section is empty.

Functions

func Add

func Add(description string, tags []string) error

Add creates a new task with the given description and tags.

func AddArgs

func AddArgs(args []string) error

AddArgs runs "task add" with the provided arguments. Each element in args is passed as a separate command-line argument, allowing the caller to specify additional modifiers like due dates or tags.

func AddArgsContext added in v0.18.1

func AddArgsContext(ctx context.Context, args []string) error

AddArgsContext runs "task add" with the provided arguments using ctx for the underlying Taskwarrior command.

func AddContext added in v0.18.1

func AddContext(ctx context.Context, description string, tags []string) error

AddContext creates a new task with the given description and tags using ctx for the underlying Taskwarrior command.

func AddLine

func AddLine(line string) error

AddLine splits the given line into shell words and runs "task add" with the resulting arguments. This allows users to pass raw Taskwarrior parameters such as "due:today" directly.

func AddLineContext added in v0.18.1

func AddLineContext(ctx context.Context, line string) error

AddLineContext splits the given line into shell words and runs "task add" with the resulting arguments using ctx for the underlying Taskwarrior command.

func AddTags

func AddTags(id int, tags []string) error

AddTags adds tags to the task with the given id.

func AddTagsContext added in v0.18.1

func AddTagsContext(ctx context.Context, id int, tags []string) error

AddTagsContext adds tags to the task with the given id using ctx for the underlying Taskwarrior command.

func Annotate

func Annotate(id int, text string) error

Annotate adds an annotation to the task with the given id.

func AnnotateContext added in v0.18.1

func AnnotateContext(ctx context.Context, id int, text string) error

AnnotateContext adds an annotation to the task with the given id using ctx for the underlying Taskwarrior command.

func Delete

func Delete(id int) error

Delete removes the task with the given id.

func DeleteContext added in v0.18.1

func DeleteContext(ctx context.Context, id int) error

DeleteContext removes the task with the given id using ctx for the underlying Taskwarrior command.

func Denotate

func Denotate(id int, text string) error

Denotate removes an annotation from the task with the given id. Denotate removes an annotation from the task with the given id. The annotation text is matched exactly when provided. If text is empty, the oldest annotation is removed.

func DenotateContext added in v0.18.1

func DenotateContext(ctx context.Context, id int, text string) error

DenotateContext removes an annotation from the task with the given id using ctx for the underlying Taskwarrior command.

func Done

func Done(id int) error

Done marks the task with the given id as completed.

func DoneContext added in v0.18.1

func DoneContext(ctx context.Context, id int) error

DoneContext marks the task with the given id as completed using ctx for the underlying Taskwarrior command.

func DueTasks

func DueTasks(tasks []Task, now time.Time) int

DueTasks returns the number of tasks with a due date that is not in the future.

func Edit

func Edit(id int) error

Edit opens the task in an editor for manual modification. This is a convenience wrapper around EditCmd.

func EditCmd

func EditCmd(id int) *exec.Cmd

Edit opens the task in an editor for manual modification. EditCmd returns an exec.Cmd that edits the task with the given id. The caller is responsible for running the command, typically via tea.ExecProcess so that the terminal state is properly managed.

func InProgressTasks

func InProgressTasks(tasks []Task) int

InProgressTasks returns the number of tasks that have been started and are not completed.

func RemoveTags

func RemoveTags(id int, tags []string) error

RemoveTags removes tags from the task with the given id.

func RemoveTagsContext added in v0.18.1

func RemoveTagsContext(ctx context.Context, id int, tags []string) error

RemoveTagsContext removes tags from the task with the given id using ctx for the underlying Taskwarrior command.

func ReplaceAnnotations

func ReplaceAnnotations(ctx context.Context, id int, text string) error

ReplaceAnnotations removes all existing annotations from the task with the given id and sets a single annotation with the provided text. If text is empty, all annotations are simply removed.

func SetDebugLog

func SetDebugLog(path string) error

SetDebugLog enables logging of executed commands to the given file. Passing an empty path disables logging and closes any previously opened file.

func SetDescription

func SetDescription(id int, desc string) error

SetDescription changes the description of the task with the given id.

func SetDescriptionContext added in v0.18.1

func SetDescriptionContext(ctx context.Context, id int, desc string) error

SetDescriptionContext changes the description of the task with the given id using ctx for the underlying Taskwarrior command.

func SetDueDate

func SetDueDate(id int, due string) error

SetDueDate sets the due date for the task with the given id.

func SetDueDateContext added in v0.18.1

func SetDueDateContext(ctx context.Context, id int, due string) error

SetDueDateContext sets the due date for the task with the given id using ctx for the underlying Taskwarrior command.

func SetPriority

func SetPriority(id int, priority string) error

SetPriority changes the priority of the task with the given id.

func SetPriorityContext added in v0.18.1

func SetPriorityContext(ctx context.Context, id int, priority string) error

SetPriorityContext changes the priority of the task with the given id using ctx for the underlying Taskwarrior command.

func SetProject added in v0.9.2

func SetProject(id int, project string) error

SetProject changes the project of the task with the given id.

func SetProjectContext added in v0.18.1

func SetProjectContext(ctx context.Context, id int, project string) error

SetProjectContext changes the project of the task with the given id using ctx for the underlying Taskwarrior command.

func SetRecurrence

func SetRecurrence(id int, rec string) error

SetRecurrence sets the recurrence for the task with the given id.

func SetRecurrenceContext added in v0.18.1

func SetRecurrenceContext(ctx context.Context, id int, rec string) error

SetRecurrenceContext sets the recurrence for the task with the given id using ctx for the underlying Taskwarrior command.

func SetRecurringSeriesRecurrenceContext added in v0.18.1

func SetRecurringSeriesRecurrenceContext(ctx context.Context, rootUUID, rec string) error

SetRecurringSeriesRecurrenceContext sets the recurrence for every known task in a recurring series identified by rootUUID.

func SetStatus

func SetStatus(id int, status string) error

SetStatus changes the status of the task with the given id.

func SetStatusContext added in v0.18.1

func SetStatusContext(ctx context.Context, id int, status string) error

SetStatusContext changes the status of the task with the given id using ctx for the underlying Taskwarrior command.

func SetStatusUUID

func SetStatusUUID(uuid, status string) error

SetStatusUUID changes the status of the task with the given UUID.

func SetStatusUUIDContext added in v0.18.1

func SetStatusUUIDContext(ctx context.Context, uuid, status string) error

SetStatusUUIDContext changes the status of the task with the given UUID using ctx for the underlying Taskwarrior command.

func SetTags

func SetTags(ctx context.Context, id int, tags []string) error

SetTags sets the tags of the task with the given id to exactly the provided set. Tags not present will be removed and new tags added as needed.

func SortTasks

func SortTasks(tasks []Task)

SortTasks orders tasks by start status, priority, due date, tag names and id. Started tasks are always placed before non-started ones. Tasks without a due date are placed after tasks with a due date. Overdue tasks are placed at the very top regardless of other properties.

The sort order is: 1. Overdue tasks (oldest due date first) 2. Started tasks (not completed) 3. High priority tasks 4. Tasks with earlier due dates 5. Tasks sorted alphabetically by tags 6. Tasks sorted by ID (oldest first)

func Start

func Start(id int) error

Start begins the task with the given id.

func StartContext added in v0.18.1

func StartContext(ctx context.Context, id int) error

StartContext begins the task with the given id using ctx for the underlying Taskwarrior command.

func Stop

func Stop(id int) error

Stop stops the task with the given id.

func StopContext added in v0.18.1

func StopContext(ctx context.Context, id int) error

StopContext stops the task with the given id using ctx for the underlying Taskwarrior command.

func TotalTasks

func TotalTasks(tasks []Task) int

TotalTasks returns the number of tasks provided.

Types

type Annotation

type Annotation struct {
	Entry       string `json:"entry"`
	Description string `json:"description"`
}

Task represents a taskwarrior task as returned by `task export`.

type Client added in v0.18.1

type Client struct{}

Client is the production Taskwarrior implementation backed by the task CLI.

func NewTaskwarrior added in v0.18.1

func NewTaskwarrior() Client

NewTaskwarrior returns a production Taskwarrior Client.

func (Client) AddLineContext added in v0.18.1

func (Client) AddLineContext(ctx context.Context, line string) error

AddLineContext adds a task from a shell-style input line.

func (Client) AddTagsContext added in v0.18.1

func (Client) AddTagsContext(ctx context.Context, id int, tags []string) error

AddTagsContext adds tags to a task.

func (Client) AnnotateContext added in v0.18.1

func (Client) AnnotateContext(ctx context.Context, id int, text string) error

AnnotateContext adds an annotation to a task.

func (Client) DoneContext added in v0.18.1

func (Client) DoneContext(ctx context.Context, id int) error

DoneContext completes a task.

func (Client) DueTasks added in v0.18.1

func (Client) DueTasks(tasks []Task, now time.Time) int

DueTasks returns the number of due tasks.

func (Client) EditCmd added in v0.18.1

func (Client) EditCmd(id int) *exec.Cmd

EditCmd returns an editor command for a task.

func (Client) Export added in v0.18.1

func (Client) Export(ctx context.Context, filters ...string) ([]Task, error)

Export retrieves tasks using Taskwarrior export.

func (Client) InProgressTasks added in v0.18.1

func (Client) InProgressTasks(tasks []Task) int

InProgressTasks returns the number of started, incomplete tasks.

func (Client) LoadCompletionSources added in v0.18.1

func (Client) LoadCompletionSources(ctx context.Context) CompletionSources

LoadCompletionSources returns Taskwarrior-provided completion candidates.

func (Client) RecurringSeries added in v0.18.1

func (Client) RecurringSeries(ctx context.Context, rootUUID string) ([]Task, error)

RecurringSeries returns a recurring task series.

func (Client) RemoveTagsContext added in v0.18.1

func (Client) RemoveTagsContext(ctx context.Context, id int, tags []string) error

RemoveTagsContext removes tags from a task.

func (Client) ReplaceAnnotations added in v0.18.1

func (Client) ReplaceAnnotations(ctx context.Context, id int, text string) error

ReplaceAnnotations replaces all annotations on a task.

func (Client) RunShellLine added in v0.18.1

func (Client) RunShellLine(ctx context.Context, line string) (RunResult, error)

RunShellLine runs a user-entered Taskwarrior shell command.

func (Client) SetDescriptionContext added in v0.18.1

func (Client) SetDescriptionContext(ctx context.Context, id int, desc string) error

SetDescriptionContext changes a task description.

func (Client) SetDueDateContext added in v0.18.1

func (Client) SetDueDateContext(ctx context.Context, id int, due string) error

SetDueDateContext changes a task due date.

func (Client) SetPriorityContext added in v0.18.1

func (Client) SetPriorityContext(ctx context.Context, id int, priority string) error

SetPriorityContext changes a task priority.

func (Client) SetProjectContext added in v0.18.1

func (Client) SetProjectContext(ctx context.Context, id int, project string) error

SetProjectContext changes a task project.

func (Client) SetRecurrenceContext added in v0.18.1

func (Client) SetRecurrenceContext(ctx context.Context, id int, rec string) error

SetRecurrenceContext changes a task recurrence value.

func (Client) SetRecurringSeriesRecurrenceContext added in v0.18.1

func (Client) SetRecurringSeriesRecurrenceContext(ctx context.Context, rootUUID, rec string) error

SetRecurringSeriesRecurrenceContext changes a recurring series recurrence value.

func (Client) SetStatusUUIDContext added in v0.18.1

func (Client) SetStatusUUIDContext(ctx context.Context, uuid, status string) error

SetStatusUUIDContext changes a task status by UUID.

func (Client) SortTasks added in v0.18.1

func (Client) SortTasks(tasks []Task)

SortTasks orders tasks using TaskSamurai's default task ordering.

func (Client) StartContext added in v0.18.1

func (Client) StartContext(ctx context.Context, id int) error

StartContext starts a task.

func (Client) StopContext added in v0.18.1

func (Client) StopContext(ctx context.Context, id int) error

StopContext stops a task.

func (Client) TotalTasks added in v0.18.1

func (Client) TotalTasks(tasks []Task) int

TotalTasks returns the number of tasks provided.

type CompletionSources added in v0.18.0

type CompletionSources struct {
	Commands []string
	Columns  []string
	Projects []string
	Tags     []string
	IDs      []string
	UUIDs    []string
	UDAs     []string
}

CompletionSources contains values used for Taskwarrior shell completion.

func LoadCompletionSources added in v0.18.0

func LoadCompletionSources(ctx context.Context) CompletionSources

LoadCompletionSources returns Taskwarrior-provided completion candidates.

type RunResult added in v0.18.0

type RunResult struct {
	Args   []string
	Stdout string
	Stderr string
}

RunResult contains the captured output from a task command invocation.

func RunArgs added in v0.18.0

func RunArgs(ctx context.Context, args []string) (RunResult, error)

RunArgs runs "task" with args and captures stdout and stderr.

func RunLine added in v0.18.0

func RunLine(ctx context.Context, line string) (RunResult, error)

RunLine splits line using shell-word rules and runs the resulting task arguments. A leading "task" token is ignored so callers may accept either "add foo" or "task add foo" from user input.

func RunShellLine added in v0.18.0

func RunShellLine(ctx context.Context, line string) (RunResult, error)

RunShellLine runs a user-entered task command in non-interactive mode. It avoids Taskwarrior's recurring-task prompt by applying the same behavior as answering "no": modify only the addressed recurrence.

type Task

type Task struct {
	ID          int          `json:"id"`
	UUID        string       `json:"uuid"`
	Description string       `json:"description"`
	Project     string       `json:"project"`
	Tags        []string     `json:"tags"`
	Status      string       `json:"status"`
	Start       string       `json:"start"`
	Entry       string       `json:"entry"`
	Due         string       `json:"due"`
	Priority    string       `json:"priority"`
	Recur       string       `json:"recur"`
	Parent      string       `json:"parent"`
	RType       string       `json:"rtype"`
	Urgency     float64      `json:"urgency"`
	Annotations []Annotation `json:"annotations"`
}

func Export

func Export(ctx context.Context, filters ...string) ([]Task, error)

Export retrieves tasks using `task <filter> export rc.json.array=off` and parses the JSON output into a slice of Task structs. Optional filter arguments are passed directly to the `task` command before `export`.

func RecurringSeries added in v0.18.0

func RecurringSeries(ctx context.Context, rootUUID string) ([]Task, error)

RecurringSeries returns the recurring template and generated instances for the recurring task identified by rootUUID.

type Taskwarrior added in v0.18.1

type Taskwarrior interface {
	Export(ctx context.Context, filters ...string) ([]Task, error)
	SortTasks(tasks []Task)
	TotalTasks(tasks []Task) int
	InProgressTasks(tasks []Task) int
	DueTasks(tasks []Task, now time.Time) int
	EditCmd(id int) *exec.Cmd
	RunShellLine(ctx context.Context, line string) (RunResult, error)
	LoadCompletionSources(ctx context.Context) CompletionSources
	AddLineContext(ctx context.Context, line string) error
	AnnotateContext(ctx context.Context, id int, text string) error
	ReplaceAnnotations(ctx context.Context, id int, text string) error
	SetDescriptionContext(ctx context.Context, id int, desc string) error
	AddTagsContext(ctx context.Context, id int, tags []string) error
	RemoveTagsContext(ctx context.Context, id int, tags []string) error
	SetDueDateContext(ctx context.Context, id int, due string) error
	SetRecurrenceContext(ctx context.Context, id int, rec string) error
	SetRecurringSeriesRecurrenceContext(ctx context.Context, rootUUID, rec string) error
	SetProjectContext(ctx context.Context, id int, project string) error
	SetPriorityContext(ctx context.Context, id int, priority string) error
	StartContext(ctx context.Context, id int) error
	StopContext(ctx context.Context, id int) error
	DoneContext(ctx context.Context, id int) error
	SetStatusUUIDContext(ctx context.Context, uuid, status string) error
	RecurringSeries(ctx context.Context, rootUUID string) ([]Task, error)
}

Taskwarrior describes the Taskwarrior operations required by the UI.

Jump to

Keyboard shortcuts

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