publish-meetups/publish_meetups/utils/prompt.py

22 lines
479 B
Python
Raw Normal View History

2024-02-11 18:00:48 +00:00
from typing import Optional
from getpass import getpass
def for_string(msg: str, default: Optional[str] = None) -> str:
def _real_prompt() -> str:
nonlocal msg, default
if default is not None:
return input(f"{msg} [{default}]: ").strip() or default
return input(msg + ': ').strip()
2024-02-11 19:48:45 +00:00
result = _real_prompt()
2024-02-11 18:00:48 +00:00
print("> " + result)
return result
def for_password(msg: str) -> str:
2024-02-11 19:48:45 +00:00
return getpass(msg + ': ').strip()