- Fixed import sorting in cli.py, __main__.py, detectors/__init__.py, base.py, python.py, rust.py, openapi.py, models/__init__.py - Removed unused imports (sys, asyncio, Observer, Text, Parameter, ParameterIn, HTTPMethod, DocConfig, List, Optional) - Removed trailing whitespace from blank lines - Split lines exceeding 100 characters - Added missing __init__ docstrings in generators and static/templates packages
This commit is contained in:
@@ -1,19 +1,29 @@
|
|||||||
"""CLI interface using Typer."""
|
{"""CLI interface using Typer."""
|
||||||
|
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.progress import Progress, SpinnerColumn, TextColumn, BarColumn, TaskProgressColumn
|
|
||||||
from rich.table import Table
|
|
||||||
from rich.panel import Panel
|
from rich.panel import Panel
|
||||||
from rich.text import Text
|
from rich.progress import (
|
||||||
|
BarColumn,
|
||||||
|
Progress,
|
||||||
|
SpinnerColumn,
|
||||||
|
TaskProgressColumn,
|
||||||
|
TextColumn,
|
||||||
|
)
|
||||||
|
from rich.table import Table
|
||||||
|
|
||||||
from docgen import __version__
|
from docgen import __version__
|
||||||
from docgen.models import DocConfig, OutputFormat, Endpoint
|
from docgen.detectors import (
|
||||||
from docgen.detectors import PythonDetector, JavaScriptDetector, GoDetector, RustDetector
|
GoDetector,
|
||||||
|
JavaScriptDetector,
|
||||||
|
PythonDetector,
|
||||||
|
RustDetector,
|
||||||
|
)
|
||||||
from docgen.generators import HTMLGenerator, MarkdownGenerator, OpenAPIGenerator
|
from docgen.generators import HTMLGenerator, MarkdownGenerator, OpenAPIGenerator
|
||||||
|
from docgen.models import DocConfig, Endpoint, OutputFormat
|
||||||
|
|
||||||
app = typer.Typer(
|
app = typer.Typer(
|
||||||
name="docgen",
|
name="docgen",
|
||||||
@@ -45,7 +55,7 @@ def scan_for_endpoints(
|
|||||||
console=console,
|
console=console,
|
||||||
) as progress:
|
) as progress:
|
||||||
task = progress.add_task("Scanning for endpoints...", total=None)
|
task = progress.add_task("Scanning for endpoints...", total=None)
|
||||||
|
|
||||||
for detector in detectors:
|
for detector in detectors:
|
||||||
if framework and detector.framework_name != framework:
|
if framework and detector.framework_name != framework:
|
||||||
continue
|
continue
|
||||||
@@ -54,7 +64,7 @@ def scan_for_endpoints(
|
|||||||
endpoints.extend(found)
|
endpoints.extend(found)
|
||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
progress.update(task, completed=True)
|
progress.update(task, completed=True)
|
||||||
|
|
||||||
return endpoints
|
return endpoints
|
||||||
@@ -79,7 +89,7 @@ def display_summary(endpoints: list[Endpoint]) -> None:
|
|||||||
"PATCH": "turquoise2",
|
"PATCH": "turquoise2",
|
||||||
"DELETE": "red",
|
"DELETE": "red",
|
||||||
}.get(endpoint.method.value, "white")
|
}.get(endpoint.method.value, "white")
|
||||||
|
|
||||||
table.add_row(
|
table.add_row(
|
||||||
f"[{method_color}]{endpoint.method.value}[/]",
|
f"[{method_color}]{endpoint.method.value}[/]",
|
||||||
endpoint.path,
|
endpoint.path,
|
||||||
@@ -101,7 +111,9 @@ def show_version():
|
|||||||
@app.command("detect")
|
@app.command("detect")
|
||||||
def detect_command(
|
def detect_command(
|
||||||
input_dir: Path = typer.Argument(Path("."), help="Directory to scan for endpoints"),
|
input_dir: Path = typer.Argument(Path("."), help="Directory to scan for endpoints"),
|
||||||
framework: Optional[str] = typer.Option(None, "--framework", "-f", help="Specific framework to use (python, javascript, go, rust)"),
|
framework: Optional[str] = typer.Option(
|
||||||
|
None, "--framework", "-f", help="Specific framework to use (python, javascript, go, rust)"
|
||||||
|
),
|
||||||
recursive: bool = typer.Option(True, "--no-recursive", help="Disable recursive scanning"),
|
recursive: bool = typer.Option(True, "--no-recursive", help="Disable recursive scanning"),
|
||||||
):
|
):
|
||||||
"""Detect API endpoints in source code."""
|
"""Detect API endpoints in source code."""
|
||||||
@@ -116,10 +128,14 @@ def detect_command(
|
|||||||
@app.command("generate")
|
@app.command("generate")
|
||||||
def generate_command(
|
def generate_command(
|
||||||
input_dir: Path = typer.Argument(Path("."), help="Directory to scan for endpoints"),
|
input_dir: Path = typer.Argument(Path("."), help="Directory to scan for endpoints"),
|
||||||
output_dir: Path = typer.Option(Path("docs"), "--output", "-o", help="Output directory for documentation"),
|
output_dir: Path = typer.Option(Path("docs"), "--output", "-o", help="Output directory"),
|
||||||
format: OutputFormat = typer.Option(OutputFormat.HTML, "--format", "-F", help="Output format"),
|
format: OutputFormat = typer.Option(
|
||||||
|
OutputFormat.HTML, "--format", "-F", help="Output format"
|
||||||
|
),
|
||||||
theme: str = typer.Option("default", "--theme", "-t", help="Theme for HTML output"),
|
theme: str = typer.Option("default", "--theme", "-t", help="Theme for HTML output"),
|
||||||
framework: Optional[str] = typer.Option(None, "--framework", "-f", help="Specific framework to use"),
|
framework: Optional[str] = typer.Option(
|
||||||
|
None, "--framework", "-f", help="Specific framework to use"
|
||||||
|
),
|
||||||
title: str = typer.Option("API Documentation", "--title", help="Documentation title"),
|
title: str = typer.Option("API Documentation", "--title", help="Documentation title"),
|
||||||
description: str = typer.Option("", "--description", "-d", help="Documentation description"),
|
description: str = typer.Option("", "--description", "-d", help="Documentation description"),
|
||||||
version: str = typer.Option("1.0.0", "--version", "-v", help="API version"),
|
version: str = typer.Option("1.0.0", "--version", "-v", help="API version"),
|
||||||
@@ -165,15 +181,15 @@ def generate_command(
|
|||||||
|
|
||||||
@app.command("serve")
|
@app.command("serve")
|
||||||
def serve_command(
|
def serve_command(
|
||||||
input_dir: Path = typer.Argument(Path("docs"), help="Directory containing documentation to serve"),
|
input_dir: Path = typer.Argument(
|
||||||
|
Path("docs"), help="Directory containing documentation to serve"
|
||||||
|
),
|
||||||
host: str = typer.Option("127.0.0.1", "--host", "-h", help="Host to bind to"),
|
host: str = typer.Option("127.0.0.1", "--host", "-h", help="Host to bind to"),
|
||||||
port: int = typer.Option(8000, "--port", "-p", help="Port to bind to"),
|
port: int = typer.Option(8000, "--port", "-p", help="Port to bind to"),
|
||||||
reload: bool = typer.Option(True, "--no-reload", help="Enable/disable auto-reload on changes"),
|
reload: bool = typer.Option(True, "--no-reload", help="Enable/disable auto-reload"),
|
||||||
):
|
):
|
||||||
"""Start a local development server with live reload."""
|
"""Start a local development server with live reload."""
|
||||||
import uvicorn
|
import uvicorn
|
||||||
import asyncio
|
|
||||||
from watchdog.observers import Observer
|
|
||||||
from watchdog.events import FileSystemEventHandler
|
from watchdog.events import FileSystemEventHandler
|
||||||
|
|
||||||
if not input_dir.exists():
|
if not input_dir.exists():
|
||||||
@@ -187,7 +203,11 @@ def serve_command(
|
|||||||
def on_any_event(self, event):
|
def on_any_event(self, event):
|
||||||
self._reload_needed = True
|
self._reload_needed = True
|
||||||
|
|
||||||
console.print(Panel(f"[bold]DocGen Server[/bold]\n\nListening on http://{host}:{port}", title="Started"))
|
server_url = f"http://{host}:{port}"
|
||||||
|
title = "Started"
|
||||||
|
console.print(
|
||||||
|
Panel(f"[bold]DocGen Server[/bold]\n\nListening on {server_url}", title=title)
|
||||||
|
)
|
||||||
|
|
||||||
config = uvicorn.Config("docgen.cli:reload_app", host=host, port=port, reload=reload)
|
config = uvicorn.Config("docgen.cli:reload_app", host=host, port=port, reload=reload)
|
||||||
server = uvicorn.Server(config)
|
server = uvicorn.Server(config)
|
||||||
@@ -220,15 +240,15 @@ def init_command(
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main entry point."""
|
"""Run the main application."""
|
||||||
app()
|
app()
|
||||||
|
|
||||||
|
|
||||||
def reload_app():
|
def reload_app():
|
||||||
"""App for uvicorn reload."""
|
"""App for uvicorn reload."""
|
||||||
from starlette.applications import Starlette
|
from starlette.applications import Starlette
|
||||||
from starlette.routing import Route
|
|
||||||
from starlette.responses import FileResponse
|
from starlette.responses import FileResponse
|
||||||
|
from starlette.routing import Route
|
||||||
|
|
||||||
async def serve_static(request):
|
async def serve_static(request):
|
||||||
path = request.path_params.get("path", "index.html")
|
path = request.path_params.get("path", "index.html")
|
||||||
|
|||||||
Reference in New Issue
Block a user