mirror of
https://github.com/yavook/kiwi-scp.git
synced 2024-12-24 18:22:59 +00:00
remove run logic from kiwi_command
This commit is contained in:
parent
f194ea9356
commit
99a50f1460
2 changed files with 37 additions and 29 deletions
|
@ -1,4 +1,5 @@
|
|||
import importlib
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from enum import Enum, auto
|
||||
|
@ -9,6 +10,8 @@ import click
|
|||
from ..instance import Instance, Project, Services
|
||||
from ..wstring import WParagraph, WAlignment
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class KiwiCLI(click.MultiCommand):
|
||||
"""Command Line Interface spread over multiple files in this directory"""
|
||||
|
@ -118,6 +121,37 @@ class KiwiCommand:
|
|||
|
||||
return answer == 'yes'
|
||||
|
||||
@classmethod
|
||||
def run(cls, instance: Instance, project_name: Optional[str] = None, service_names: Optional[List[str]] = None,
|
||||
**kwargs):
|
||||
|
||||
_logger.debug(f"{instance.directory!r}: {project_name!r}, {service_names!r}")
|
||||
if project_name is None:
|
||||
# run for whole instance
|
||||
_logger.debug(f"running for instance, kwargs={kwargs}")
|
||||
cls.run_for_instance(instance, **kwargs)
|
||||
|
||||
elif not service_names:
|
||||
# run for one entire project
|
||||
project = instance.get_project(project_name)
|
||||
if project is None:
|
||||
_logger.debug(f"running for new project {project_name}, kwargs={kwargs}")
|
||||
cls.run_for_new_project(instance, project_name, **kwargs)
|
||||
|
||||
else:
|
||||
_logger.debug(f"running for project {project.name}, kwargs={kwargs}")
|
||||
cls.run_for_project(instance, project, **kwargs)
|
||||
|
||||
else:
|
||||
# run for some services
|
||||
project = instance.get_project(project_name)
|
||||
if project is not None:
|
||||
_logger.debug(f"running for services {service_names} in project {project}, kwargs={kwargs}")
|
||||
cls.run_for_services(instance, project, service_names, **kwargs)
|
||||
|
||||
else:
|
||||
cls.print_error(f"Project '{project_name}' not in kiwi-scp instance at '{instance.directory}'!")
|
||||
|
||||
@classmethod
|
||||
def run_for_instance(cls, instance: Instance, **kwargs) -> None:
|
||||
for project_config in instance.config.projects:
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import logging
|
||||
from typing import Callable, Type, Optional, Tuple
|
||||
|
||||
import click
|
||||
|
@ -25,8 +24,6 @@ _services_arg = click.argument(
|
|||
type=str,
|
||||
)
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def kiwi_command(
|
||||
cmd_type: KiwiCommandType = KiwiCommandType.SERVICE,
|
||||
|
@ -41,33 +38,10 @@ def kiwi_command(
|
|||
@_pass_instance
|
||||
def cmd(ctx: Instance, project_name: Optional[str] = None, service_names: Optional[Tuple[str]] = None,
|
||||
**kwargs) -> None:
|
||||
if service_names is not None:
|
||||
service_names = list(service_names)
|
||||
|
||||
_logger.debug(f"{ctx.directory!r}: {project_name!r}, {service_names!r}")
|
||||
if project_name is None:
|
||||
# run for whole instance
|
||||
_logger.debug(f"running for instance, kwargs={kwargs}")
|
||||
command_cls.run_for_instance(ctx, **kwargs)
|
||||
|
||||
elif not service_names:
|
||||
# run for one entire project
|
||||
project = ctx.get_project(project_name)
|
||||
if project is not None:
|
||||
_logger.debug(f"running for existing project {project}, kwargs={kwargs}")
|
||||
command_cls.run_for_project(ctx, project, **kwargs)
|
||||
|
||||
else:
|
||||
_logger.debug(f"running for new project {project_name}, kwargs={kwargs}")
|
||||
command_cls.run_for_new_project(ctx, project_name, **kwargs)
|
||||
|
||||
else:
|
||||
# run for some services
|
||||
project = ctx.get_project(project_name)
|
||||
if project is not None:
|
||||
_logger.debug(f"running for services {service_names} in project {project}, kwargs={kwargs}")
|
||||
command_cls.run_for_services(ctx, project, list(service_names), **kwargs)
|
||||
|
||||
else:
|
||||
KiwiCommand.print_error(f"Project '{project_name}' not in kiwi-scp instance at '{ctx.directory}'!")
|
||||
command_cls.run(ctx, project_name, service_names, **kwargs)
|
||||
|
||||
if cmd_type is KiwiCommandType.PROJECT:
|
||||
cmd = _project_arg(cmd)
|
||||
|
|
Loading…
Reference in a new issue