diff options
Diffstat (limited to 'webmentions_ssg/cli.py')
| -rw-r--r-- | webmentions_ssg/cli.py | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/webmentions_ssg/cli.py b/webmentions_ssg/cli.py index 5c2d534..225a39f 100644 --- a/webmentions_ssg/cli.py +++ b/webmentions_ssg/cli.py @@ -13,14 +13,14 @@ from flask_migrate import upgrade as migrate_upgrade from sqlalchemy import inspect from sqlalchemy.exc import IntegrityError -from .auth import validate_password +from .auth import validate_new_password from .extensions import db, mail from .models import User USERS_CLI = AppGroup("users", help="Manage users.") -def _require_user(username: str): +def _get_user_or_fail(username: str): """Return a user by username or report a CLI-friendly error. :param username: Username to look up in the database. @@ -48,7 +48,7 @@ def create_user(username: str, password: str) -> None: raise click.ClickException("Username must not be empty.") try: - validate_password(password) + validate_new_password(password) except ValueError as exc: raise click.ClickException(str(exc)) from exc @@ -89,11 +89,11 @@ def set_user_password(username: str, password: str) -> None: :raises click.ClickException: If the account is missing or the password is invalid. """ try: - validate_password(password) + validate_new_password(password) except ValueError as exc: raise click.ClickException(str(exc)) from exc - user = _require_user(username) + user = _get_user_or_fail(username) user.password = password db.session.commit() click.echo(f"Updated password for user {username!r}.") @@ -109,7 +109,7 @@ def delete_user(username: str, yes: bool) -> None: :param yes: Whether to skip the confirmation prompt. :raises click.ClickException: If the account does not exist. """ - user = _require_user(username) + user = _get_user_or_fail(username) if not yes: click.confirm(f"Delete user {username!r}?", abort=True) @@ -122,19 +122,17 @@ MAIL_CLI = AppGroup("mail", help="Handle mail") @MAIL_CLI.command("test", help="Send an email to test the SMTP configuration") -@click.option( - "--to", "recipient", help="Recipient address (defaults to NOTIFICATION_EMAIL)." -) +@click.option("--to", "recipient", help="Recipient address (defaults to DIGEST_EMAIL).") def send_test_mail(recipient: str | None) -> None: """Send a test email using the configured SMTP server. - :param recipient: Optional recipient overriding NOTIFICATION_EMAIL. + :param recipient: Optional recipient overriding DIGEST_EMAIL. :raises click.ClickException: If configuration is missing or sending fails. """ - recipient = recipient or current_app.config.get("NOTIFICATION_EMAIL") + recipient = recipient or current_app.config.get("DIGEST_EMAIL") if not recipient: raise click.ClickException( - "No recipient specified. Set NOTIFICATION_EMAIL or pass --to." + "No recipient specified. Set DIGEST_EMAIL or pass --to." ) sender = current_app.config.get("MAIL_DEFAULT_SENDER") @@ -162,7 +160,7 @@ def send_test_mail(recipient: str | None) -> None: DB_CLI = AppGroup("db", help="Handle database") -def _table_names() -> set[str]: +def _existing_table_names() -> set[str]: """Return existing table names without modifying the database schema. :returns: Names of tables in the configured database. @@ -179,7 +177,7 @@ def create_db() -> None: :raises click.ClickException: If the database already contains tables. """ - if _table_names(): + if _existing_table_names(): raise click.ClickException( "The database already contains tables. " "Use 'flask db upgrade' for an existing migrated database." @@ -198,7 +196,7 @@ def upgrade_db() -> None: :raises click.ClickException: If the database has no Alembic revision table. """ - if "alembic_version" not in _table_names(): + if "alembic_version" not in _existing_table_names(): raise click.ClickException( "No Flask-Migrate revision table found. " "For a new, empty database run 'flask db create-db'. " |
