Skip to content

CLI History Resource

CLIHistoryResource(cli)

Bases: BaseCLIResource

CLI resource for local file history 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

versions(path) async

List versions of a specific file in local history.

Parameters:

Name Type Description Default
path str

Path to the file relative to the vault root.

required

Returns:

Type Description
list[dict[str, Any]]

List of version objects for the file.

Source code in src/aiobsidian/cli/history.py
async def versions(self, path: str) -> list[dict[str, Any]]:
    """List versions of a specific file in local history.

    Args:
        path: Path to the file relative to the vault root.

    Returns:
        List of version objects for the file.
    """
    output = await self._cli._execute("history", params={"path": path})
    result: list[dict[str, Any]] = json.loads(output)
    return result

open(path) async

Open the File Recovery UI for a file.

Parameters:

Name Type Description Default
path str

Path to the file relative to the vault root.

required
Source code in src/aiobsidian/cli/history.py
async def open(self, path: str) -> None:
    """Open the File Recovery UI for a file.

    Args:
        path: Path to the file relative to the vault root.
    """
    await self._cli._execute("history:open", params={"path": path})

diff(path, *, from_version=None, to_version=None, filter=None) async

Get a diff between file versions.

Parameters:

Name Type Description Default
path str

Path to the file relative to the vault root.

required
from_version str | None

Starting version identifier.

None
to_version str | None

Ending version identifier.

None
filter str | None

Filter expression for the diff output.

None

Returns:

Type Description
str

Diff output as a string.

Source code in src/aiobsidian/cli/history.py
async def diff(
    self,
    path: str,
    *,
    from_version: str | None = None,
    to_version: str | None = None,
    filter: str | None = None,
) -> str:
    """Get a diff between file versions.

    Args:
        path: Path to the file relative to the vault root.
        from_version: Starting version identifier.
        to_version: Ending version identifier.
        filter: Filter expression for the diff output.

    Returns:
        Diff output as a string.
    """
    params: dict[str, str] = {"path": path}
    if from_version is not None:
        params["from"] = from_version
    if to_version is not None:
        params["to"] = to_version
    if filter is not None:
        params["filter"] = filter
    return await self._cli._execute("diff", params=params)

read(path, *, version=None) async

Read a version from local history.

Parameters:

Name Type Description Default
path str

Path to the file relative to the vault root.

required
version str | None

Version identifier. Defaults to the latest version.

None

Returns:

Type Description
str

File content at the specified version.

Source code in src/aiobsidian/cli/history.py
async def read(self, path: str, *, version: str | None = None) -> str:
    """Read a version from local history.

    Args:
        path: Path to the file relative to the vault root.
        version: Version identifier. Defaults to the latest version.

    Returns:
        File content at the specified version.
    """
    params: dict[str, str] = {"path": path}
    if version is not None:
        params["version"] = version
    return await self._cli._execute("history:read", params=params)

restore(path, *, version) async

Restore a file from local history.

Parameters:

Name Type Description Default
path str

Path to the file relative to the vault root.

required
version str

Version identifier to restore.

required
Source code in src/aiobsidian/cli/history.py
async def restore(self, path: str, *, version: str) -> None:
    """Restore a file from local history.

    Args:
        path: Path to the file relative to the vault root.
        version: Version identifier to restore.
    """
    await self._cli._execute(
        "history:restore", params={"path": path, "version": version}
    )

list() async

List files that have local history.

Returns:

Type Description
list[dict[str, Any]]

List of file objects with local history.

Source code in src/aiobsidian/cli/history.py
async def list(self) -> list[dict[str, Any]]:
    """List files that have local history.

    Returns:
        List of file objects with local history.
    """
    output = await self._cli._execute("history:list")
    result: list[dict[str, Any]] = json.loads(output)
    return result