Refactor cli_api.py and cli.py

This commit is contained in:
Iam54r1n4
2025-01-26 12:50:14 +00:00
parent 403ec33648
commit 772096922d
2 changed files with 9 additions and 9 deletions

View File

@ -80,9 +80,9 @@ def change_hysteria2_sni(sni: str):
@cli.command('backup-hysteria') @cli.command('backup-hysteria')
def backup_hysteria(): def backup_hysteria2():
try: try:
cli_api.backup_hysteria() cli_api.backup_hysteria2()
click.echo("Hysteria configuration backed up successfully.") click.echo("Hysteria configuration backed up successfully.")
except Exception as e: except Exception as e:
click.echo(f'{e}', err=True) click.echo(f'{e}', err=True)
@ -216,10 +216,10 @@ def manage_obfs(remove: bool, generate: bool):
if remove and generate: if remove and generate:
raise click.UsageError('Error: You cannot use both --remove and --generate at the same time') raise click.UsageError('Error: You cannot use both --remove and --generate at the same time')
elif generate: elif generate:
cli_api.generate_hysteria_obfs() cli_api.enable_hysteria2_obfs()
click.echo("Obfs generated successfully.") click.echo("Obfs generated successfully.")
elif remove: elif remove:
cli_api.remove_hysteria_obfs() cli_api.disable_hysteria2_obfs()
click.echo("Obfs removed successfully.") click.echo("Obfs removed successfully.")
except Exception as e: except Exception as e:
click.echo(f'{e}', err=True) click.echo(f'{e}', err=True)

View File

@ -30,7 +30,7 @@ class Command(Enum):
UPDATE_GEO = os.path.join(SCRIPT_DIR, 'hysteria2', 'update_geo.py') UPDATE_GEO = os.path.join(SCRIPT_DIR, 'hysteria2', 'update_geo.py')
LIST_USERS = os.path.join(SCRIPT_DIR, 'hysteria2', 'list_users.sh') LIST_USERS = os.path.join(SCRIPT_DIR, 'hysteria2', 'list_users.sh')
SERVER_INFO = os.path.join(SCRIPT_DIR, 'hysteria2', 'server_info.sh') SERVER_INFO = os.path.join(SCRIPT_DIR, 'hysteria2', 'server_info.sh')
BACKUP_HYSTERIA = os.path.join(SCRIPT_DIR, 'hysteria2', 'backup.sh') BACKUP_HYSTERIA2 = os.path.join(SCRIPT_DIR, 'hysteria2', 'backup.sh')
INSTALL_TELEGRAMBOT = os.path.join(SCRIPT_DIR, 'telegrambot', 'runbot.sh') INSTALL_TELEGRAMBOT = os.path.join(SCRIPT_DIR, 'telegrambot', 'runbot.sh')
INSTALL_SINGBOX = os.path.join(SCRIPT_DIR, 'singbox', 'singbox_shell.sh') INSTALL_SINGBOX = os.path.join(SCRIPT_DIR, 'singbox', 'singbox_shell.sh')
INSTALL_NORMALSUB = os.path.join(SCRIPT_DIR, 'normalsub', 'normalsub.sh') INSTALL_NORMALSUB = os.path.join(SCRIPT_DIR, 'normalsub', 'normalsub.sh')
@ -143,17 +143,17 @@ def change_hysteria2_sni(sni: str):
run_cmd(['bash', Command.CHANGE_SNI_HYSTERIA2.value, sni]) run_cmd(['bash', Command.CHANGE_SNI_HYSTERIA2.value, sni])
def backup_hysteria(): def backup_hysteria2():
'''Backups Hysteria configuration.''' '''Backups Hysteria configuration.'''
run_cmd(['bash', Command.BACKUP_HYSTERIA.value]) run_cmd(['bash', Command.BACKUP_HYSTERIA2.value])
def generate_hysteria_obfs(): def enable_hysteria2_obfs():
'''Generates 'obfs' in Hysteria2 configuration.''' '''Generates 'obfs' in Hysteria2 configuration.'''
run_cmd(['bash', Command.MANAGE_OBFS.value, '--generate']) run_cmd(['bash', Command.MANAGE_OBFS.value, '--generate'])
def remove_hysteria_obfs(): def disable_hysteria2_obfs():
'''Removes 'obfs' from Hysteria2 configuration.''' '''Removes 'obfs' from Hysteria2 configuration.'''
run_cmd(['bash', Command.MANAGE_OBFS.value, '--remove']) run_cmd(['bash', Command.MANAGE_OBFS.value, '--remove'])