Last active
September 15, 2023 08:48
-
-
Save olivierphi/fee7671ddc8a1dad24809477afef6e98 to your computer and use it in GitHub Desktop.
quick confirm script to pipe in a terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
import sys | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
"-l", | |
"--level", | |
choices=("e", "m", "h"), | |
default="m", | |
help="confirmation difficulty: e(asy), m(edium), h(ard)", | |
) | |
args = parser.parse_args() | |
match args.level: | |
case "e": | |
expected_confirmation = "[y/N]", "y" | |
case "m": | |
expected_confirmation = """["I confirm"]""", "I confirm" | |
case "h": | |
from datetime import date | |
today = date.today().isoformat() | |
expected_confirmation = f"[{today}]", today | |
case _: | |
raise ValueError(f"Unhandled confirmation difficuly {args.level}") | |
res = input(f"Confirm? {expected_confirmation[0]} ") | |
sys.exit(0 if res.strip() == expected_confirmation[1] else 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment