mirror of
https://github.com/karma-riuk/crab.git
synced 2025-07-05 05:28:13 +02:00
prompts can now have a default value when enter is
pressed
This commit is contained in:
10
utils.py
10
utils.py
@ -166,12 +166,18 @@ def run_git_cmd(cmd: list[str], repo_path: str) -> subprocess.CompletedProcess:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def prompt_yes_no(prompt: str) -> bool:
|
def prompt_yes_no(prompt: str, *, default: bool | None = None) -> bool:
|
||||||
|
choices = "y/n"
|
||||||
|
if default is not None:
|
||||||
|
choices = "Y/n" if default else "y/N"
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
ans = input(f"{prompt} [y/n]: ").strip().lower()
|
ans = input(f"{prompt} [{choices}]: ").strip().lower()
|
||||||
if ans in {"y", "yes"}:
|
if ans in {"y", "yes"}:
|
||||||
return True
|
return True
|
||||||
elif ans in {"n", "no"}:
|
elif ans in {"n", "no"}:
|
||||||
return False
|
return False
|
||||||
|
elif default is not None:
|
||||||
|
return default
|
||||||
else:
|
else:
|
||||||
print("Please enter 'y' or 'n'.")
|
print("Please enter 'y' or 'n'.")
|
||||||
|
Reference in New Issue
Block a user