From 6adae46a4cf4aed43c050e245c9b48b46a776493 Mon Sep 17 00:00:00 2001 From: octo-dama <101798859+octo-dama@users.noreply.github.com> Date: Wed, 14 Feb 2024 06:50:44 +0100 Subject: [PATCH] Add --yes option for skipping the confirmation prompt while deleting the user via CLI for scripting purpose. #7204 --- docs/en_US/user_management.rst | 3 ++- web/setup.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/en_US/user_management.rst b/docs/en_US/user_management.rst index 2ddb59172..0765f9503 100644 --- a/docs/en_US/user_management.rst +++ b/docs/en_US/user_management.rst @@ -187,11 +187,12 @@ Delete User *********** To delete the user, invoke ``setup.py`` with ``delete-user`` command line option, followed by -username and auth_source. For Internal users, email adress will be used instead of username. +username and auth_source. For Internal users, email adress will be used instead of username. the option ``--yes`` is available to skip the confirmation prompt before deleting the user. .. code-block:: bash /path/to/python /path/to/setup.py delete-user user1@gmail.com --auth-source internal + /path/to/python /path/to/setup.py delete-user user2@gmail.com --auth-source internal --yes /path/to/python /path/to/setup.py delete-user ldapuser --auth-source ldap diff --git a/web/setup.py b/web/setup.py index e8b822175..0dfdf681d 100644 --- a/web/setup.py +++ b/web/setup.py @@ -180,11 +180,15 @@ class ManageUsers: ManageUsers.create_user(data, console, json) @app.command() - def delete_user(username: str, auth_source: AuthType = AuthType.internal): + def delete_user(username: str, + auth_source: AuthType = AuthType.internal, + auto_confirm: Annotated[Optional[bool], + typer.Option( + "--yes")] = False + ): """Delete the user. """ - delete = typer.confirm("Are you sure you want to delete it?") - - if delete: + confirm_msg = "Are you sure you want to delete it?" + if auto_confirm or typer.confirm(confirm_msg): app = create_app(config.APP_NAME + '-cli') with app.test_request_context(): uid = ManageUsers.get_user(username=username,