subcommand "down"
This commit is contained in:
parent
4ad2b7c458
commit
79520c2a63
3 changed files with 71 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
|||
# local
|
||||
from .cmd import CmdCommand
|
||||
from .down import DownCommand
|
||||
from .init import InitCommand
|
||||
from .logs import LogsCommand
|
||||
from .net import NetUpCommand, NetDownCommand
|
||||
|
@ -9,6 +10,7 @@ from .up import UpCommand
|
|||
|
||||
__all__ = [
|
||||
'CmdCommand',
|
||||
'DownCommand',
|
||||
'InitCommand',
|
||||
'LogsCommand',
|
||||
'NetUpCommand',
|
||||
|
|
46
src/kiwi/subcommands/down.py
Normal file
46
src/kiwi/subcommands/down.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
# system
|
||||
import logging
|
||||
|
||||
# local
|
||||
from ._subcommand import ServiceCommand
|
||||
from .utils.dockercommand import DockerCommand
|
||||
from .utils.project import get_project_name, list_projects
|
||||
from .utils.user_input import are_you_sure
|
||||
|
||||
|
||||
class DownCommand(ServiceCommand):
|
||||
"""kiwi down"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
'down', num_projects='?', num_services='*',
|
||||
description="Bring down the whole instance, a project or service(s) inside a project"
|
||||
)
|
||||
|
||||
def run(self, runner, config, args):
|
||||
if 'projects' not in args or args.projects is None:
|
||||
# "down" for all projects
|
||||
if are_you_sure("This will bring down the entire instance."):
|
||||
for project_name in list_projects(config):
|
||||
args.projects = project_name
|
||||
runner.run('down')
|
||||
return
|
||||
|
||||
if 'services' in args and args.services:
|
||||
# "down" for service(s) inside project
|
||||
logging.info(f"Bringing down services {args.services} in project '{get_project_name(args)}'")
|
||||
|
||||
DockerCommand('docker-compose').run(
|
||||
config, args, ['stop', *args.services]
|
||||
)
|
||||
DockerCommand('docker-compose').run(
|
||||
config, args, ['rm', '-f', *args.services]
|
||||
)
|
||||
|
||||
else:
|
||||
# "down" for project
|
||||
logging.info(f"Bringing down project '{get_project_name(args)}'")
|
||||
|
||||
DockerCommand('docker-compose').run(
|
||||
config, args, ['down']
|
||||
)
|
23
src/kiwi/subcommands/utils/user_input.py
Normal file
23
src/kiwi/subcommands/utils/user_input.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
def are_you_sure(prompt, default="no"):
|
||||
if default.lower() == 'yes':
|
||||
suffix = "[YES|no]"
|
||||
else:
|
||||
suffix = "[yes|NO]"
|
||||
|
||||
answer = input(
|
||||
"!!!!!!!!!!!!!!!!!!\n"
|
||||
"!!! BE CAREFUL !!!\n"
|
||||
"!!!!!!!!!!!!!!!!!!\n"
|
||||
"\n"
|
||||
f"{prompt}\n"
|
||||
"\n"
|
||||
f"Are you sure you want to proceed? {suffix} "
|
||||
).strip().lower()
|
||||
|
||||
if answer == '':
|
||||
answer = default
|
||||
|
||||
while answer not in ['yes', 'no']:
|
||||
answer = input("Please type 'yes' or 'no' explicitly: ").strip().lower()
|
||||
|
||||
return answer == 'yes'
|
Loading…
Reference in a new issue