askrobots / dbbasic-cli
Public
Make a complete, running app (a CRM, a shop, a blog) with one command, such as dbbasic crm.
cli.py · 2.9 KB · 105 lines
| 1 | #!/usr/bin/env python3 |
| 2 | """ |
| 3 | DBBasic CLI - Main application |
| 4 | """ |
| 5 | |
| 6 | import typer |
| 7 | from rich.console import Console |
| 8 | from rich.table import Table |
| 9 | from pathlib import Path |
| 10 | |
| 11 | from .commands import start, status, stop, logs, ports, open_service |
| 12 | from .commands import crm, shop, blog |
| 13 | |
| 14 | console = Console() |
| 15 | app = typer.Typer( |
| 16 | name="dbbasic", |
| 17 | help="DBBasic - The crate engine for web apps. Zero to running app in 30 seconds.", |
| 18 | no_args_is_help=True, |
| 19 | add_completion=False, |
| 20 | ) |
| 21 | |
| 22 | # Phase 1: Core service commands |
| 23 | app.command("start")(start.start) |
| 24 | app.command("stop")(stop.stop) |
| 25 | app.command("status")(status.status) |
| 26 | app.command("logs")(logs.logs) |
| 27 | app.command("ports")(ports.ports) |
| 28 | app.command("open")(open_service.open_service) |
| 29 | |
| 30 | # Phase 2: Instant app generators |
| 31 | app.command("crm")(crm.create_crm) |
| 32 | app.command("shop")(shop.create_shop) |
| 33 | app.command("blog")(blog.create_blog) |
| 34 | |
| 35 | @app.callback() |
| 36 | def callback(): |
| 37 | """ |
| 38 | DBBasic - Replace your entire stack with one command. |
| 39 | |
| 40 | Quick start: |
| 41 | dbbasic crm # Instant CRM app |
| 42 | dbbasic shop # Instant e-commerce |
| 43 | dbbasic blog # Instant blog |
| 44 | """ |
| 45 | pass |
| 46 | |
| 47 | @app.command() |
| 48 | def version(): |
| 49 | """Show version information""" |
| 50 | from . import __version__ |
| 51 | console.print(f"[bold blue]DBBasic CLI[/bold blue] version {__version__}") |
| 52 | console.print("The crate engine for web apps 🚀") |
| 53 | |
| 54 | @app.command() |
| 55 | def doctor(): |
| 56 | """Diagnose and fix common issues""" |
| 57 | console.print("[bold]🏥 Running diagnostics...[/bold]\n") |
| 58 | |
| 59 | checks = [] |
| 60 | |
| 61 | # Check if DuckDB is available |
| 62 | try: |
| 63 | import duckdb |
| 64 | checks.append(("DuckDB", "✅", duckdb.__version__)) |
| 65 | except ImportError: |
| 66 | checks.append(("DuckDB", "❌", "Not installed")) |
| 67 | |
| 68 | # Check if FastAPI is available |
| 69 | try: |
| 70 | import fastapi |
| 71 | checks.append(("FastAPI", "✅", fastapi.__version__)) |
| 72 | except ImportError: |
| 73 | checks.append(("FastAPI", "❌", "Not installed")) |
| 74 | |
| 75 | # Check if ports are available |
| 76 | import socket |
| 77 | for port in [8000, 8003, 8004, 8005, 8007]: |
| 78 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 79 | result = sock.connect_ex(('localhost', port)) |
| 80 | sock.close() |
| 81 | if result == 0: |
| 82 | checks.append((f"Port {port}", "⚠️", "In use")) |
| 83 | else: |
| 84 | checks.append((f"Port {port}", "✅", "Available")) |
| 85 | |
| 86 | # Display results |
| 87 | table = Table(title="System Check") |
| 88 | table.add_column("Component", style="cyan") |
| 89 | table.add_column("Status", style="bold") |
| 90 | table.add_column("Info") |
| 91 | |
| 92 | for component, status, info in checks: |
| 93 | table.add_row(component, status, info) |
| 94 | |
| 95 | console.print(table) |
| 96 | |
| 97 | # Check for issues |
| 98 | issues = [c for c in checks if c[1] != "✅"] |
| 99 | if issues: |
| 100 | console.print("\n[yellow]⚠️ Found issues that may need attention[/yellow]") |
| 101 | else: |
| 102 | console.print("\n[green]✅ All systems operational![/green]") |
| 103 | |
| 104 | if __name__ == "__main__": |
| 105 | app() |