Subcommand 'up'
This commit is contained in:
parent
f222786015
commit
34507b9b8c
3 changed files with 72 additions and 0 deletions
|
@ -5,6 +5,7 @@ from .logs import LogsCommand
|
|||
from .net import NetUpCommand, NetDownCommand
|
||||
from .sh import ShCommand
|
||||
from .show import ShowCommand
|
||||
from .up import UpCommand
|
||||
|
||||
__all__ = [
|
||||
'CmdCommand',
|
||||
|
@ -14,4 +15,5 @@ __all__ = [
|
|||
'NetDownCommand',
|
||||
'ShCommand',
|
||||
'ShowCommand',
|
||||
'UpCommand',
|
||||
]
|
||||
|
|
33
src/kiwi/subcommands/up.py
Normal file
33
src/kiwi/subcommands/up.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
# system
|
||||
import logging
|
||||
|
||||
# local
|
||||
from ._subcommand import ServiceCommand
|
||||
from .utils.dockercommand import DockerCommand
|
||||
from .utils.project import list_projects
|
||||
|
||||
|
||||
class UpCommand(ServiceCommand):
|
||||
"""kiwi up"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
'up', num_projects='?', num_services='*',
|
||||
description="Start the whole instance, a project or service(s) inside a project"
|
||||
)
|
||||
|
||||
def run(self, runner, config, args):
|
||||
if args.projects is None:
|
||||
# "up" for all projects
|
||||
for project_name in list_projects(config):
|
||||
logging.info(f"Bringing up project '{project_name}'")
|
||||
args.projects = project_name
|
||||
|
||||
runner.run('up')
|
||||
|
||||
return
|
||||
|
||||
runner.run('net-up')
|
||||
DockerCommand('docker-compose').run(
|
||||
config, args, ['up', '-d', *args.services]
|
||||
)
|
37
src/kiwi/subcommands/utils/project.py
Normal file
37
src/kiwi/subcommands/utils/project.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
import os
|
||||
|
||||
|
||||
def get_project_name(args):
|
||||
"""get project name from CLI args"""
|
||||
|
||||
if args is not None and 'projects' in args:
|
||||
if isinstance(args.projects, list) and len(args.projects) > 0:
|
||||
return args.projects[0]
|
||||
else:
|
||||
return args.projects
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_project_dir(config, project_name):
|
||||
"""get project directory"""
|
||||
|
||||
return f"{project_name}{config['markers:project']}"
|
||||
|
||||
|
||||
def list_projects(config):
|
||||
"""list projects in current instance"""
|
||||
|
||||
# complete dir listing
|
||||
content = os.listdir()
|
||||
|
||||
# filter directories
|
||||
dirs = [d for d in content if os.path.isdir(d)]
|
||||
|
||||
# filter suffix
|
||||
project_dirs = [p for p in dirs if p.endswith(config['markers:project'])]
|
||||
|
||||
# remove suffix
|
||||
projects = [p[:-len(config['markers:project'])] for p in project_dirs]
|
||||
|
||||
return projects
|
Loading…
Reference in a new issue