click-compose-2025.10.27.3
توضیحات
Composable Click callback utilities for building flexible CLI applications.
| ویژگی | مقدار |
|---|---|
| سیستم عامل | OS Independent |
| نام فایل | click-compose-2025.10.27.3 |
| نام | click-compose |
| نسخه کتابخانه | 2025.10.27.3 |
| نگهدارنده | [] |
| ایمیل نگهدارنده | [] |
| نویسنده | - |
| ایمیل نویسنده | Adam Dangoor <adamdangoor@gmail.com> |
| آدرس صفحه اصلی | - |
| آدرس اینترنتی | https://pypi.org/project/click-compose/ |
| مجوز | - |
click-compose
=============
Composable Click callback utilities for building flexible CLI applications.
.. contents::
:local:
Installation
------------
.. code-block:: shell
$ pip install click-compose
Or with ``uv``:
.. code-block:: shell
$ uv add click-compose
Quick Start
-----------
``click-compose`` provides two main utilities for composing Click callbacks:
multi_callback
~~~~~~~~~~~~~~
Combine multiple callbacks into a single callback that applies them in sequence:
.. code-block:: python
"""Example of using multi_callback to combine validators."""
import click
from click_compose import multi_callback
def validate_positive(
_ctx: click.Context,
_param: click.Parameter,
value: int,
) -> int:
"""Validate that value is positive."""
if value <= 0:
msg = "Must be positive"
raise click.BadParameter(message=msg)
return value
MAX_VALUE = 100
def validate_max_100(
_ctx: click.Context,
_param: click.Parameter,
value: int,
) -> int:
"""Validate that value is at most 100."""
if value > MAX_VALUE:
msg = "Must be <= 100"
raise click.BadParameter(message=msg)
return value
@click.command()
@click.option(
"--count",
type=int,
callback=multi_callback(callbacks=[validate_positive, validate_max_100]),
)
def cmd(count: int) -> None:
"""Example command with multiple validators."""
click.echo(message=f"Count: {count}")
sequence_validator
~~~~~~~~~~~~~~~~~~
Apply a validator to each element in a sequence (useful with ``multiple=True``):
.. code-block:: python
"""Example of using sequence_validator with multiple values."""
import click
from click_compose import sequence_validator
def validate_positive(
_ctx: click.Context | None,
_param: click.Parameter | None,
value: int,
) -> int:
"""Validate that value is positive."""
if value <= 0:
msg = "Must be positive"
raise click.BadParameter(message=msg)
return value
@click.command()
@click.option(
"--numbers",
multiple=True,
type=int,
callback=sequence_validator(validator=validate_positive),
)
def cmd(numbers: tuple[int, ...]) -> None:
"""Example command with sequence validation."""
click.echo(message=f"Sum: {sum(numbers)}")
Documentation
-------------
See the `full documentation <https://adamtheturtle.github.io/click-compose/>`__.
نیازمندی
| مقدار | نام |
|---|---|
| - | beartype>=0.18.5 |
| - | click>=8.0.0 |
| xtr | actionlint-py==1.7.8.24; |
| xtr | check-manifest==0.51; |
| xtr | deptry==0.23.1; |
| xtr | doc8==2.0.0; |
| xtr | doccmd==2025.10.27; |
| xtr | docformatter==1.7.7; |
| xtr | furo==2025.9.25; |
| xtr | interrogate==1.7.0; |
| xtr | mypy[faster-cache]==1.18.2; |
| xtr | mypy-strict-kwargs==2025.4.3; |
| xtr | packaging>=24.0; |
| xtr | pre-commit==4.3.0; |
| xtr | pydocstyle==6.3; |
| xtr | pygments==2.19.2; |
| xtr | pylint[spelling]==4.0.2; |
| xtr | pylint-per-file-ignores==3.1.0; |
| xtr | pyproject-fmt==2.11.0; |
| xtr | pyright==1.1.407; |
| xtr | pyroma==5.0; |
| xtr | pytest==8.4.2; |
| xtr | pytest-cov==7.0.0; |
| xtr | pytest-regressions==2.8.3; |
| xtr | pyyaml==6.0.3; |
| xtr | ruff==0.14.2; |
| xtr | shellcheck-py==0.11.0.1; |
| xtr | shfmt-py==3.12.0.2; |
| xtr | sphinx>=8.1.3; |
| xtr | sphinx-copybutton==0.5.2; |
| xtr | sphinx-lint==1.0.0; |
| xtr | sphinx-pyproject==0.3.0; |
| xtr | sphinx-substitution-extensions==2025.10.24; |
| xtr | sphinxcontrib-spelling==8.0.1; |
| xtr | vulture==2.14; |
| xtr | yamlfix==1.19.0; |
| xtr | check-wheel-contents==0.6.3; |
زبان مورد نیاز
| مقدار | نام |
|---|---|
| >=3.10 | Python |
نحوه نصب
نصب پکیج whl click-compose-2025.10.27.3:
pip install click-compose-2025.10.27.3.whl
نصب پکیج tar.gz click-compose-2025.10.27.3:
pip install click-compose-2025.10.27.3.tar.gz