Coverage for seedboxsync/cli/context.py: 100%
12 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-26 17:46 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-07-26 17:46 +0000
1#
2# Copyright (C) 2015-2026 Guillaume Kulakowski <guillaume@kulakowski.fr>
3#
4# For the full copyright and license information, please view the LICENSE
5# file that was distributed with this source code.
6#
7"""Build a context used by Click."""
9from collections.abc import Iterable, Sequence
10from functools import cached_property
11from typing import Any
12import click
13from tabulate import tabulate
14from seedboxsync.core import Flask, current_app
17class Context(click.Context):
18 """SeedboxSync Click context."""
20 @cached_property
21 def app(self) -> Flask:
22 """
23 Return the current Flask application.
25 Returns:
26 Flask: The current Flask application.
27 """
28 return current_app
30 def render(self, data: Iterable[Any], headers: str | dict[str, str] | Sequence[str], tablefmt: str = "github") -> Any:
31 """
32 Render tabular data using the specified output format.
34 Args:
35 data: Tabular data to render.
36 headers: Column headers passed to ``tabulate``.
37 tablefmt: Output table format.
39 Returns:
40 str: The formatted table.
41 """
42 return tabulate(data, headers=headers, tablefmt=tablefmt)