Skip to content

Commit 88f06c5

Browse files
committed
Use click.UsageError in more places
1 parent 55a6eaf commit 88f06c5

File tree

8 files changed

+13
-29
lines changed

8 files changed

+13
-29
lines changed

plain-code/plain/code/cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ def fix(ctx, path, unsafe_fixes, add_noqa):
100100
ruff_args.extend(["--exclude", e])
101101

102102
if unsafe_fixes and add_noqa:
103-
print("Cannot use both --unsafe-fixes and --add-noqa")
104-
sys.exit(1)
103+
raise click.UsageError("Cannot use both --unsafe-fixes and --add-noqa")
105104

106105
if unsafe_fixes:
107106
print_event("Ruff fix (with unsafe fixes)")

plain-dev/plain/dev/cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ def logs(follow, pid, path, services):
261261
def entrypoint(show_list, entrypoint):
262262
"""Entrypoints registered under plain.dev"""
263263
if not show_list and not entrypoint:
264-
click.secho("Please provide an entrypoint name or use --list", fg="red")
265-
sys.exit(1)
264+
raise click.UsageError("Please provide an entrypoint name or use --list")
266265

267266
for entry_point in entry_points().select(group=ENTRYPOINT_GROUP):
268267
if show_list:

plain-dev/plain/dev/contribute/cli.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ def cli(packages, repo, reset, all_packages):
9696
elif package.startswith("plainx-"):
9797
plainx_packages.append(str(repo))
9898
else:
99-
click.secho(f"Unknown package {package}", fg="red")
100-
sys.exit(2)
99+
raise click.UsageError(f"Unknown package {package}")
101100

102101
if plain_packages:
103102
result = subprocess.run(["uv", "add", "--editable", "--dev"] + plain_packages)

plain-models/plain/models/backups/cli.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,10 @@ def restore_backup(backup_name, latest, pg_restore):
6666
backups_handler = DatabaseBackups()
6767

6868
if backup_name and latest:
69-
click.secho("Only one of --latest or backup_name is allowed", fg="red")
70-
exit(1)
69+
raise click.UsageError("Only one of --latest or backup_name is allowed")
7170

7271
if not backup_name and not latest:
73-
click.secho("Backup name or --latest is required", fg="red")
74-
exit(1)
72+
raise click.UsageError("Backup name or --latest is required")
7573

7674
if not backup_name and latest:
7775
backup_name = backups_handler.find_backups()[0].name

plain-vendor/plain/vendor/cli.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,9 @@ def update(name):
7070
deps = [dep for dep in deps if dep.name in name]
7171
if len(deps) != len(name):
7272
not_found = set(name) - {dep.name for dep in deps}
73-
click.secho(
74-
f"Some dependencies not found: {', '.join(not_found)}", fg="red"
73+
raise click.UsageError(
74+
f"Some dependencies not found: {', '.join(not_found)}"
7575
)
76-
exit(1)
7776

7877
for dep in deps:
7978
click.secho(f"Updating {dep.name} {dep.installed}...", bold=True, nl=False)

plain/plain/cli/build.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,9 @@ def build(keep_original, fingerprint, compress):
3737
"""Pre-deployment build step (compile assets, css, js, etc.)"""
3838

3939
if not keep_original and not fingerprint:
40-
click.secho(
41-
"You must either keep the original assets or fingerprint them.",
42-
fg="red",
43-
err=True,
40+
raise click.UsageError(
41+
"You must either keep the original assets or fingerprint them."
4442
)
45-
sys.exit(1)
4643

4744
# Run user-defined build commands first
4845
pyproject_path = plain.runtime.APP_PATH.parent / "pyproject.toml"

plain/plain/cli/docs.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import ast
22
import importlib.util
3-
import sys
43
from pathlib import Path
54

65
import click
@@ -16,8 +15,7 @@
1615
@click.argument("module", default="")
1716
def docs(module, llm, open):
1817
if not module and not llm:
19-
click.secho("You must specify a module or use --llm", fg="red")
20-
sys.exit(1)
18+
raise click.UsageError("You must specify a module or use --llm")
2119

2220
if llm:
2321
paths = [Path(__file__).parent.parent]
@@ -49,14 +47,12 @@ def docs(module, llm, open):
4947
# Get the README.md file for the module
5048
spec = importlib.util.find_spec(module)
5149
if not spec:
52-
click.secho(f"Module {module} not found", fg="red")
53-
sys.exit(1)
50+
raise click.UsageError(f"Module {module} not found")
5451

5552
module_path = Path(spec.origin).parent
5653
readme_path = module_path / "README.md"
5754
if not readme_path.exists():
58-
click.secho(f"README.md not found for {module}", fg="red")
59-
sys.exit(1)
55+
raise click.UsageError(f"README.md not found for {module}")
6056

6157
if open:
6258
click.launch(str(readme_path))

plain/plain/cli/urls.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sys
2-
31
import click
42

53

@@ -17,8 +15,7 @@ def list_urls(flat):
1715
from plain.urls import URLResolver, get_resolver
1816

1917
if not settings.URLS_ROUTER:
20-
click.secho("URLS_ROUTER is not set", fg="red")
21-
sys.exit(1)
18+
raise click.UsageError("URLS_ROUTER is not set")
2219

2320
resolver = get_resolver(settings.URLS_ROUTER)
2421
if flat:

0 commit comments

Comments
 (0)