feat: Add --check flag to manage_obfs CLI command

Integrates the OBFS status check functionality into the main CLI.
Users can now use `cli.py manage_obfs --check` to see if OBFS is active.
This commit is contained in:
Whispering Wind
2025-06-02 00:16:41 +03:30
committed by GitHub
parent 3ddb981077
commit 228e01f6e9
2 changed files with 17 additions and 7 deletions

View File

@ -250,19 +250,25 @@ def server_info():
@cli.command('manage_obfs')
@click.option('--remove', '-r', is_flag=True, help="Remove 'obfs' from config.json.")
@click.option('--generate', '-g', is_flag=True, help="Generate new 'obfs' in config.json.")
def manage_obfs(remove: bool, generate: bool):
@click.option('--check', '-c', is_flag=True, help="Check 'obfs' status in config.json.")
def manage_obfs(remove: bool, generate: bool, check: bool):
try:
if not remove and not generate:
raise click.UsageError('Error: You must use either --remove or --generate')
if remove and generate:
raise click.UsageError('Error: You cannot use both --remove and --generate at the same time')
options_selected = sum([remove, generate, check])
if options_selected == 0:
raise click.UsageError('Error: You must use either --remove, --generate, or --check.')
if options_selected > 1:
raise click.UsageError('Error: You can only use one of --remove, --generate, or --check at a time.')
if generate:
cli_api.enable_hysteria2_obfs()
click.echo('Obfs enabled successfully.')
click.echo('OBFS enabled successfully.')
elif remove:
cli_api.disable_hysteria2_obfs()
click.echo('Obfs disabled successfully.')
click.echo('OBFS disabled successfully.')
elif check:
status_output = cli_api.check_hysteria2_obfs()
click.echo(status_output)
except Exception as e:
click.echo(f'{e}', err=True)