1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-11-24 21:52:59 +00:00

Subcommand 'up'

This commit is contained in:
Jörn-Michael Miehe 2020-08-17 14:12:33 +02:00
parent f222786015
commit 34507b9b8c
3 changed files with 72 additions and 0 deletions

View file

@ -5,6 +5,7 @@ from .logs import LogsCommand
from .net import NetUpCommand, NetDownCommand from .net import NetUpCommand, NetDownCommand
from .sh import ShCommand from .sh import ShCommand
from .show import ShowCommand from .show import ShowCommand
from .up import UpCommand
__all__ = [ __all__ = [
'CmdCommand', 'CmdCommand',
@ -14,4 +15,5 @@ __all__ = [
'NetDownCommand', 'NetDownCommand',
'ShCommand', 'ShCommand',
'ShowCommand', 'ShowCommand',
'UpCommand',
] ]

View 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]
)

View 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