commands.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. """
  2. Compose module commands and functionality.
  3. Manage Compose configurations and services and template operations.
  4. """
  5. import typer
  6. from pathlib import Path
  7. from rich.console import Console
  8. from rich.table import Table
  9. from ...core.command import BaseModule
  10. from ...core.helpers import find_boilerplates
  11. class ComposeModule(BaseModule):
  12. """Module for managing compose boilerplates."""
  13. def __init__(self):
  14. super().__init__(name="compose", icon="🐳", description="Manage Compose Templates and Configurations")
  15. def _add_module_commands(self, app: typer.Typer) -> None:
  16. """Add Module-specific commands to the app."""
  17. @app.command("list", help="List all compose boilerplates")
  18. def list():
  19. """List all compose boilerplates from library/compose directory."""
  20. # Get the library/compose path
  21. library_path = Path(__file__).parent.parent.parent.parent / "library" / "compose"
  22. # Define the compose file names to search for
  23. compose_filenames = ["compose.yaml", "docker-compose.yaml", "compose.yml", "docker-compose.yml"]
  24. # Find all boilerplates
  25. bps = find_boilerplates(library_path, compose_filenames)
  26. if not bps:
  27. console = Console()
  28. console.print("[yellow]No compose boilerplates found.[/yellow]")
  29. return
  30. # Create a rich table
  31. console = Console()
  32. table = Table(title="🐳 Available Compose Boilerplates", title_style="bold blue")
  33. table.add_column("Name", style="cyan", no_wrap=True)
  34. table.add_column("Module", style="magenta")
  35. table.add_column("Path", style="green")
  36. table.add_column("Size", justify="right", style="yellow")
  37. table.add_column("Description", style="dim")
  38. for bp in bps:
  39. # Format file size
  40. if bp.size < 1024:
  41. size_str = f"{bp.size} B"
  42. elif bp.size < 1024 * 1024:
  43. size_str = f"{bp.size // 1024} KB"
  44. else:
  45. size_str = f"{bp.size // (1024 * 1024)} MB"
  46. table.add_row(
  47. bp.name,
  48. bp.module,
  49. str(bp.file_path.relative_to(library_path)),
  50. size_str,
  51. bp.description[:50] + "..." if len(bp.description) > 50 else bp.description
  52. )
  53. console.print(table)
  54. @app.command("show", help="Show details about a compose boilerplate")
  55. def show(name: str):
  56. pass
  57. @app.command("search", help="Search compose boilerplates")
  58. def search(query: str):
  59. pass