QoL: Added _run_project overridable with automatic call for multiple projects
This commit is contained in:
parent
40e476ba7b
commit
6819eabb67
7 changed files with 28 additions and 39 deletions
|
@ -65,6 +65,13 @@ class ProjectCommand(SubCommand):
|
|||
return self._run_projects(runner, args, Projects.from_dir().filter_enabled())
|
||||
|
||||
def _run_projects(self, runner, args, projects):
|
||||
# default: run for all given projects
|
||||
return all([
|
||||
self._run_project(runner, args, project)
|
||||
for project in projects
|
||||
])
|
||||
|
||||
def _run_project(self, runner, args, project):
|
||||
pass
|
||||
|
||||
def run(self, runner, args):
|
||||
|
@ -102,14 +109,9 @@ class ServiceCommand(ProjectCommand):
|
|||
help=f"select {services} in a project"
|
||||
)
|
||||
|
||||
def _run_projects(self, runner, args, projects):
|
||||
result = True
|
||||
|
||||
# default: run without services for all given
|
||||
for project in projects:
|
||||
result &= self._run_services(runner, args, project, [])
|
||||
|
||||
return result
|
||||
def _run_project(self, runner, args, project):
|
||||
# default: run with empty service list
|
||||
return self._run_services(runner, args, project, [])
|
||||
|
||||
def _run_services(self, runner, args, project, services):
|
||||
pass
|
||||
|
|
|
@ -27,7 +27,7 @@ class CmdCommand(ProjectCommand):
|
|||
help="arguments for 'docker-compose' commands"
|
||||
)
|
||||
|
||||
def _run_projects(self, runner, args, projects):
|
||||
def _run_project(self, runner, args, project):
|
||||
if args.unknowns:
|
||||
args.compose_args = [*args.compose_args, *args.unknowns]
|
||||
args.unknowns = []
|
||||
|
@ -35,6 +35,6 @@ class CmdCommand(ProjectCommand):
|
|||
logging.debug(f"Updated args: {args}")
|
||||
|
||||
# run with split compose_cmd argument
|
||||
projects[0].compose_run([args.compose_cmd, *args.compose_args])
|
||||
project.compose_run([args.compose_cmd, *args.compose_args])
|
||||
|
||||
return True
|
||||
|
|
|
@ -12,8 +12,5 @@ class DisableCommand(ProjectCommand):
|
|||
description="Disable project(s) in this instance"
|
||||
)
|
||||
|
||||
def _run_projects(self, runner, args, projects):
|
||||
return all([
|
||||
project.disable()
|
||||
for project in projects
|
||||
])
|
||||
def _run_project(self, runner, args, project):
|
||||
return project.disable()
|
||||
|
|
|
@ -24,10 +24,8 @@ class DownCommand(ServiceCommand):
|
|||
|
||||
return False
|
||||
|
||||
def _run_projects(self, runner, args, projects):
|
||||
for project in projects:
|
||||
def _run_project(self, runner, args, project):
|
||||
project.compose_run(['down'])
|
||||
|
||||
return True
|
||||
|
||||
def _run_services(self, runner, args, project, services):
|
||||
|
|
|
@ -12,8 +12,5 @@ class EnableCommand(ProjectCommand):
|
|||
description="Enable project(s) in this instance"
|
||||
)
|
||||
|
||||
def _run_projects(self, runner, args, projects):
|
||||
return all([
|
||||
project.enable()
|
||||
for project in projects
|
||||
])
|
||||
def _run_project(self, runner, args, project):
|
||||
return project.enable()
|
||||
|
|
|
@ -51,8 +51,7 @@ class InspectCommand(ServiceCommand):
|
|||
|
||||
return True
|
||||
|
||||
def _run_projects(self, runner, args, projects):
|
||||
project = projects[0]
|
||||
def _run_project(self, runner, args, project):
|
||||
if not project.exists():
|
||||
logging.warning(f"Project '{project.get_name()}' not found")
|
||||
return False
|
||||
|
|
|
@ -18,17 +18,13 @@ class NewCommand(ProjectCommand):
|
|||
description="Create new empty project(s) in this instance"
|
||||
)
|
||||
|
||||
def _run_projects(self, runner, args, projects):
|
||||
result = True
|
||||
|
||||
for project in projects:
|
||||
def _run_project(self, runner, args, project):
|
||||
if project.exists():
|
||||
logging.error(f"Project '{project.get_name()}' exists in this instance!")
|
||||
result = False
|
||||
return False
|
||||
|
||||
else:
|
||||
logging.info(f"Creating project '{project.get_name()}'")
|
||||
os.mkdir(project.disabled_dir_name())
|
||||
shutil.copy(DEFAULT_DOCKER_COMPOSE_NAME, project.compose_file_name())
|
||||
|
||||
return result
|
||||
logging.debug(f"Project '{project.get_name()}' created")
|
||||
return True
|
||||
|
|
Loading…
Reference in a new issue