neater prompts

This commit is contained in:
Jörn-Michael Miehe 2020-08-18 15:05:19 +02:00
parent 679a47e4fa
commit 81b597cb58
3 changed files with 29 additions and 3 deletions

View file

@ -14,7 +14,12 @@ class DownCommand(FlexCommand):
) )
def _run_instance(self, runner, config, args): 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 super()._run_instance(runner, config, args)
return False return False

View file

@ -1,5 +1,6 @@
# local # local
from ._subcommand import FlexCommand from ._subcommand import FlexCommand
from .utils.misc import are_you_sure
class UpdateCommand(FlexCommand): class UpdateCommand(FlexCommand):
@ -11,6 +12,18 @@ class UpdateCommand(FlexCommand):
description="Update the whole instance, a project or service(s) inside a project" 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): def _run_services(self, runner, config, args, services):
result = runner.run('build') result = runner.run('build')
result &= runner.run('pull') result &= runner.run('pull')

View file

@ -59,6 +59,14 @@ def _surround(string, bang):
return f"{sidelane}\n{midlane}\n{sidelane}" 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"): def are_you_sure(prompt, default="no"):
if default.lower() == 'yes': if default.lower() == 'yes':
suffix = "[YES|no]" suffix = "[YES|no]"
@ -66,9 +74,9 @@ def are_you_sure(prompt, default="no"):
suffix = "[yes|NO]" suffix = "[yes|NO]"
answer = input( answer = input(
f"{_surround('CAREFULING IN PROGRESS', '!')}\n" f"{_surround('MUST HAVE CAREFULING IN PROGRESS', '!')}\n"
f"\n" f"\n"
f">>> {prompt} <<<\n" f"{_emphasize(prompt)}\n"
f"\n" f"\n"
f"Are you sure you want to proceed? {suffix} " f"Are you sure you want to proceed? {suffix} "
).strip().lower() ).strip().lower()