refactor: Separate CLI presentation from core business logic

Complete architectural separation of concerns implementing clean layered design:

• Services Layer: Pure business logic isolated from presentation
  - WorkspaceService: TDD workspace operations
  - IssueService: Issue management and creation
  - ProjectService: Project management and milestones
  - ExportService: Unix-friendly data export

• CLI Layer: Clean presentation with command/presenter separation
  - Commands delegate to services for all business operations
  - Presenters handle formatted output and error messaging
  - Framework provides unified interface

• Benefits:
  - Eliminates mixed concerns in 943-line CLI monolith
  - Enables easier testing and maintenance
  - Preserves all existing functionality and Unix pipeline compatibility
  - Provides foundation for future CLI development

Resolves issue #20: CLI separation from core logic

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-26 15:08:54 +02:00
parent fd8f792f08
commit 7f5309c4b0
17 changed files with 1274 additions and 713 deletions

46
cli/commands/export.py Normal file
View File

@@ -0,0 +1,46 @@
"""
Export and reporting CLI commands.
"""
import sys
from typing import Optional
from tddai import TddaiError
from services import ExportService
from cli.presenters import OutputFormatter
class ExportCommands:
"""Commands for data export and reporting."""
def __init__(self):
self.service = ExportService()
def issue_index(self, format_type: str = "tsv", sort_by: str = "number",
filter_state: Optional[str] = None, filter_priority: Optional[str] = None,
include_state: bool = False) -> None:
"""Output compact index of all issues for Unix processing.
Args:
format_type: Output format (tsv, csv, json, fields)
sort_by: Sort by field (number, title, priority, state, created, updated)
filter_state: Filter by state (open, closed)
filter_priority: Filter by priority (low, medium, high, critical, none)
include_state: Include state column in output
"""
try:
output = self.service.export_issues(
format_type=format_type,
sort_by=sort_by,
filter_state=filter_state,
filter_priority=filter_priority,
include_state=include_state
)
# Output directly to stdout for piping
print(output)
except TddaiError as e:
# Send error to stderr to avoid corrupting piped output
print(f"❌ Error: {e}", file=sys.stderr)
sys.exit(1)