task.mk/src/confirm.py

33 lines
583 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
###-
# this is just to trick the LSP during development
from utils import a
# -###
2022-09-24 16:20:23 -05:00
##- '$(utils_py)' -##
2022-09-14 16:52:49 -05:00
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"]:
sys.stderr.write(f"""$(2) {a.b_red}[Y/n]{a.end} \n""")
answer = input().lower()
2022-09-14 16:52:49 -05:00
return answer == "y"
2022-09-16 12:47:21 -05:00
2022-09-14 16:52:49 -05:00
if confirm():
sys.exit()
2022-09-14 16:52:49 -05:00
else:
sys.exit(1)
2022-09-14 16:52:49 -05:00
#% endblock %#