|
| 1 | +"""CLI commands for aidocs.""" |
| 2 | + |
| 3 | +from pathlib import Path |
| 4 | +from typing import Optional |
| 5 | + |
| 6 | +import typer |
| 7 | +from rich.console import Console |
| 8 | +from rich.panel import Panel |
| 9 | + |
| 10 | +from .installer import check_tools, install_docs_module |
| 11 | + |
| 12 | +app = typer.Typer( |
| 13 | + name="aidocs", |
| 14 | + help="AI-powered documentation generator for web applications.", |
| 15 | + no_args_is_help=True, |
| 16 | +) |
| 17 | +console = Console() |
| 18 | + |
| 19 | + |
| 20 | +@app.command() |
| 21 | +def init( |
| 22 | + project_name: Optional[str] = typer.Argument( |
| 23 | + None, |
| 24 | + help="Project name or path. Use '.' for current directory.", |
| 25 | + ), |
| 26 | + ai: str = typer.Option( |
| 27 | + "claude", |
| 28 | + "--ai", |
| 29 | + help="AI assistant to configure for (claude, cursor, copilot).", |
| 30 | + ), |
| 31 | + force: bool = typer.Option( |
| 32 | + False, |
| 33 | + "--force", |
| 34 | + "-f", |
| 35 | + help="Overwrite existing files.", |
| 36 | + ), |
| 37 | + no_git: bool = typer.Option( |
| 38 | + False, |
| 39 | + "--no-git", |
| 40 | + help="Skip git initialization.", |
| 41 | + ), |
| 42 | +) -> None: |
| 43 | + """Initialize docs module in a project. |
| 44 | +
|
| 45 | + Examples: |
| 46 | + aidocs init . # Current directory |
| 47 | + aidocs init my-project # New directory |
| 48 | + aidocs init . --force # Overwrite existing |
| 49 | + """ |
| 50 | + if project_name is None or project_name == ".": |
| 51 | + target_dir = Path.cwd() |
| 52 | + console.print(f"[blue]Initializing docs module in current directory...[/blue]") |
| 53 | + else: |
| 54 | + target_dir = Path.cwd() / project_name |
| 55 | + if not target_dir.exists(): |
| 56 | + target_dir.mkdir(parents=True) |
| 57 | + console.print(f"[blue]Created directory: {project_name}[/blue]") |
| 58 | + console.print(f"[blue]Initializing docs module in {project_name}...[/blue]") |
| 59 | + |
| 60 | + try: |
| 61 | + install_docs_module(target_dir, ai=ai, force=force, no_git=no_git) |
| 62 | + |
| 63 | + console.print() |
| 64 | + console.print(Panel.fit( |
| 65 | + "[green]Docs module installed successfully![/green]\n\n" |
| 66 | + "[bold]Next steps:[/bold]\n" |
| 67 | + "1. Run [cyan]/docs:init[/cyan] in Claude Code to configure your project\n" |
| 68 | + "2. Run [cyan]/docs:generate <url>[/cyan] to document a page\n\n" |
| 69 | + "[dim]Requires Playwright MCP for browser automation.[/dim]", |
| 70 | + title="Success", |
| 71 | + border_style="green", |
| 72 | + )) |
| 73 | + except Exception as e: |
| 74 | + console.print(f"[red]Error: {e}[/red]") |
| 75 | + raise typer.Exit(1) |
| 76 | + |
| 77 | + |
| 78 | +@app.command() |
| 79 | +def check() -> None: |
| 80 | + """Check for required tools and dependencies.""" |
| 81 | + console.print("[blue]Checking environment...[/blue]") |
| 82 | + console.print() |
| 83 | + |
| 84 | + results = check_tools() |
| 85 | + |
| 86 | + all_passed = all(results.values()) |
| 87 | + |
| 88 | + console.print() |
| 89 | + if all_passed: |
| 90 | + console.print(Panel.fit( |
| 91 | + "[green]All checks passed![/green]\n\n" |
| 92 | + "You're ready to use aidocs.", |
| 93 | + title="Environment Check", |
| 94 | + border_style="green", |
| 95 | + )) |
| 96 | + else: |
| 97 | + console.print(Panel.fit( |
| 98 | + "[yellow]Some checks failed.[/yellow]\n\n" |
| 99 | + "Install missing tools to use all features.", |
| 100 | + title="Environment Check", |
| 101 | + border_style="yellow", |
| 102 | + )) |
| 103 | + |
| 104 | + |
| 105 | +@app.command() |
| 106 | +def version() -> None: |
| 107 | + """Show version information.""" |
| 108 | + from . import __version__ |
| 109 | + console.print(f"aidocs-cli version {__version__}") |
| 110 | + |
| 111 | + |
| 112 | +if __name__ == "__main__": |
| 113 | + app() |
0 commit comments