minor typer adjustments to use typer in error/exception throws
This commit is contained in:
Binary file not shown.
@@ -1,5 +1,8 @@
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import click
|
||||||
import typer
|
import typer
|
||||||
|
|
||||||
args = ["qs", "-c", "zshell"]
|
args = ["qs", "-c", "zshell"]
|
||||||
@@ -9,40 +12,65 @@ app = typer.Typer()
|
|||||||
|
|
||||||
@app.command()
|
@app.command()
|
||||||
def kill():
|
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()
|
@app.command()
|
||||||
def start(no_daemon: bool = False):
|
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()
|
@app.command()
|
||||||
def restart(no_daemon: bool = False):
|
def restart(no_daemon: bool = False):
|
||||||
subprocess.run(args + ["kill"], check=False)
|
subprocess.run(args + ["kill"])
|
||||||
for _ in range(50):
|
for _ in range(50):
|
||||||
result = subprocess.run(args + ["kill"], capture_output=True)
|
result = subprocess.run(args + ["kill"], capture_output=True)
|
||||||
if result.returncode == 255:
|
if result.returncode == 255:
|
||||||
break
|
break
|
||||||
time.sleep(0.05)
|
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()
|
@app.command()
|
||||||
def show():
|
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()
|
@app.command()
|
||||||
def log():
|
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()
|
@app.command()
|
||||||
def lock():
|
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()
|
@app.command()
|
||||||
def call(target: str, method: str, method_args: list[str] = typer.Argument(None)):
|
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())
|
||||||
|
|||||||
Reference in New Issue
Block a user