1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-12-25 18:42:59 +00:00

decorators for instancem, project and service commands

This commit is contained in:
Jörn-Michael Miehe 2021-10-21 04:02:28 +02:00
parent 71943a1911
commit 1621e13360

View file

@ -1,6 +1,47 @@
from typing import Any, Type
from typing import Any, Type, List, Callable
import attr
import click
from click.decorators import FC
@attr.s
class _MultiDecorator:
options: List[Callable[[FC], FC]] = attr.ib(factory=list)
def __call__(self, target: FC):
for option in reversed(self.options):
target = option(target)
return target
_instance_args = []
instance_command = _MultiDecorator(_instance_args)
_project_args = [
*_instance_args,
click.argument(
"project",
required=False,
type=click.Path(exists=True),
default=".",
),
]
project_command = _MultiDecorator(_project_args)
_service_args = [
*_project_args,
click.argument(
"service",
required=False,
type=str,
),
]
service_command = _MultiDecorator(_service_args)
def user_query(description: str, default: Any, cast_to: Type[Any] = str):