Skip to content

Instantly share code, notes, and snippets.

@olivierphi
Last active September 15, 2023 08:48
Show Gist options
  • Save olivierphi/fee7671ddc8a1dad24809477afef6e98 to your computer and use it in GitHub Desktop.
Save olivierphi/fee7671ddc8a1dad24809477afef6e98 to your computer and use it in GitHub Desktop.
quick confirm script to pipe in a terminal
#!/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