decorators for instancem, project and service commands
This commit is contained in:
parent
71943a1911
commit
1621e13360
1 changed files with 42 additions and 1 deletions
|
@ -1,6 +1,47 @@
|
||||||
from typing import Any, Type
|
from typing import Any, Type, List, Callable
|
||||||
|
|
||||||
|
import attr
|
||||||
import click
|
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):
|
def user_query(description: str, default: Any, cast_to: Type[Any] = str):
|
||||||
|
|
Loading…
Reference in a new issue