diff --git a/src/kiwi/subcommands/_subcommand.py b/src/kiwi/subcommands/_subcommand.py index 66687c6..61db871 100644 --- a/src/kiwi/subcommands/_subcommand.py +++ b/src/kiwi/subcommands/_subcommand.py @@ -1,5 +1,8 @@ +# system +import logging + # local -from .utils._misc import get_project_name, get_services, list_projects +from .utils.misc import get_project_name, get_services, list_projects # parent from ..parser import Parser @@ -71,12 +74,20 @@ class ServiceCommand(ProjectCommand): class FlexCommand(ServiceCommand): """this command concerns the entire instance, a whole project or just service(s) in a project""" - def __init__(self, name, **kwargs): + __action = None + + def __init__(self, name, action='', **kwargs): super().__init__( name, num_projects='?', num_services='*', **kwargs ) + if not action: + # default action string + self.__action = f"Running '{str(self)}' for" + else: + self.__action = action + def _run_instance(self, runner, config, args): result = True @@ -86,10 +97,10 @@ class FlexCommand(ServiceCommand): return result - def _run_project(self, runner, config, args, project_name): + def _run_project(self, runner, config, args): pass - def _run_services(self, runner, config, args, project_name, services): + def _run_services(self, runner, config, args, services): pass def run(self, runner, config, args): @@ -98,11 +109,14 @@ class FlexCommand(ServiceCommand): if project_name is None: # no project given, run for entire instance + logging.info(f"{self.__action} this instance") return self._run_instance(runner, config, args) - if services is None: + if not services: # no services given, run for whole project - return self._run_project(runner, config, args, project_name) + logging.info(f"{self.__action} project '{project_name}'") + return self._run_project(runner, config, args) # run for service(s) inside project - return self._run_services(runner, config, args, project_name, services) + logging.info(f"{self.__action} services {services} in project '{project_name}'") + return self._run_services(runner, config, args, services) diff --git a/src/kiwi/subcommands/conf.py b/src/kiwi/subcommands/conf.py index ea2981d..702261e 100644 --- a/src/kiwi/subcommands/conf.py +++ b/src/kiwi/subcommands/conf.py @@ -5,7 +5,7 @@ import subprocess # local from ._subcommand import SubCommand -from .utils._misc import list_projects, get_project_dir +from .utils.misc import list_projects, get_project_dir from .utils.rootkit import Rootkit, prefix_path_mnt # parent diff --git a/src/kiwi/subcommands/down.py b/src/kiwi/subcommands/down.py index 6a9fc7d..2950cdd 100644 --- a/src/kiwi/subcommands/down.py +++ b/src/kiwi/subcommands/down.py @@ -4,7 +4,7 @@ import logging # local from ._subcommand import FlexCommand from .utils.dockercommand import DockerCommand -from .utils._misc import are_you_sure +from .utils.misc import are_you_sure class DownCommand(FlexCommand): @@ -12,7 +12,8 @@ class DownCommand(FlexCommand): def __init__(self): super().__init__( - 'down', description="Bring down the whole instance, a project or service(s) inside a project" + 'down', "Bringing down", + description="Bring down the whole instance, a project or service(s) inside a project" ) def _run_instance(self, runner, config, args): @@ -21,17 +22,13 @@ class DownCommand(FlexCommand): return False - def _run_project(self, runner, config, args, project_name): - logging.info(f"Bringing down project '{project_name}'") - + def _run_project(self, runner, config, args): DockerCommand('docker-compose').run( config, args, ['down'] ) return True - def _run_services(self, runner, config, args, project_name, services): - logging.info(f"Bringing down services {services} in project '{project_name}'") - + def _run_services(self, runner, config, args, services): DockerCommand('docker-compose').run( config, args, ['stop', *services] ) diff --git a/src/kiwi/subcommands/net.py b/src/kiwi/subcommands/net.py index 10bd92c..6c007f8 100644 --- a/src/kiwi/subcommands/net.py +++ b/src/kiwi/subcommands/net.py @@ -5,7 +5,7 @@ import subprocess # local from ._subcommand import SubCommand from .utils.dockercommand import DockerCommand -from .utils._misc import are_you_sure +from .utils.misc import are_you_sure def _find_net(config, args): diff --git a/src/kiwi/subcommands/up.py b/src/kiwi/subcommands/up.py index a1dedbb..1bf8c7c 100644 --- a/src/kiwi/subcommands/up.py +++ b/src/kiwi/subcommands/up.py @@ -11,20 +11,17 @@ class UpCommand(FlexCommand): def __init__(self): super().__init__( - 'up', description="Bring up the whole instance, a project or service(s) inside a project" + 'up', "Bringing up", + description="Bring up the whole instance, a project or service(s) inside a project" ) - def _run_project(self, runner, config, args, project_name): - logging.info(f"Bringing up project '{project_name}'") - + def _run_project(self, runner, config, args): DockerCommand('docker-compose').run( config, args, ['up', '-d'] ) return True - def _run_services(self, runner, config, args, project_name, services): - logging.info(f"Bringing up services {services} in project '{project_name}'") - + def _run_services(self, runner, config, args, services): DockerCommand('docker-compose').run( config, args, ['up', '-d', *services] ) diff --git a/src/kiwi/subcommands/utils/dockercommand.py b/src/kiwi/subcommands/utils/dockercommand.py index 5b1bebe..6093dfd 100644 --- a/src/kiwi/subcommands/utils/dockercommand.py +++ b/src/kiwi/subcommands/utils/dockercommand.py @@ -5,7 +5,7 @@ import subprocess # local from .executable import Executable -from ._misc import get_project_dir, get_project_name +from .misc import get_project_dir, get_project_name # parent from ..._constants import CONF_DIRECTORY_NAME diff --git a/src/kiwi/subcommands/utils/_misc.py b/src/kiwi/subcommands/utils/misc.py similarity index 100% rename from src/kiwi/subcommands/utils/_misc.py rename to src/kiwi/subcommands/utils/misc.py