Notes, improve args, some UX
This commit is contained in:
30
commands/util/choice.py
Normal file
30
commands/util/choice.py
Normal 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?")
|
||||
)
|
||||
Reference in New Issue
Block a user