Files
SuperClaude/superclaude/cli/app.py

71 lines
2.0 KiB
Python
Raw Normal View History

feat: migrate CLI to typer + rich for modern UX ## What Changed ### New CLI Architecture (typer + rich) - Created `superclaude/cli/` module with modern typer-based CLI - Replaced custom UI utilities with rich native features - Added type-safe command structure with automatic validation ### Commands Implemented - **install**: Interactive installation with rich UI (progress, panels) - **doctor**: System diagnostics with rich table output - **config**: API key management with format validation ### Technical Improvements - Dependencies: Added typer>=0.9.0, rich>=13.0.0, click>=8.0.0 - Entry Point: Updated pyproject.toml to use `superclaude.cli.app:cli_main` - Tests: Added comprehensive smoke tests (11 passed) ### User Experience Enhancements - Rich formatted help messages with panels and tables - Automatic input validation with retry loops - Clear error messages with actionable suggestions - Non-interactive mode support for CI/CD ## Testing ```bash uv run superclaude --help # ✓ Works uv run superclaude doctor # ✓ Rich table output uv run superclaude config show # ✓ API key management pytest tests/test_cli_smoke.py # ✓ 11 passed, 1 skipped ``` ## Migration Path - ✅ P0: Foundation complete (typer + rich + smoke tests) - 🔜 P1: Pydantic validation models (next sprint) - 🔜 P2: Enhanced error messages (next sprint) - 🔜 P3: API key retry loops (next sprint) ## Performance Impact - **Code Reduction**: Prepared for -300 lines (custom UI → rich) - **Type Safety**: Automatic validation from type hints - **Maintainability**: Framework primitives vs custom code 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-17 03:50:26 +09:00
"""
SuperClaude CLI - Root application with typer
Modern, type-safe command-line interface with rich formatting
"""
import sys
import typer
from typing import Optional
from superclaude.cli._console import console
from superclaude.cli.commands import install, doctor, config
# Create root typer app
app = typer.Typer(
name="superclaude",
help="SuperClaude Framework CLI - AI-enhanced development framework for Claude Code",
add_completion=False, # Disable shell completion for now
no_args_is_help=True, # Show help when no args provided
pretty_exceptions_enable=True, # Rich exception formatting
)
# Register command groups
app.add_typer(install.app, name="install", help="Install SuperClaude components")
app.add_typer(doctor.app, name="doctor", help="Diagnose system environment")
app.add_typer(config.app, name="config", help="Manage configuration")
def version_callback(value: bool):
"""Show version and exit"""
if value:
from superclaude import __version__
feat: migrate CLI to typer + rich for modern UX ## What Changed ### New CLI Architecture (typer + rich) - Created `superclaude/cli/` module with modern typer-based CLI - Replaced custom UI utilities with rich native features - Added type-safe command structure with automatic validation ### Commands Implemented - **install**: Interactive installation with rich UI (progress, panels) - **doctor**: System diagnostics with rich table output - **config**: API key management with format validation ### Technical Improvements - Dependencies: Added typer>=0.9.0, rich>=13.0.0, click>=8.0.0 - Entry Point: Updated pyproject.toml to use `superclaude.cli.app:cli_main` - Tests: Added comprehensive smoke tests (11 passed) ### User Experience Enhancements - Rich formatted help messages with panels and tables - Automatic input validation with retry loops - Clear error messages with actionable suggestions - Non-interactive mode support for CI/CD ## Testing ```bash uv run superclaude --help # ✓ Works uv run superclaude doctor # ✓ Rich table output uv run superclaude config show # ✓ API key management pytest tests/test_cli_smoke.py # ✓ 11 passed, 1 skipped ``` ## Migration Path - ✅ P0: Foundation complete (typer + rich + smoke tests) - 🔜 P1: Pydantic validation models (next sprint) - 🔜 P2: Enhanced error messages (next sprint) - 🔜 P3: API key retry loops (next sprint) ## Performance Impact - **Code Reduction**: Prepared for -300 lines (custom UI → rich) - **Type Safety**: Automatic validation from type hints - **Maintainability**: Framework primitives vs custom code 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-17 03:50:26 +09:00
console.print(f"[bold cyan]SuperClaude[/bold cyan] version [green]{__version__}[/green]")
raise typer.Exit()
@app.callback()
def main(
version: Optional[bool] = typer.Option(
None,
"--version",
"-v",
callback=version_callback,
is_eager=True,
help="Show version and exit",
),
):
"""
SuperClaude Framework CLI
Modern command-line interface for managing SuperClaude installation,
configuration, and diagnostic operations.
"""
pass
def cli_main():
"""Entry point for CLI (called from pyproject.toml)"""
try:
app()
except KeyboardInterrupt:
console.print("\n[yellow]Operation cancelled by user[/yellow]")
sys.exit(130)
except Exception as e:
console.print(f"[bold red]Unhandled error:[/bold red] {e}")
if "--debug" in sys.argv or "--verbose" in sys.argv:
console.print_exception()
sys.exit(1)
if __name__ == "__main__":
cli_main()