Taskwarrior:如何找到依赖于特定任务的任务?

Taskwarrior: How do I find the tasks that depend on a specific tasks?

如何在不读取所有任务信息的情况下找出哪些任务依赖于特定任务?

复制

系统

版本

$ task --version
2.5.1

.taskrc

# Taskwarrior program configuration file.

# Files
data.location=~/.task

alias.cal=calendar
rc.date.iso=Y-M-D

default.command=ready
journal.info=no
rc.regex=on

以下是我为测试目的创建的任务:

$ task list

ID Age  Description                           Urg 
 1 2min Something to do                          0
 2 1min first do this                            0
 3 1min do this whenever you feel like it        0

3 tasks

创建从任务#1 到任务#2 的依赖关系:

$ task 1 modify depends:2
Modifying task 1 'something to do'.
Modified 1 task.

$ task list

ID Age  D Description                           Urg 
 2 4min   first do this                            8
 3 4min   do this whenever you feel like it        0
 1 4min D Something to do                         -5

3 tasks

目标

现在我想找到依赖于任务#2 的任务,应该是任务#1。

试炼

不幸的是,这不会导致任何匹配:

$ task list depends:2
No matches.
$ # I can filter by blocked tasks
$ task blocked

ID Deps Age   Description    
 1 2    18min Something to do

1 task

$ # But when I want to only have tasks \
    that are blocked by task#2 also task#3 is returned
$ task blocked:2
[task ready ( blocked:2 )]

ID Age   Description                       Urg 
 2 20min first do this                        8
 3 19min do this whenever you feel like it    0

2 tasks

建议?

你会如何处理这个问题? 通过脚本解析 taskwarrior 输出看起来有点矫枉过正。

您可以使用这个 taskwarrior 钩子脚本,为任务添加“块”属性:https://gist.github.com/wbsch/a2f7264c6302918dfb30

您的命令正确,但实际上遇到了 bugdepends 属性不适用于“短 ID”。

如果您改为使用 UUID,它将起作用。使用 task <id> _uuid 将 id 解析为 UUID。

$ task --version
2.5.1

# Create tasks
$ task rc.data.location: add -- Something to do
$ task rc.data.location: add -- first do this
$ task rc.data.location: add -- do this whenever you feel like it
$ task rc.data.location: list

ID Age Description                           Urg
 1 -   Something to do                        1.8
 2 -   first do this                          1.8
 3 -   do this whenever you feel like it      1.8
3 tasks

# Set up dependency
$ task rc.data.location: 1 modify depends:2

Modifying task 1 'Something to do'.
Modified 1 task.

# Query using depends:UUID
$ task rc.data.location: list "depends:$(task rc.data.location: _get 2.uuid)"

ID Age D Description         Urg
 1 -   D Something to do     -3.2

1 task

# Query using depends:SHORT ID
# This does not work, despite documentation. Likely a bug
$ task rc.data.location: list "depends:$(task rc.data.location: _get 2.id)"

No matches.

对您的试用进行小修正以查找被阻止的任务

没有 blocked 属性,您正在使用 ready 报告。

$ task blocked:2
[task ready ( blocked:2 )]

ready报告会过滤掉我们要找的东西,blocked报告就是我们需要的。为了消除这一点,这些只是有用的默认报告,在 task all.

之上具有预设过滤器
$ task show filter | grep -e 'blocked' -e 'ready'                                                                                                                                                                                                                                             
report.blocked.filter   status:pending +BLOCKED
report.ready.filter     +READY
report.unblocked.filter status:pending -BLOCKED

被阻止的任务将具有虚拟标签 +BLOCKED,它与 +READY.

互斥

blocked 属性不存在,请使用 task _columns 显示可用属性(例如 depends)。不幸的是,CLI 解析器可能正在尝试应用过滤器 blocked:2 并最终忽略它。对于您的工作流程,有用的命令是 task blocked "depends:$(task _get 2.uuid)"。建议写一个shell函数,方便使用:

#!/bin/bash
# Untested but gets the point across
function task_blocked {
  blocker=
  shift
  task blocked depends:$(task _get ${blocker}.uuid) "$@"
}

# Find tasks of project "foo" that are blocked on task 2
task_blocked 2 project:foo
# What about other project that is also impacted
task_blocked 2 project:bar