GothenburgBitFactory / GothenburgBitFactory/taskwarrior

Pass structured arguments to hooks

Open
#3,840 3 comments 0 reactions 0 assignees View on GitHub
topic:hooks
Dominant language
C++
Stars
6.1k
Forks
423
Avg merge
1d 19h
Merged PRs (30d)
11

Description

## Problem
Currently, hooks get various [metadata arguments](https://taskwarrior.org/docs/hooks2/) passed.
All of these are prefixed with their name, making this sort-of self describing.

This means that to use the version (e.g., in a version comparison), a hook would first need to strip the `api:` of the first argument.
This simply leads to unnecessary code, as the documentation already describes these arguments.
Worst of all though, the arguments can only a string type, which forces Taskwarrior for example to pass the original command line arguments as concatenated string instead of array of strings it actually got pass from the OS.

The last problem makes it difficult to further expand the API (e.g., according to my issue https://github.com/GothenburgBitFactory/taskwarrior/issues/3839).

## Proposed improvement
The task data is already passed as JSON attribute set via stdin, so I suggest also passing the metadata via a JSON attribute set.
Additionally, I think we should also continue passing the version as first argument, so that v2 hooks can detect that this is not v1 but v3.

Example JSON file (with newlines added for readability):
```json
{
"api":3,
"args": ["task", "rc.hooks.location:/tmp/c/hook_test", "add", "test"],
"command":"add",
"rc":"/home/user/.config/task/taskrc",
"data":"/home/user/.local/share/task",
"version":"3.4.1",
}
```

ref: https://github.com/GothenburgBitFactory/taskwarrior/issues/1912

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.