Notes, improve args, some UX

This commit is contained in:
2026-04-07 18:13:03 +02:00
parent 6ebae74f93
commit 6e497fdfd2
8 changed files with 80 additions and 17 deletions

30
commands/util/choice.py Normal file
View File

@@ -0,0 +1,30 @@
from typing import Optional
def choice(default: str, options: str, msg: str) -> str:
default = default.lower()
formatted_options = "".join(
[(opt + "/" if opt != default else default.upper() + "/") for opt in options]
)[:-1]
choice = input(msg + " [" + formatted_options + "] ")
if choice == "":
return default
else:
return choice.lower()
def confirm(is_true_default: bool, msg: Optional[str] = ""):
return (
choice(
"y" if is_true_default else "n",
"yn",
(msg if msg != "" and msg != None else "Do you really want to continue?"),
)
== "y"
)
def confirm_overwrite(msg: Optional[str] = ""):
return confirm(
False, (msg if msg != "" else "Do you really want to overwrite your changes?")
)