This commit is contained in:
Jörn-Michael Miehe 2021-12-01 13:02:49 +01:00
parent 88004f0d2d
commit 10e600a4ac
2 changed files with 12 additions and 7 deletions

View file

@ -92,10 +92,15 @@ class KiwiCommand:
def danger_confirm(*prompt_lines: str, default: Optional[bool] = None) -> bool: def danger_confirm(*prompt_lines: str, default: Optional[bool] = None) -> bool:
if default is True: if default is True:
suffix = "[YES|no]" suffix = "[YES|no]"
default_answer = "yes"
elif default is False: elif default is False:
suffix = "[yes|NO]" suffix = "[yes|NO]"
default_answer = "no"
else: else:
suffix = "[yes|no]" suffix = "[yes|no]"
default_answer = None
dumb = WParagraph.from_strings( dumb = WParagraph.from_strings(
click.style("WARNING", bold=True, underline=True, blink=True, fg="red"), click.style("WARNING", bold=True, underline=True, blink=True, fg="red"),
@ -103,23 +108,23 @@ class KiwiCommand:
click.style("を捨てないで下さい", fg="cyan"), click.style("を捨てないで下さい", fg="cyan"),
click.style("DO NOT DUMB HERE", fg="yellow"), click.style("DO NOT DUMB HERE", fg="yellow"),
click.style("NO DUMB AREA", fg="yellow"), click.style("NO DUMB AREA", fg="yellow"),
).align().surround("!") ).align(WAlignment.CENTER).surround("!")
prompt = WParagraph.from_strings(*prompt_lines).align(WAlignment.LEFT).emphasize(3) prompt = WParagraph.from_strings(*prompt_lines).align(WAlignment.LEFT).emphasize(3)
answer = input( answer = input(
f"{dumb}\n\n" f"{dumb}\n\n"
f"{prompt}\n\n" f"{prompt}\n\n"
f"Are you sure you want to proceed? {suffix} " f"Are you sure you want to proceed? {suffix}: "
).strip().lower() ).strip().lower()
if answer == '': if not answer:
answer = default answer = default_answer
while answer not in ['yes', 'no']: while answer not in ["yes", "no"]:
answer = input("Please type 'yes' or 'no' explicitly: ").strip().lower() answer = input("Please type 'yes' or 'no' explicitly: ").strip().lower()
return answer == 'yes' return answer == "yes"
@classmethod @classmethod
def run(cls, instance: Instance, project_name: Optional[str] = None, service_names: Optional[List[str]] = None, def run(cls, instance: Instance, project_name: Optional[str] = None, service_names: Optional[List[str]] = None,

View file

@ -28,7 +28,7 @@ class ListCommand(KiwiCommand):
else: else:
KiwiCommand.print_header(f"Projects in kiwi-scp instance at '{instance.directory}':") KiwiCommand.print_header(f"Projects in kiwi-scp instance at '{instance.directory}':")
KiwiCommand.print_list( KiwiCommand.print_list(
project.name + click.style(" (disabled)" if not project.enabled else "", fg="red") project.name + (click.style(" (disabled)", fg="red") if not project.enabled else "")
for project in instance.config.projects for project in instance.config.projects
) )