Skip to content

Commit 18b6a84

Browse files
committed
use proper exit codes
1 parent 3d0a825 commit 18b6a84

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

qbpm/main.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
from .utils import SUPPORTED_MENUS, default_profile_dir, error
1212

1313

14+
def exit_with(result: bool):
15+
exit(0 if result else 1)
16+
17+
1418
@click.group()
1519
@click.option(
1620
"-P",
@@ -40,7 +44,8 @@ def new(ctx, profile_name: str, launch: bool, foreground: bool, **kwargs):
4044
result = profiles.new_profile(profile, **kwargs)
4145
if result and launch:
4246
# TODO args?
43-
then_launch(profile, foreground, [])
47+
exit_with(then_launch(profile, foreground, []))
48+
exit_with(result)
4449

4550

4651
@main.command()
@@ -60,7 +65,8 @@ def from_session(
6065
profile = operations.from_session(profile_dir=ctx.obj["PROFILE_DIR"], **kwargs)
6166
if profile and launch:
6267
# TODO args?
63-
then_launch(profile, foreground, [])
68+
exit_with(then_launch(profile, foreground, []))
69+
exit_with(bool(profile))
6470

6571

6672
@main.command()
@@ -71,7 +77,7 @@ def desktop(
7177
profile_name: str,
7278
):
7379
profile = Profile(profile_name, ctx.obj["PROFILE_DIR"])
74-
return operations.desktop(profile)
80+
exit_with(operations.desktop(profile))
7581

7682

7783
@main.command()
@@ -82,7 +88,7 @@ def desktop(
8288
def launch(ctx, profile_name: str, **kwargs):
8389
profile = Profile(profile_name, ctx.obj["PROFILE_DIR"])
8490
# TODO qb args
85-
return operations.launch(profile, **kwargs)
91+
exit_with(operations.launch(profile, **kwargs))
8692

8793

8894
@main.command()
@@ -91,7 +97,9 @@ def launch(ctx, profile_name: str, **kwargs):
9197
@click.pass_context
9298
def choose(ctx, **kwargs):
9399
# TODO qb args
94-
return operations.choose(profile_dir=ctx.obj["PROFILE_DIR"], qb_args=[], **kwargs)
100+
exit_with(
101+
operations.choose(profile_dir=ctx.obj["PROFILE_DIR"], qb_args=[], **kwargs)
102+
)
95103

96104

97105
@main.command()
@@ -102,7 +110,7 @@ def edit(ctx, profile_name):
102110
profile = Profile(profile_name, ctx.obj["PROFILE_DIR"])
103111
if not profile.exists():
104112
error(f"profile {profile.name} not found at {profile.root}")
105-
return False
113+
exit(1)
106114
click.edit(filename=profile.root / "config" / "config.py")
107115

108116

@@ -111,10 +119,9 @@ def edit(ctx, profile_name):
111119
def list_(ctx):
112120
for profile in sorted(ctx.obj["PROFILE_DIR"].iterdir()):
113121
print(profile.name)
114-
return True
115122

116123

117-
def then_launch(profile: Profile, foreground: bool, qb_args: list[str]):
124+
def then_launch(profile: Profile, foreground: bool, qb_args: list[str]) -> bool:
118125
result = False
119126
if profile:
120127
result = operations.launch(profile, False, foreground, qb_args)

0 commit comments

Comments
 (0)