feat(cli): add note option to add-user command

This commit is contained in:
ReturnFI
2025-10-28 16:08:49 +00:00
parent 1f15d09f31
commit ea75084eeb
2 changed files with 10 additions and 4 deletions

View File

@ -131,9 +131,10 @@ def get_user(username: str):
@click.option('--password', '-p', required=False, help='Password for the user', type=str) @click.option('--password', '-p', required=False, help='Password for the user', type=str)
@click.option('--creation-date', '-c', required=False, help='Creation date for the user (YYYY-MM-DD)', type=str) @click.option('--creation-date', '-c', required=False, help='Creation date for the user (YYYY-MM-DD)', type=str)
@click.option('--unlimited', is_flag=True, default=False, help='Exempt user from IP limit checks.') @click.option('--unlimited', is_flag=True, default=False, help='Exempt user from IP limit checks.')
def add_user(username: str, traffic_limit: int, expiration_days: int, password: str, creation_date: str, unlimited: bool): @click.option('--note', '-n', required=False, help='An optional note for the user', type=str)
def add_user(username: str, traffic_limit: int, expiration_days: int, password: str, creation_date: str, unlimited: bool, note: str):
try: try:
cli_api.add_user(username, traffic_limit, expiration_days, password, creation_date, unlimited) cli_api.add_user(username, traffic_limit, expiration_days, password, creation_date, unlimited, note)
click.echo(f"User '{username}' added successfully.") click.echo(f"User '{username}' added successfully.")
except Exception as e: except Exception as e:
click.echo(f'{e}', err=True) click.echo(f'{e}', err=True)

View File

@ -269,13 +269,18 @@ def get_user(username: str) -> dict[str, Any] | None:
return json.loads(res) return json.loads(res)
def add_user(username: str, traffic_limit: int, expiration_days: int, password: str | None, creation_date: str | None, unlimited: bool): def add_user(username: str, traffic_limit: int, expiration_days: int, password: str | None, creation_date: str | None, unlimited: bool, note: str | None):
''' '''
Adds a new user with the given parameters, respecting positional argument requirements. Adds a new user with the given parameters, respecting positional argument requirements.
''' '''
command = ['python3', Command.ADD_USER.value, username, str(traffic_limit), str(expiration_days)] command = ['python3', Command.ADD_USER.value, username, str(traffic_limit), str(expiration_days)]
if unlimited: if note:
final_password = password if password else generate_password()
final_creation_date = creation_date if creation_date else datetime.now().strftime('%Y-%m-%d')
unlimited_str = 'true' if unlimited else 'false'
command.extend([final_password, final_creation_date, unlimited_str, note])
elif unlimited:
final_password = password if password else generate_password() final_password = password if password else generate_password()
final_creation_date = creation_date if creation_date else datetime.now().strftime('%Y-%m-%d') final_creation_date = creation_date if creation_date else datetime.now().strftime('%Y-%m-%d')
command.extend([final_password, final_creation_date, 'true']) command.extend([final_password, final_creation_date, 'true'])