1
0
Fork 0
mirror of https://github.com/yavook/kiwi-scp.git synced 2024-11-23 05:13:01 +00:00
kiwi-scp/kiwi_scp/commands/cmd_disable.py

41 lines
1.2 KiB
Python
Raw Normal View History

2021-12-01 11:29:40 +00:00
import click
from .cli import KiwiCommand, KiwiCommandType
from .decorators import kiwi_command
from .._constants import KIWI_CONF_NAME
2021-12-02 16:08:14 +00:00
from ..instance import Instance
from ..project import Project
2021-12-01 11:29:40 +00:00
@click.option(
"-f/-F",
"--force/--no-force",
help=f"skip confirmation",
)
2021-12-01 16:49:19 +00:00
@kiwi_command()
2021-12-01 11:29:40 +00:00
class DisableCommand(KiwiCommand):
2021-12-01 16:49:19 +00:00
"""Disable project(s)"""
type = KiwiCommandType.PROJECTS
2021-12-01 11:29:40 +00:00
@classmethod
def run_for_instance(cls, instance: Instance, force: bool = None) -> None:
if not force:
if not KiwiCommand.danger_confirm("This will disable all projects in this instance."):
return
super().run_for_instance(instance)
@classmethod
def run_for_project(cls, instance: Instance, project: Project, **kwargs) -> None:
2021-12-02 01:38:29 +00:00
if not project.config.enabled:
2021-12-01 11:29:40 +00:00
KiwiCommand.print_error(f"Project {project.name} is already disabled!")
return
2021-12-02 01:38:29 +00:00
project.config.enabled = False
2021-12-01 11:29:40 +00:00
KiwiCommand.print_header(f"Project {project.name} disabled")
# write out the new kiwi.yml
with open(instance.directory.joinpath(KIWI_CONF_NAME), "w") as file:
instance.config.dump_kiwi_yml(file)