ulwlg_run.py: Capture and return the exit code of the subprocess

* Return the exitcode of the subprocess from `main` in case the caller
wants to do something this it.

* Catch any exceptions during execution and return an error exitcode.
This commit is contained in:
Stelios Tsampas 2024-02-19 14:55:08 +02:00
parent a7c38855bc
commit 709e0bd67a

View File

@ -2,6 +2,7 @@
import os
import argparse
from traceback import print_exception
from argparse import ArgumentParser, Namespace
import sys
from pathlib import Path
@ -281,7 +282,7 @@ def build_command(
return command
def main() -> None: # noqa: D103
def main() -> int: # noqa: D103
env: Dict[str, str] = {
"WINEPREFIX": "",
"GAMEID": "",
@ -327,8 +328,12 @@ def main() -> None: # noqa: D103
os.environ[key] = val
build_command(env, command, opts)
subprocess.run(command)
return subprocess.run(command).returncode
if __name__ == "__main__":
main()
try:
sys.exit(main())
except Exception as e: # noqa: BLE001
print_exception(e)
sys.exit(1)