11import asyncclick as click
22from 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
2726def 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
3533def 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
4542EXPORTER_COLUMNS = ["NAME" , "ENDPOINT" , "DEVICES" , "AGE" ]
@@ -79,28 +76,26 @@ def get_device_rows(exporters: list[V1Alpha1Exporter]):
7976
8077
8178def 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
9389def 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
106101LEASE_COLUMNS = ["NAME" , "CLIENT" , "SELECTOR" , "EXPORTER" , "STATUS" , "REASON" , "BEGIN" , "END" , "DURATION" , "AGE" ]
@@ -143,18 +138,16 @@ def make_lease_row(lease: V1Alpha1Lease):
143138
144139
145140def 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
153147def 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