task.mk/src/confirm.py

27 lines
470 B
Python
Raw Normal View History

2022-09-14 16:52:49 -05:00
#% extends "py-script.mk" %#
#% block name %#confirm#% endblock %#
#% block script %#
import sys
2022-09-16 12:47:21 -05:00
2022-09-14 16:52:49 -05:00
##- '$(ansi_py)' -##
2022-09-16 12:47:21 -05:00
2022-09-14 16:52:49 -05:00
def confirm():
"""
Ask user to enter Y or N (case-insensitive).
:return: True if the answer is Y.
:rtype: bool
"""
answer = ""
while answer not in ["y", "n"]:
answer = input(f"""$(2) {a.b_red}[Y/n]{a.end} """).lower()
return answer == "y"
2022-09-16 12:47:21 -05:00
2022-09-14 16:52:49 -05:00
if confirm():
sys.exit(0)
else:
sys.exit(1)
#% endblock %#