diff --git a/cli/src/zshell/subcommands/__pycache__/shell.cpython-314.pyc b/cli/src/zshell/subcommands/__pycache__/shell.cpython-314.pyc index 7f6e764..a337671 100644 Binary files a/cli/src/zshell/subcommands/__pycache__/shell.cpython-314.pyc and b/cli/src/zshell/subcommands/__pycache__/shell.cpython-314.pyc differ diff --git a/cli/src/zshell/subcommands/shell.py b/cli/src/zshell/subcommands/shell.py index ae73d0b..d66ea57 100644 --- a/cli/src/zshell/subcommands/shell.py +++ b/cli/src/zshell/subcommands/shell.py @@ -1,5 +1,8 @@ import subprocess +import sys import time + +import click import typer args = ["qs", "-c", "zshell"] @@ -9,40 +12,65 @@ app = typer.Typer() @app.command() def kill(): - subprocess.run(args + ["kill"], check=False) + result = subprocess.run(args + ["kill"], capture_output=True) + if result.returncode != 0: + raise click.ClickException("No running instance to kill.") + sys.stderr.write(result.stderr.decode()) @app.command() def start(no_daemon: bool = False): - subprocess.run(args + ["-n"] + ([] if no_daemon else ["-d"]), check=True) + check = subprocess.run(args + ["ipc"] + ["show"], capture_output=True) + if check.returncode == 0: + raise click.ClickException("An instance of this configuration is already running.") + result = subprocess.run(args + ["-n"] + ([] if no_daemon else ["-d"]), capture_output=True) + if result.returncode != 0: + raise click.ClickException(result.stderr.decode().strip()) + sys.stderr.write(result.stderr.decode()) @app.command() def restart(no_daemon: bool = False): - subprocess.run(args + ["kill"], check=False) + subprocess.run(args + ["kill"]) for _ in range(50): result = subprocess.run(args + ["kill"], capture_output=True) if result.returncode == 255: break time.sleep(0.05) - subprocess.run(args + ["-n"] + ([] if no_daemon else ["-d"]), check=True) + result = subprocess.run(args + ["-n"] + ([] if no_daemon else ["-d"]), capture_output=True) + if result.returncode != 0: + raise click.ClickException(result.stderr.decode().strip()) + sys.stderr.write(result.stderr.decode()) @app.command() def show(): - subprocess.run(args + ["ipc"] + ["show"], check=True) + result = subprocess.run(args + ["ipc"] + ["show"], capture_output=True) + if result.returncode != 0: + raise click.ClickException(result.stderr.decode().strip()) + sys.stderr.write(result.stderr.decode()) @app.command() def log(): - subprocess.run(args + ["log"], check=True) + result = subprocess.run(args + ["log"], capture_output=True) + if result.returncode != 0: + raise click.ClickException(result.stderr.decode().strip()) + sys.stdout.write(result.stdout.decode()) + sys.stderr.write(result.stderr.decode()) @app.command() def lock(): - subprocess.run(args + ["ipc"] + ["call"] + ["lock"] + ["lock"], check=True) + result = subprocess.run(args + ["ipc"] + ["call"] + ["lock"] + ["lock"], capture_output=True) + if result.returncode != 0: + raise click.ClickException(result.stderr.decode().strip()) + sys.stderr.write(result.stderr.decode()) @app.command() def call(target: str, method: str, method_args: list[str] = typer.Argument(None)): - subprocess.run(args + ["ipc"] + ["call"] + [target] + [method] + (method_args or []), check=True) + result = subprocess.run(args + ["ipc"] + ["call"] + [target] + [method] + (method_args or []), capture_output=True) + if result.returncode != 0: + raise click.ClickException(result.stderr.decode().strip()) + sys.stderr.write(result.stderr.decode())