From 81b597cb586d78dfd06f4ddb39704139f5ae745f Mon Sep 17 00:00:00 2001 From: ldericher Date: Tue, 18 Aug 2020 15:05:19 +0200 Subject: [PATCH] neater prompts --- src/kiwi/subcommands/down.py | 7 ++++++- src/kiwi/subcommands/update.py | 13 +++++++++++++ src/kiwi/subcommands/utils/misc.py | 12 ++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/kiwi/subcommands/down.py b/src/kiwi/subcommands/down.py index 013f6a4..ebb4a4c 100644 --- a/src/kiwi/subcommands/down.py +++ b/src/kiwi/subcommands/down.py @@ -14,7 +14,12 @@ class DownCommand(FlexCommand): ) def _run_instance(self, runner, config, args): - if are_you_sure("This will bring down the entire instance."): + if are_you_sure([ + "This will bring down the entire instance.", + "", + "This may not be what you intended, because:", + " - Bringing down the instance stops ALL services in here", + ]): return super()._run_instance(runner, config, args) return False diff --git a/src/kiwi/subcommands/update.py b/src/kiwi/subcommands/update.py index 045c192..cfac6fe 100644 --- a/src/kiwi/subcommands/update.py +++ b/src/kiwi/subcommands/update.py @@ -1,5 +1,6 @@ # local from ._subcommand import FlexCommand +from .utils.misc import are_you_sure class UpdateCommand(FlexCommand): @@ -11,6 +12,18 @@ class UpdateCommand(FlexCommand): description="Update the whole instance, a project or service(s) inside a project" ) + def _run_instance(self, runner, config, args): + if are_you_sure([ + "This will update the entire instance at once.", + "", + "This is probably not what you intended, because:", + " - Updates may take a long time", + " - Updates may break beloved functionality", + ]): + return super()._run_instance(runner, config, args) + + return False + def _run_services(self, runner, config, args, services): result = runner.run('build') result &= runner.run('pull') diff --git a/src/kiwi/subcommands/utils/misc.py b/src/kiwi/subcommands/utils/misc.py index c9aeee3..93d5e9b 100644 --- a/src/kiwi/subcommands/utils/misc.py +++ b/src/kiwi/subcommands/utils/misc.py @@ -59,6 +59,14 @@ def _surround(string, bang): return f"{sidelane}\n{midlane}\n{sidelane}" +def _emphasize(lines): + if isinstance(lines, list): + return '\n'.join([_emphasize(line) for line in lines]) + elif lines: + return f">>> {lines} <<<" + else: + return lines + def are_you_sure(prompt, default="no"): if default.lower() == 'yes': suffix = "[YES|no]" @@ -66,9 +74,9 @@ def are_you_sure(prompt, default="no"): suffix = "[yes|NO]" answer = input( - f"{_surround('CAREFULING IN PROGRESS', '!')}\n" + f"{_surround('MUST HAVE CAREFULING IN PROGRESS', '!')}\n" f"\n" - f">>> {prompt} <<<\n" + f"{_emphasize(prompt)}\n" f"\n" f"Are you sure you want to proceed? {suffix} " ).strip().lower()