kiwi-scp/kiwi_scp/commands/cmd_update.py

66 lines
2.1 KiB
Python
Raw Permalink Normal View History

2022-01-19 11:03:42 +00:00
from typing import List
import click
from click import get_current_context
from .cmd import KiwiCommandType, KiwiCommand
2022-01-19 14:36:41 +00:00
from .cmd_build import BuildCommand
from .cmd_down import DownCommand
from .cmd_pull import PullCommand
from .cmd_up import UpCommand
2022-01-19 11:03:42 +00:00
from .decorators import kiwi_command
from ..instance import Instance
from ..project import Project
from ..services import Services
@click.option(
"-f/-F",
"--force/--no-force",
help=f"skip confirmation",
)
@kiwi_command(
short_help="Update kiwi services",
)
class UpdateCommand(KiwiCommand):
"""Update the whole instance, a project or service(s) inside a project"""
type = KiwiCommandType.SERVICES
enabled_only = True
2022-01-19 14:36:41 +00:00
@classmethod
def run_for_instance(cls, instance: Instance, force: bool = None) -> None:
if not force:
if not KiwiCommand.danger_confirm(
"This will update the entire instance at once.",
"",
"This may not be what you intended, because:",
" - Updates may take a long time",
" - Updates may break beloved functionality",
):
return
super().run_for_instance(instance)
2022-01-19 11:03:42 +00:00
@classmethod
def run_for_filtered_services(cls, instance: Instance, project: Project, services: Services,
new_service_names: List[str], **kwargs) -> None:
if not services:
if not click.confirm(
"Did not find any of those services. \n"
f"Update the entire project {project.name} instead?",
default=True
):
return
ctx = get_current_context()
2022-01-19 14:36:41 +00:00
assert isinstance(BuildCommand, click.Command)
2022-01-19 11:03:42 +00:00
ctx.forward(BuildCommand)
2022-01-19 14:36:41 +00:00
assert isinstance(PullCommand, click.Command)
2022-01-19 11:03:42 +00:00
ctx.forward(PullCommand)
2022-01-27 16:57:15 +00:00
services.copy_configs()
2022-01-19 14:36:41 +00:00
assert isinstance(DownCommand, click.Command)
2022-01-19 11:03:42 +00:00
ctx.forward(DownCommand)
2022-01-19 14:36:41 +00:00
assert isinstance(UpCommand, click.Command)
2022-01-19 11:03:42 +00:00
ctx.forward(UpCommand)