Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit 7341c81

Browse files
committed
Drop redundant match clause
1 parent 6ac9ca1 commit 7341c81

1 file changed

Lines changed: 37 additions & 44 deletions

File tree

  • packages/jumpstarter-cli-admin/jumpstarter_cli_admin

packages/jumpstarter-cli-admin/jumpstarter_cli_admin/print.py

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import asyncclick as click
22
from jumpstarter_cli_common import (
3-
OutputMode,
43
OutputType,
54
echo,
65
make_table,
@@ -25,21 +24,19 @@ def make_client_row(client: V1Alpha1Client):
2524

2625

2726
def print_client(client: V1Alpha1Client, output: OutputType):
28-
match output:
29-
case OutputMode.JSON | OutputMode.YAML | OutputMode.NAME:
30-
echo(client.dump(output))
31-
case _:
32-
click.echo(make_table(CLIENT_COLUMNS, [make_client_row(client)]))
27+
if output:
28+
echo(client.dump(output))
29+
else:
30+
click.echo(make_table(CLIENT_COLUMNS, [make_client_row(client)]))
3331

3432

3533
def print_clients(clients: V1Alpha1List[V1Alpha1Client], namespace: str, output: OutputType):
36-
match output:
37-
case OutputMode.JSON | OutputMode.YAML | OutputMode.NAME:
38-
echo(clients.dump(output))
39-
case _:
40-
if len(clients.items) == 0:
41-
raise click.ClickException(f'No resources found in "{namespace}" namespace')
42-
click.echo(make_table(CLIENT_COLUMNS, list(map(make_client_row, clients.items))))
34+
if output:
35+
echo(clients.dump(output))
36+
else:
37+
if len(clients.items) == 0:
38+
raise click.ClickException(f'No resources found in "{namespace}" namespace')
39+
click.echo(make_table(CLIENT_COLUMNS, list(map(make_client_row, clients.items))))
4340

4441

4542
EXPORTER_COLUMNS = ["NAME", "ENDPOINT", "DEVICES", "AGE"]
@@ -79,28 +76,26 @@ def get_device_rows(exporters: list[V1Alpha1Exporter]):
7976

8077

8178
def print_exporter(exporter: V1Alpha1Exporter, devices: bool, output: OutputType):
82-
match output:
83-
case OutputMode.JSON | OutputMode.YAML | OutputMode.NAME:
84-
echo(exporter.dump(output))
85-
case _:
86-
if devices:
87-
# Print the devices for the exporter
88-
click.echo(make_table(DEVICE_COLUMNS, get_device_rows([exporter])))
89-
else:
90-
click.echo(make_table(EXPORTER_COLUMNS, [make_exporter_row(exporter)]))
79+
if output:
80+
echo(exporter.dump(output))
81+
else:
82+
if devices:
83+
# Print the devices for the exporter
84+
click.echo(make_table(DEVICE_COLUMNS, get_device_rows([exporter])))
85+
else:
86+
click.echo(make_table(EXPORTER_COLUMNS, [make_exporter_row(exporter)]))
9187

9288

9389
def print_exporters(exporters: V1Alpha1List[V1Alpha1Exporter], namespace: str, devices: bool, output: OutputType):
94-
match output:
95-
case OutputMode.JSON | OutputMode.YAML | OutputMode.NAME:
96-
echo(exporters.dump(output))
97-
case _:
98-
if len(exporters.items) == 0:
99-
raise click.ClickException(f'No resources found in "{namespace}" namespace')
100-
if devices:
101-
click.echo(make_table(DEVICE_COLUMNS, get_device_rows(exporters.items)))
102-
else:
103-
click.echo(make_table(EXPORTER_COLUMNS, list(map(make_exporter_row, exporters.items))))
90+
if output:
91+
echo(exporters.dump(output))
92+
else:
93+
if len(exporters.items) == 0:
94+
raise click.ClickException(f'No resources found in "{namespace}" namespace')
95+
if devices:
96+
click.echo(make_table(DEVICE_COLUMNS, get_device_rows(exporters.items)))
97+
else:
98+
click.echo(make_table(EXPORTER_COLUMNS, list(map(make_exporter_row, exporters.items))))
10499

105100

106101
LEASE_COLUMNS = ["NAME", "CLIENT", "SELECTOR", "EXPORTER", "STATUS", "REASON", "BEGIN", "END", "DURATION", "AGE"]
@@ -143,18 +138,16 @@ def make_lease_row(lease: V1Alpha1Lease):
143138

144139

145140
def print_lease(lease: V1Alpha1Lease, output: OutputType):
146-
match output:
147-
case OutputMode.JSON | OutputMode.YAML | OutputMode.NAME:
148-
echo(lease.dump(output))
149-
case _:
150-
click.echo(make_table(LEASE_COLUMNS, [make_lease_row(lease)]))
141+
if output:
142+
echo(lease.dump(output))
143+
else:
144+
click.echo(make_table(LEASE_COLUMNS, [make_lease_row(lease)]))
151145

152146

153147
def print_leases(leases: V1Alpha1List[V1Alpha1Lease], namespace: str, output: OutputType):
154-
match output:
155-
case OutputMode.JSON | OutputMode.YAML | OutputMode.NAME:
156-
echo(leases.dump(output))
157-
case _:
158-
if len(leases.items) == 0:
159-
raise click.ClickException(f'No resources found in "{namespace}" namespace')
160-
click.echo(make_table(LEASE_COLUMNS, list(map(make_lease_row, leases.items))))
148+
if output:
149+
echo(leases.dump(output))
150+
else:
151+
if len(leases.items) == 0:
152+
raise click.ClickException(f'No resources found in "{namespace}" namespace')
153+
click.echo(make_table(LEASE_COLUMNS, list(map(make_lease_row, leases.items))))

0 commit comments

Comments
 (0)