Skip to content

CLI Tasks Resource

CLITasksResource(cli)

Bases: BaseCLIResource

CLI resource for task operations.

Attributes:

Name Type Description
_cli

Reference to the parent ObsidianCLI instance.

Source code in src/aiobsidian/cli/_base.py
def __init__(self, cli: ObsidianCLI) -> None:
    self._cli = cli

list(*, path=None, daily=False, done=False) async

List tasks across the vault.

Parameters:

Name Type Description Default
path str | None

Restrict to tasks in files under this path.

None
daily bool

If True, only list tasks from the daily note.

False
done bool

If True, include completed tasks.

False

Returns:

Type Description
list[dict[str, Any]]

List of task objects.

Source code in src/aiobsidian/cli/tasks.py
async def list(
    self,
    *,
    path: str | None = None,
    daily: bool = False,
    done: bool = False,
) -> list[dict[str, Any]]:
    """List tasks across the vault.

    Args:
        path: Restrict to tasks in files under this path.
        daily: If ``True``, only list tasks from the daily note.
        done: If ``True``, include completed tasks.

    Returns:
        List of task objects.
    """
    params = {"path": path} if path is not None else None
    flags: list[str] = []
    if daily:
        flags.append("--daily")
    if done:
        flags.append("--done")
    output = await self._cli._execute("tasks", params=params, flags=flags or None)
    result: list[dict[str, Any]] = json.loads(output)
    return result

toggle(path, line) async

Toggle a task's completion status.

Parameters:

Name Type Description Default
path str

Path to the file containing the task.

required
line int

Line number of the task in the file.

required
Source code in src/aiobsidian/cli/tasks.py
async def toggle(self, path: str, line: int) -> None:
    """Toggle a task's completion status.

    Args:
        path: Path to the file containing the task.
        line: Line number of the task in the file.
    """
    await self._cli._execute(
        "task", params={"path": path, "line": str(line)}, flags=["--toggle"]
    )

create(content, *, tags=None) async

Create a new task.

Parameters:

Name Type Description Default
content str

Task text content.

required
tags str | None

Comma-separated tag names to attach to the task.

None
Source code in src/aiobsidian/cli/tasks.py
async def create(self, content: str, *, tags: str | None = None) -> None:
    """Create a new task.

    Args:
        content: Task text content.
        tags: Comma-separated tag names to attach to the task.
    """
    params: dict[str, str] = {"content": content}
    if tags:
        params["tags"] = tags
    await self._cli._execute("task:create", params=params)

complete(task_id) async

Mark a task as complete.

Parameters:

Name Type Description Default
task_id str

Identifier of the task to complete.

required
Source code in src/aiobsidian/cli/tasks.py
async def complete(self, task_id: str) -> None:
    """Mark a task as complete.

    Args:
        task_id: Identifier of the task to complete.
    """
    await self._cli._execute("task:complete", params={"task": task_id})