claude-configs/skills/major-domo/cli_injuries.py
Cal Corum 43d32e9b9d Update major-domo skill CLI refactor and plugin/config updates
- Refactor major-domo skill: api_client.py, cli.py, and CLI modules (admin, common, injuries, results, schedule, transactions) with significant simplification (-275 lines net)
- Update CLI_REFERENCE.md and SKILL.md docs for major-domo
- Update create-scheduled-task SKILL.md
- Update plugins blocklist.json and known_marketplaces.json
- Add patterns/ directory to repo
- Update CLAUDE.md

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-09 02:00:41 -05:00

140 lines
4.0 KiB
Python

#!/usr/bin/env python3
"""
Major Domo CLI - Injury Operations
This module provides injury listing and filtering commands.
"""
from typing import Annotated, Optional
import typer
from cli_common import (
console,
state,
output_json,
output_table,
handle_error,
get_season,
safe_nested,
)
injuries_app = typer.Typer(help="Injury operations")
@injuries_app.command("list")
def injuries_list(
team: Annotated[
Optional[str],
typer.Option("--team", "-t", help="Filter by team abbreviation"),
] = None,
active: Annotated[
bool, typer.Option("--active", "-a", help="Only show active injuries")
] = False,
season: Annotated[
Optional[int], typer.Option("--season", "-s", help="Season number")
] = None,
sort: Annotated[
str,
typer.Option(
"--sort", help="Sort order (start-asc, start-desc, return-asc, return-desc)"
),
] = "return-asc",
):
"""List injuries with optional filtering"""
try:
season = get_season(season)
# Resolve team abbreviation to team ID if provided
team_id = None
team_abbrev = None
if team:
team_abbrev = team.upper()
try:
team_obj = state.api.get_team(abbrev=team_abbrev, season=season)
team_id = team_obj["id"]
except Exception:
console.print(
f"[red]Error:[/red] Team '{team_abbrev}' not found in season {season}"
)
raise typer.Exit(1)
# Call API with resolved parameters
result = state.api.get(
"injuries",
season=season,
team_id=team_id,
is_active=active if active else None,
sort=sort,
)
injuries = result.get("injuries", [])
if state.json_output:
output_json(injuries)
return
if not injuries:
filter_parts = []
if team_abbrev:
filter_parts.append(f"team {team_abbrev}")
if active:
filter_parts.append("active")
filter_str = " (".join(filter_parts) + ")" if filter_parts else ""
console.print(
f"[yellow]No injuries found in season {season}{filter_str}[/yellow]"
)
return
# Format table rows
rows = []
for injury in injuries:
player = injury.get("player", {})
player_name = player.get("name", "N/A")
team_abbrev_display = safe_nested(player, "team", "abbrev")
total_games = injury.get("total_games", 0)
start_week = injury.get("start_week", 0)
start_game = injury.get("start_game", 0)
end_week = injury.get("end_week", 0)
end_game = injury.get("end_game", 0)
is_active = injury.get("is_active", False)
# Format start/end as wXXgY
start_str = f"w{start_week:02d}g{start_game}" if start_week else "N/A"
end_str = f"w{end_week:02d}g{end_game}" if end_week else "N/A"
active_str = "Yes" if is_active else "No"
rows.append(
[
player_name,
team_abbrev_display,
total_games,
start_str,
end_str,
active_str,
]
)
# Build title
title = f"Injuries - Season {season}"
if team_abbrev:
title += f" ({team_abbrev})"
if active:
title += " (Active Only)"
output_table(title, ["Player", "Team", "Games", "Start", "End", "Active"], rows)
except typer.Exit:
raise
except Exception as e:
handle_error(e)
# Make list the default command when running 'majordomo injuries'
@injuries_app.callback(invoke_without_command=True)
def injuries_default(ctx: typer.Context):
"""Default to list command if no subcommand specified"""
if ctx.invoked_subcommand is None:
ctx.invoke(injuries_list)