Fix some bug related to DEBUG variable

This commit is contained in:
Sarina
2024-08-06 00:13:54 +03:30
parent c0abbae31e
commit 3974f89429
2 changed files with 11 additions and 8 deletions

View File

@ -42,10 +42,13 @@ def run_cmd(command: list[str]):
Runs a command and returns the output. Runs a command and returns the output.
Could raise subprocess.CalledProcessError Could raise subprocess.CalledProcessError
''' '''
if DEBUG and Command.GET_USER.value not in command and Command.LIST_USERS.value not in command:
# if the command is GET_USER or LIST_USERS we don't print the debug-command and just print the output
if DEBUG and not (Command.GET_USER.value in command or Command.LIST_USERS.value in command):
print(' '.join(command)) print(' '.join(command))
result = subprocess.check_output(command, shell=False) result = subprocess.check_output(command, shell=False)
if DEBUG:
print(result.decode().strip()) print(result.decode().strip())
@ -174,7 +177,6 @@ def edit_user(username: str, new_username: str, new_traffic_limit: int, new_expi
run_cmd(command_args) run_cmd(command_args)
@ cli.command('remove-user') @ cli.command('remove-user')
@ click.option('--username', '-u', required=True, help='Username for the user to remove', type=str) @ click.option('--username', '-u', required=True, help='Username for the user to remove', type=str)
def remove_user(username: str): def remove_user(username: str):
@ -196,6 +198,7 @@ def traffic_status():
def list_users(): def list_users():
run_cmd(['bash', Command.LIST_USERS.value]) run_cmd(['bash', Command.LIST_USERS.value])
@cli.command('server-info') @cli.command('server-info')
def server_info(): def server_info():
output = run_cmd(['bash', Command.SERVER_INFO.value]) output = run_cmd(['bash', Command.SERVER_INFO.value])

View File

@ -150,7 +150,7 @@ hysteria2_get_user_handler() {
done done
# Run the command and suppress error output # Run the command and suppress error output
if ! python3 "$CLI_PATH" get-user --username "$username" > /dev/null 2>&1; then if ! python3 "$CLI_PATH" get-user --username "$username" 2>/dev/null; then
echo -e "${red}Error:${NC} User '$username' not found." echo -e "${red}Error:${NC} User '$username' not found."
return 1 return 1
fi fi
@ -293,7 +293,7 @@ display_hysteria2_menu() {
echo -e "${cyan}[3] ${NC}↝ Edit User" echo -e "${cyan}[3] ${NC}↝ Edit User"
echo -e "${cyan}[4] ${NC}↝ Remove User" echo -e "${cyan}[4] ${NC}↝ Remove User"
echo -e "${cyan}[5] ${NC}↝ Get User" echo -e "${cyan}[5] ${NC}↝ Get User"
echo -e "${cyan}[6] ${NC}↝ List Users (WIP)" echo -e "${cyan}[6] ${NC}↝ List Users"
echo -e "${cyan}[7] ${NC}↝ Check Traffic Status" echo -e "${cyan}[7] ${NC}↝ Check Traffic Status"
echo -e "${cyan}[8] ${NC}↝ Show User URI" echo -e "${cyan}[8] ${NC}↝ Show User URI"