claude-configs/skills/major-domo/cli_common.py
Cal Corum 6201b4c9af Major Domo CLI: modular refactor + 6 new command modules
Refactored monolithic cli.py into modular architecture:
- cli_common.py: shared state, console, output helpers
- cli_transactions.py: list + simulate (compliance checker)
- cli_injuries.py: injury listing with team/active filters
- cli_stats.py: batting/pitching leaderboards
- cli_results.py: game results
- cli_schedule.py: game schedules

Also: team get now shows salary_cap, SKILL.md fully updated
with CLI docs, flag ordering warning, and compliance workflow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 11:24:18 -06:00

73 lines
1.9 KiB
Python

"""
Shared utilities for Major Domo CLI modules.
All CLI sub-modules import from here for consistent output and state management.
"""
import json
import os
import sys
from typing import List, Optional
from rich.console import Console
from rich.table import Table
# Import the API client from same directory
sys.path.insert(0, os.path.dirname(__file__))
from api_client import MajorDomoAPI
console = Console()
class State:
"""Global state for API client and settings"""
api: Optional[MajorDomoAPI] = None
json_output: bool = False
current_season: Optional[int] = None
state = State()
def output_json(data):
"""Output data as formatted JSON"""
console.print_json(json.dumps(data, indent=2, default=str))
def output_table(
title: str, columns: List[str], rows: List[List], show_lines: bool = False
):
"""Output data as a rich table"""
table = Table(
title=title, show_header=True, header_style="bold cyan", show_lines=show_lines
)
for col in columns:
table.add_column(col)
for row in rows:
table.add_row(*[str(cell) if cell is not None else "" for cell in row])
console.print(table)
def handle_error(e: Exception, context: str = ""):
"""Graceful error handling with helpful messages"""
import typer
error_str = str(e)
if "401" in error_str:
console.print("[red]Error:[/red] Unauthorized. Check your API_TOKEN.")
elif "404" in error_str:
console.print(f"[red]Error:[/red] Not found. {context}")
elif "Connection" in error_str or "ConnectionError" in error_str:
console.print(
"[red]Error:[/red] Cannot connect to API. Check network and --env setting."
)
else:
console.print(f"[red]Error:[/red] {e}")
raise typer.Exit(1)
def get_season(season: Optional[int]) -> int:
"""Get season, defaulting to current if not specified"""
return season if season is not None else state.current_season