diff --git a/src/parxy_cli/commands/drivers.py b/src/parxy_cli/commands/drivers.py index 86ae4cd..335d5aa 100644 --- a/src/parxy_cli/commands/drivers.py +++ b/src/parxy_cli/commands/drivers.py @@ -1,5 +1,8 @@ import typer +from rich.table import Table +from pydantic import ValidationError + from parxy_core.facade import Parxy from parxy_cli.console.console import Console @@ -12,11 +15,60 @@ def drivers(): """List supported drivers.""" - drivers = Parxy.drivers() + factory = Parxy._get_factory() + + # Get supported and custom drivers + supported_drivers = factory.get_supported_drivers() + custom_drivers = factory.get_custom_drivers() + + drivers = supported_drivers + custom_drivers + + console.action('Parxy drivers', space_after=False) + + console.print( + f'[faint]⎿ [/faint] [bold]{len(drivers)}[/bold] driver{"s" if len(drivers) > 1 else ""} supported ({len(custom_drivers)} custom{"s" if len(custom_drivers) > 1 else ""}).' + ) + + if not drivers: + return + + console.newline() + + with console.shimmer(f'Checking installed drivers...'): + # Create a table for displaying driver information + table = Table( + show_header=True, + # header_style='bold', + show_lines=False, + padding=(0, 1), + ) + + table.add_column('Driver', no_wrap=True) + table.add_column('Status', no_wrap=True) + table.add_column('Type', style='faint') + table.add_column('Details', style='faint') + + # Check each driver + for driver_name in drivers: + driver_type = 'custom' if driver_name in custom_drivers else 'built-in' - console.action('Parxy available drivers') + try: + # Attempt to create driver instance + factory.driver(driver_name) + status = '[green]✓ Ready[/green]' + details = '' + except ImportError as e: + status = '[red]✗ Not installed[/red]' + # Extract the missing module name from the error + missing_module = ( + str(e).split("'")[1] if "'" in str(e) else 'dependencies' + ) + details = f'Missing: {missing_module}' + except Exception as e: + status = '[yellow]⚠ Installed with warnings[/yellow]' + details = str(e)[:50].strip() - console.print(f'{len(drivers)} drivers supported:') + table.add_row(driver_name, status, driver_type, details) - driver_list = '\n'.join(f'- {driver}' for driver in drivers) - console.markdown(driver_list) + console.print(table) + console.newline() diff --git a/src/parxy_core/drivers/factory.py b/src/parxy_core/drivers/factory.py index a256aeb..46b02d1 100644 --- a/src/parxy_core/drivers/factory.py +++ b/src/parxy_core/drivers/factory.py @@ -287,6 +287,16 @@ def get_supported_drivers(self) -> List[str]: return supported_drivers + def get_custom_drivers(self) -> List[str]: + """Get the list of custom registered drivers. + + Returns + ------- + List[str] + The custom driver names + """ + return list(self.__custom_creators.keys()) + def forget_drivers(self) -> 'DriverFactory': """Forget all instantiated and custom "drivers". diff --git a/src/parxy_core/facade/parxy.py b/src/parxy_core/facade/parxy.py index d4a624a..17525f3 100644 --- a/src/parxy_core/facade/parxy.py +++ b/src/parxy_core/facade/parxy.py @@ -103,7 +103,10 @@ def drivers(cls) -> Dict[str, Driver]: Driver The requested driver instance """ - return cls._get_factory().get_supported_drivers() + return ( + cls._get_factory().get_supported_drivers() + + cls._get_factory().get_custom_drivers() + ) @classmethod def config(cls) -> ParxyConfig: