hubvault.entry.context

CLI repository-context helpers for hubvault.entry.

This module centralizes repository-path resolution for CLI commands and keeps repo discovery on top of the public hubvault.api.HubVaultApi surface. The CLI deliberately does not inspect private storage files directly just to discover the default branch or other repository metadata.

The module contains:

Example:

>>> import click
>>> ctx = click.Context(click.Command("demo"))
>>> with ctx:
...     set_cli_repo_path(ctx, None)
...     str(get_cli_repo_path(ctx)).endswith(str(get_cli_repo_path(ctx).name))
True

CliRepoContext

class hubvault.entry.context.CliRepoContext(repo_path: Path, default_branch: str)[source]

Describe the repository selection used by CLI commands.

Parameters:
  • repo_path (pathlib.Path) – Filesystem path to the local repository root

  • default_branch (str) – Repository default branch resolved through the public API

Example:

>>> context = CliRepoContext(repo_path=Path("/tmp/repo"), default_branch="main")
>>> context.default_branch
'main'
create_api(revision: str | None = None) HubVaultApi[source]

Build a public API wrapper scoped to this repository context.

Parameters:

revision (Optional[str]) – Optional default revision for subsequent API calls. When omitted, the repository default branch is used.

Returns:

Public repository API wrapper

Return type:

hubvault.api.HubVaultApi

Example:

>>> context = CliRepoContext(repo_path=Path("/tmp/repo"), default_branch="main")
>>> context.create_api("main").__class__.__name__
'HubVaultApi'
classmethod from_repo_path(repo_path: Path) CliRepoContext[source]

Build CLI repository metadata from a local repository path.

Parameters:

repo_path (pathlib.Path) – Filesystem path to the local repository root

Returns:

Resolved CLI repository context

Return type:

CliRepoContext

Example:

>>> context = CliRepoContext.from_repo_path  

set_cli_repo_path

hubvault.entry.context.set_cli_repo_path(ctx: Context, repo_path: str | None) None[source]

Persist the global CLI repo path in the current Click context.

Parameters:
  • ctx (click.Context) – Click context for the current CLI invocation

  • repo_path (Optional[str]) – Repo path from the global -C option, or None to use the current working directory

Returns:

None.

Return type:

None

Example:

>>> ctx = click.Context(click.Command("demo"))
>>> with ctx:
...     set_cli_repo_path(ctx, None)
...     "repo_path" in ctx.obj
True

get_cli_repo_path

hubvault.entry.context.get_cli_repo_path(ctx: Context) Path[source]

Return the repo path configured for the current CLI invocation.

Parameters:

ctx (click.Context) – Click context for the current CLI invocation

Returns:

Resolved repository path

Return type:

pathlib.Path

Example:

>>> ctx = click.Context(click.Command("demo"))
>>> with ctx:
...     set_cli_repo_path(ctx, None)
...     isinstance(get_cli_repo_path(ctx), Path)
True

load_cli_repo_context

hubvault.entry.context.load_cli_repo_context(ctx: Context) CliRepoContext[source]

Build and cache repository metadata for CLI commands.

Parameters:

ctx (click.Context) – Click context for the current CLI invocation

Returns:

Cached repository context

Return type:

CliRepoContext

Example:

>>> context_loader = load_cli_repo_context