mirror of
https://github.com/nix-community/disko.git
synced 2026-11-30 21:13:28 +01:00
34 lines
778 B
Python
34 lines
778 B
Python
import subprocess
|
|
|
|
from lib.logging import debug
|
|
from lib.result import DiskoError, DiskoResult, DiskoSuccess
|
|
|
|
|
|
def run(args: list[str]) -> DiskoResult[str]:
|
|
command = " ".join(args)
|
|
debug(f"Running: {command}")
|
|
|
|
result = subprocess.run(args, capture_output=True, text=True)
|
|
|
|
debug(
|
|
f"""
|
|
Ran: {command}
|
|
Exit code: {result.returncode}
|
|
Stdout: {result.stdout}
|
|
Stderr: {result.stderr}
|
|
"""
|
|
)
|
|
|
|
if result.returncode == 0:
|
|
return DiskoSuccess(result.stdout, "run command")
|
|
|
|
return DiskoError.single_message(
|
|
"ERR_COMMAND_FAILED",
|
|
{
|
|
"command": command,
|
|
"stderr": result.stderr,
|
|
"exit_code": result.returncode,
|
|
},
|
|
"run command",
|
|
)
|