Step 1 of 4
Name the dangers
Write the patterns down first. Each should have a reason.
import re
RULES = [(r"git\s+reset\s+--hard", "throws away uncommitted work"),
(r"drop\s+table", "deletes a whole table"),
(r"chmod\s+-R\s+777", "lets anyone change every file")]
def check(cmd):
return next((why for pat, why in RULES if re.search(pat, cmd, re.I)), None)
for c in ["git status", "git reset --hard HEAD~3", "psql -c 'DROP TABLE users'", "chmod -R 777 ."]:
print(f"{c:30} -> {check(c) or 'allowed'}")
You are done whenThe safe command passes and the three risky ones are named.
