mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-04 15:09:22 +02:00
Server CLI: user management
This commit is contained in:
parent
900fabae79
commit
654d206033
13 changed files with 700 additions and 1 deletions
65
api/funkwhale_api/cli/base.py
Normal file
65
api/funkwhale_api/cli/base.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
import click
|
||||
import functools
|
||||
|
||||
|
||||
@click.group()
|
||||
def cli():
|
||||
pass
|
||||
|
||||
|
||||
def confirm_action(f, id_var, message_template="Do you want to proceed?"):
|
||||
@functools.wraps(f)
|
||||
def action(*args, **kwargs):
|
||||
if id_var:
|
||||
id_value = kwargs[id_var]
|
||||
message = message_template.format(len(id_value))
|
||||
else:
|
||||
message = message_template
|
||||
if not kwargs.pop("no_input", False) and not click.confirm(message, abort=True):
|
||||
return
|
||||
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return action
|
||||
|
||||
|
||||
def delete_command(
|
||||
group,
|
||||
id_var="id",
|
||||
name="rm",
|
||||
message_template="Do you want to delete {} objects? This action is irreversible.",
|
||||
):
|
||||
"""
|
||||
Wrap a command to ensure it asks for confirmation before deletion, unless the --no-input
|
||||
flag is provided
|
||||
"""
|
||||
|
||||
def decorator(f):
|
||||
decorated = click.option("--no-input", is_flag=True)(f)
|
||||
decorated = confirm_action(
|
||||
decorated, id_var=id_var, message_template=message_template
|
||||
)
|
||||
return group.command(name)(decorated)
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
def update_command(
|
||||
group,
|
||||
id_var="id",
|
||||
name="set",
|
||||
message_template="Do you want to update {} objects? This action may have irreversible consequnces.",
|
||||
):
|
||||
"""
|
||||
Wrap a command to ensure it asks for confirmation before deletion, unless the --no-input
|
||||
flag is provided
|
||||
"""
|
||||
|
||||
def decorator(f):
|
||||
decorated = click.option("--no-input", is_flag=True)(f)
|
||||
decorated = confirm_action(
|
||||
decorated, id_var=id_var, message_template=message_template
|
||||
)
|
||||
return group.command(name)(decorated)
|
||||
|
||||
return decorator
|
Loading…
Add table
Add a link
Reference in a new issue