finished the config

This commit is contained in:
Hellow
2024-02-11 19:00:48 +01:00
parent 22e49aa83c
commit b4926729d6
7 changed files with 125 additions and 10 deletions

View File

@@ -0,0 +1,19 @@
from pathlib import Path
import platformdirs
PROGRAM_NAME: str = "publish-meetups"
class Paths:
CONFIG_PATH: Path = Path(platformdirs.user_config_path(appname=PROGRAM_NAME))
Paths.CONFIG_PATH.mkdir(parents=True, exist_ok=True)
__all__ = ["prompt", "CONFIG_PATH", "PROGRAM_NAME", "errors"]

View File

@@ -0,0 +1,4 @@
class InvalidCredential(Exception):
def __init__(self, message):
super().__init__(message)

View File

@@ -0,0 +1,21 @@
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()
result = _real_prompt
print("> " + result)
return result
def for_password(msg: str) -> str:
return getpass.getpass(msg + ': ').strip()