diff --git a/kiwi_scp/misc.py b/kiwi_scp/misc.py index 7202fd3..cfa808b 100644 --- a/kiwi_scp/misc.py +++ b/kiwi_scp/misc.py @@ -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):