From add18020a77d9c5c40fdfce854d52a81296bfdcf Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Wed, 10 May 2023 20:45:49 +0200 Subject: rename user fietsctl commands --- fietsboek/scripts/fietsctl.py | 97 +++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 41 deletions(-) diff --git a/fietsboek/scripts/fietsctl.py b/fietsboek/scripts/fietsctl.py index 4255b18..caca0f9 100644 --- a/fietsboek/scripts/fietsctl.py +++ b/fietsboek/scripts/fietsctl.py @@ -38,7 +38,12 @@ def cli(): """CLI main entry point.""" -@cli.command("useradd") +@cli.group("user") +def cmd_user(): + """Management functions for user accounts.""" + + +@cmd_user.command("add") @config_option @click.option("--email", help="email address of the user", prompt=True) @click.option("--name", help="name of the user", prompt=True) @@ -51,7 +56,14 @@ def cli(): ) @click.option("--admin", help="make the new user an admin", is_flag=True) @click.pass_context -def cmd_useradd(ctx: click.Context, config: str, email: str, name: str, password: str, admin: bool): +def cmd_user_add( + ctx: click.Context, + config: str, + email: str, + name: str, + password: str, + admin: bool, +): """Create a new user. This user creation bypasses the "enable_account_registration" setting. It @@ -89,14 +101,14 @@ def cmd_useradd(ctx: click.Context, config: str, email: str, name: str, password click.echo(user_id) -@cli.command("userdel") +@cmd_user.command("del") @config_option @click.option("--force", "-f", help="override the safety check", is_flag=True) @optgroup.group("User selection", cls=RequiredMutuallyExclusiveOptionGroup) @optgroup.option("--id", "-i", "id_", help="database ID of the user", type=int) @optgroup.option("--email", "-e", help="email of the user") @click.pass_context -def cmd_userdel( +def user_del( ctx: click.Context, config: str, force: bool, @@ -131,9 +143,9 @@ def cmd_userdel( click.echo("User deleted") -@cli.command("userlist") +@cmd_user.command("list") @config_option -def cmd_userlist(config: str): +def cmd_user_list(config: str): """Prints a listing of all user accounts. The format is: @@ -156,14 +168,14 @@ def cmd_userlist(config: str): click.echo(f"{tag} {user.id} - {user.email} - {user.name}") -@cli.command("passwd") +@cmd_user.command("passwd") @config_option @click.option("--password", help="password of the user") @optgroup.group("User selection", cls=RequiredMutuallyExclusiveOptionGroup) @optgroup.option("--id", "-i", "id_", help="database ID of the user", type=int) @optgroup.option("--email", "-e", help="email of the user") @click.pass_context -def cmd_passwd( +def cms_user_passwd( ctx: click.Context, config: str, password: Optional[str], @@ -189,38 +201,7 @@ def cmd_passwd( click.echo(f"Changed password of {user.name} ({user.email})") -@cli.command("maintenance-mode") -@config_option -@click.option("--disable", help="disable the maintenance mode", is_flag=True) -@click.argument("reason", required=False) -@click.pass_context -def cmd_maintenance_mode(ctx: click.Context, config: str, disable: bool, reason: Optional[str]): - """Check the status of the maintenance mode, or activate or deactive it. - - When REASON is given, enables the maintenance mode with the given text as - reason. - - With neither --disable nor REASON given, just checks the state of the - maintenance mode. - """ - env = setup(config) - data_manager = env["request"].data_manager - if disable and reason: - click.echo("Cannot enable and disable maintenance mode at the same time", err=True) - ctx.exit(EXIT_FAILURE) - elif not disable and not reason: - maintenance = data_manager.maintenance_mode() - if maintenance is None: - click.echo("Maintenance mode is disabled") - else: - click.echo(f"Maintenance mode is enabled: {maintenance}") - elif disable: - (data_manager.data_dir / "MAINTENANCE").unlink() - else: - (data_manager.data_dir / "MAINTENANCE").write_text(reason, encoding="utf-8") - - -@cli.command("hittekaart") +@cmd_user.command("hittekaart") @config_option @click.option( "--mode", @@ -235,7 +216,7 @@ def cmd_maintenance_mode(ctx: click.Context, config: str, disable: bool, reason: @optgroup.option("--id", "-i", "id_", help="database ID of the user", type=int) @optgroup.option("--email", "-e", help="email of the user") @click.pass_context -def cmd_hittekaart( +def cmd_user_hittekaart( ctx: click.Context, config: str, modes: list[str], @@ -282,8 +263,42 @@ def cmd_hittekaart( click.echo(f"Generated {mode.value}") +@cli.command("maintenance-mode") +@config_option +@click.option("--disable", help="disable the maintenance mode", is_flag=True) +@click.argument("reason", required=False) +@click.pass_context +def cmd_maintenance_mode(ctx: click.Context, config: str, disable: bool, reason: Optional[str]): + """Check the status of the maintenance mode, or activate or deactive it. + + When REASON is given, enables the maintenance mode with the given text as + reason. + + With neither --disable nor REASON given, just checks the state of the + maintenance mode. + """ + env = setup(config) + data_manager = env["request"].data_manager + if disable and reason: + click.echo("Cannot enable and disable maintenance mode at the same time", err=True) + ctx.exit(EXIT_FAILURE) + elif not disable and not reason: + maintenance = data_manager.maintenance_mode() + if maintenance is None: + click.echo("Maintenance mode is disabled") + else: + click.echo(f"Maintenance mode is enabled: {maintenance}") + elif disable: + (data_manager.data_dir / "MAINTENANCE").unlink() + else: + (data_manager.data_dir / "MAINTENANCE").write_text(reason, encoding="utf-8") + + @cli.command("version") def cmd_version(): """Show the installed fietsboek version.""" name = __name__.split(".", 1)[0] print(f"{name} {__VERSION__}") + + +__all__ = ["cli"] -- cgit v1.2.3