Revert CLI Change
This commit is contained in:
@ -83,34 +83,24 @@ class ScriptNotFoundError(HysteriaError):
|
|||||||
# region Utils
|
# region Utils
|
||||||
|
|
||||||
|
|
||||||
def run_cmd(command: list[str]) -> str:
|
def run_cmd(command: list[str]) -> str | None:
|
||||||
'''
|
'''
|
||||||
Runs a command and returns its stdout if successful.
|
Runs a command and returns the output.
|
||||||
Raises CommandExecutionError if the command fails (non-zero exit code) or cannot be found.
|
Could raise subprocess.CalledProcessError
|
||||||
'''
|
'''
|
||||||
if DEBUG:
|
if (DEBUG) and not (Command.GET_USER.value in command or Command.LIST_USERS.value in command):
|
||||||
print(f"Executing command: {' '.join(command)}")
|
print(' '.join(command))
|
||||||
try:
|
try:
|
||||||
process = subprocess.run(command, capture_output=True, text=True, shell=False, check=False)
|
result = subprocess.check_output(command, stderr=subprocess.STDOUT, shell=False)
|
||||||
|
if result:
|
||||||
if process.returncode != 0:
|
result = result.decode().strip()
|
||||||
error_output = process.stderr.strip() if process.stderr.strip() else process.stdout.strip()
|
return result
|
||||||
if not error_output:
|
except subprocess.CalledProcessError as e:
|
||||||
error_output = f"Command exited with status {process.returncode} without specific error message."
|
if DEBUG:
|
||||||
|
raise CommandExecutionError(f'Command execution failed: {e}\nOutput: {e.output.decode()}')
|
||||||
detailed_error_message = f"Command '{' '.join(command)}' failed with exit code {process.returncode}: {error_output}"
|
else:
|
||||||
raise CommandExecutionError(detailed_error_message)
|
return None
|
||||||
|
return None
|
||||||
return process.stdout.strip() if process.stdout else ""
|
|
||||||
|
|
||||||
except FileNotFoundError as e:
|
|
||||||
raise ScriptNotFoundError(f"Script or command not found: {command[0]}. Original error: {e}")
|
|
||||||
except subprocess.TimeoutExpired as e:
|
|
||||||
raise CommandExecutionError(f"Command '{' '.join(command)}' timed out. Original error: {e}")
|
|
||||||
except OSError as e:
|
|
||||||
raise CommandExecutionError(f"OS error while trying to run command '{' '.join(command)}': {e}")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def generate_password() -> str:
|
def generate_password() -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user