11import asyncclick as click
22from jumpstarter_cli_common import OutputMode , OutputType , opt_output_all
33from jumpstarter_cli_common .exceptions import handle_exceptions
4- from jumpstarter_cli_pkg .repository import LocalDriverRepository
54
5+ from ..opt import opt_adapters , opt_driver_clients , opt_drivers , opt_inspect
6+ from ..repository import LocalDriverRepository , V1Alpha1DriverPackage
67
7- def print_package_details (package : str , drivers : bool , driver_clients : bool , adapters : bool , output : OutputType ):
8+
9+ def print_package_info (package : V1Alpha1DriverPackage ):
10+ """Print basic package information."""
11+ click .echo ("Name: " + package .name )
12+ click .echo ("Version: " + package .version )
13+ click .echo ("Summary: " + (package .summary if package .summary else "" ))
14+ click .echo ("Categories: " + ", " .join (package .categories ))
15+ click .echo ("License: " + (package .license if package .license else "" ))
16+
17+
18+ def print_drivers (package : V1Alpha1DriverPackage , inspect : bool ):
19+ """Print drivers information."""
20+ click .echo ("Drivers:" )
21+ for driver in package .drivers .items :
22+ click .echo (f" { driver .name } :" )
23+ click .echo (f" Module: { driver .module } " )
24+ click .echo (f" Class: { driver .class_name } " )
25+ click .echo (f" Type: { driver .type } " )
26+
27+ client_type_out = driver .client_type if driver .client_type else "(not available)"
28+ if not inspect :
29+ client_type_out = "(run this command with --inspect to see the client type)"
30+ click .echo (f" Client: { client_type_out } " )
31+
32+ summary_out = driver .summary if driver .summary else "(not available)"
33+ if not inspect :
34+ summary_out = "(run this command with --inspect to see the summary)"
35+ click .echo (f" Summary: { summary_out } " )
36+
37+
38+ def print_driver_clients (package : V1Alpha1DriverPackage , inspect : bool ):
39+ """Print driver clients information."""
40+ click .echo ("Driver Clients:" )
41+ for driver_client in package .driver_clients .items :
42+ click .echo (f" { driver_client .name } :" )
43+ click .echo (f" Module: { driver_client .module } " )
44+ click .echo (f" Class: { driver_client .class_name } " )
45+ click .echo (f" Type: { driver_client .type } " )
46+
47+ summary_out = driver_client .summary if driver_client .summary else "(not available)"
48+ if not inspect :
49+ summary_out = "(run this command with --inspect to see the summary)"
50+ click .echo (f" Summary: { summary_out } " )
51+ cli_out = "Yes" if driver_client .cli else "No"
52+ if not inspect :
53+ cli_out = "(run this command with --inspect to check if a CLI is available)"
54+ click .echo (f" Has CLI: { cli_out } " )
55+
56+
57+ def print_adapters (package : V1Alpha1DriverPackage , inspect : bool ):
58+ """Print adapters information."""
59+ click .echo ("Adapters:" )
60+ for adapter in package .adapters .items :
61+ click .echo (f" { adapter .name } :" )
62+ click .echo (f" Module: { adapter .module } " )
63+ click .echo (f" Function: { adapter .function_name } " )
64+ click .echo (f" Type: { adapter .type } " )
65+ summary_out = adapter .summary if adapter .summary else "(not available)"
66+ if not inspect :
67+ summary_out = "(run this command with --inspect to see the summary)"
68+ click .echo (f" Summary: { summary_out } " )
69+
70+
71+ def print_package_details (
72+ package : V1Alpha1DriverPackage , drivers : bool , driver_clients : bool , adapters : bool , inspect : bool
73+ ):
74+ """Print package details based on the specified flags."""
875 flag_sum = sum ([drivers , driver_clients , adapters ])
76+
977 if flag_sum == 0 :
10- click .echo ("Name: " + package .name )
11- click .echo ("Version: " + package .version )
12- click .echo ("Summary: " + (package .summary if package .summary else "" ))
13- click .echo ("Categories: " + ", " .join (package .categories ))
14- click .echo ("License: " + (package .license if package .license else "" ))
78+ print_package_info (package )
1579
1680 if flag_sum == 0 or drivers :
17- click .echo ("Drivers:" )
18- for driver in package .drivers .items :
19- click .echo (f" { driver .name } :" )
20- click .echo (f" Name: { driver .name } " )
21- click .echo (f" Type: { driver .type } " )
81+ print_drivers (package , inspect )
82+
2283 if flag_sum == 0 or driver_clients :
23- click .echo ("Driver Clients:" )
24- for driver_client in package .driver_clients .items :
25- click .echo (f" { driver_client .name } :" )
26- click .echo (f" Name: { driver_client .name } " )
27- click .echo (f" Type: { driver_client .type } " )
84+ print_driver_clients (package , inspect )
85+
2886 if flag_sum == 0 or adapters :
29- click .echo ("Adapters:" )
30- for adapter in package .adapters .items :
31- click .echo (f" { adapter .name } :" )
32- click .echo (f" Name: { adapter .name } " )
33- click .echo (f" Type: { adapter .type } " )
87+ print_adapters (package , inspect )
3488
3589
3690@click .command ("show" )
3791@click .argument ("package" )
38- @click .option ("--drivers" , is_flag = True , help = "Print drivers only." )
39- @click .option ("--driver-clients" , is_flag = True , help = "Print driver clients only." )
40- @click .option ("--adapters" , is_flag = True , help = "Print adapters only." )
92+ @opt_drivers
93+ @opt_driver_clients
94+ @opt_adapters
95+ @opt_inspect
4196@opt_output_all
4297@handle_exceptions
43- def show (package : str , drivers : bool , driver_clients : bool , adapters : bool , output : OutputType ):
98+ def show (package : str , drivers : bool , driver_clients : bool , adapters : bool , output : OutputType , inspect : bool ):
4499 """
45100 Show a Jumpstarter plugin package details.
46101 """
@@ -49,7 +104,7 @@ def show(package: str, drivers: bool, driver_clients: bool, adapters: bool, outp
49104 raise click .UsageError ("Only one of --drivers, --driver-clients, or --adapters can be specified." )
50105
51106 local_repo = LocalDriverRepository .from_venv ()
52- local_package = local_repo .get_package (package )
107+ local_package = local_repo .get_package (package , inspect )
53108
54109 match output :
55110 case OutputMode .JSON :
@@ -71,4 +126,4 @@ def show(package: str, drivers: bool, driver_clients: bool, adapters: bool, outp
71126 else :
72127 click .echo (local_package .dump_yaml ())
73128 case _:
74- print_package_details (local_package , drivers , driver_clients , adapters , output )
129+ print_package_details (local_package , drivers , driver_clients , adapters , inspect )
0 commit comments